Repository navigation
Conversation
Under JWT authentication, \ resolves to null via sessionVerify()
because JWT auth never populates \'s cookie secret. This silently
bypasses checks in 4 places in production today:
1. MFA recency check — JWT requests bypass MFA recency enforcement
2. MFA factor-count check — JWT requests bypass factor count enforcement
3. deleteSession('current') — returns 404, wrong session resolved
4. getSession('current') — returns 404, wrong session resolved
Tests assert expected behavior — all currently fail, confirming the bug.
Fix will thread JWT-resolved session ID through from request.php auth
resolution so all 4 spots benefit from a single change.
Draft PR — tests only
|
- testMFAFactorCountBypassedUnderJWT: create JWT from session B before enabling MFA so JWT creation is not blocked by the factor-count check - testMFARecencyCheckFailsUnderJWT: rename from Bypassed — request errors with TypeError 500 because session resolves to null under JWT Addresses Greptile P1 and P2 findings.
41dd0b2 to
9b55e3e
Compare
🟢 Tier S · Ready to merge
This PR resolves the request session from an active JWT when no cookie session is available, then uses it for account session, password, and push-target operations. It adds E2E coverage for those JWT flows. The latest commits also make a JWT-authenticated deletion of the current session report Latest changes: The newest commits update the session-delete event payload's current-session flag and add a JWT webhook regression test.
Note @jaysomani does not have write access to this repository, so Hansi does not approve automatically. A maintainer can review and approve. 📂 Walkthrough · 4
✅ Fixed since the last review · 1
Reviewed the commits since |
Rename the JWT session tests to describe expected behavior, share JWT and session setup through helpers, and add coverage for updating the current session, marking the current session in the sessions list, and invalidating other sessions on password change under JWT. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The session resource only resolved from the cookie secret, so JWT requests had no session. MFA factor enforcement was skipped, MFA-protected routes crashed, and 'current' session lookups, current-session flags, password change invalidation and push target rotation all missed the JWT's session. Fall back to the JWT's session ID and use the session resource in those account routes. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ution fix: resolve the current session under JWT auth
Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Adds optional bool param current (default true) to DELETE /account/sessions. When false, all sessions except the calling session are deleted, allowing sign-out everywhere while staying signed in on the current device. Uses the session resource from #13900 so JWT auth works correctly for both cookie and JWT authenticated callers. X-Fallback-Cookies header is now only sent when current=true to avoid wiping the caller's stored session cookie when signing out other sessions. E2E tests cover cookie and JWT auth paths with three-session setup per spec: other two sessions get 401, calling session stays 200, listSessions returns exactly one session marked current.
What does this PR do?
Resolves the current session under JWT auth. The
sessionresource (app/init/resources/request.php) and the'current'lookups inaccount.phponly checked the cookie secret. They ignored thesessionIdthat the JWT already carries and thatrequest.phpalready validates withsessionActive(). Under JWT,sessionwasnulland'current'matched nothing.Bugs covered by the new E2E tests
Every test fails on
mainand passes with this PR.maintestMFAFactorCountUnderJWTuser_more_factors_requiredshared/api.phpguards the factor check withif ($session && ...). A JWT minted from a password-only session before MFA was enabled keeps working for its lifetime (15 min by default, 60 max), while that session's cookie is blocked.testUpdatePasswordInvalidatesOtherSessionsUnderJWTtestMFARecencyCheckUnderJWTuser_challenge_requiredmfaProtectedrequires a non-nullDocument $session, so this is a TypeError. The same applies to the other routes that injectsession: MFA update, challenge completion and authenticator verification.testGetSessionCurrentUnderJWT'current'keyword unusable with JWTtestUpdateSessionCurrentUnderJWTtestDeleteSessionCurrentUnderJWTtestListSessionsCurrentUnderJWTcurrent: truetestCreatePushTargetReplacesRotatedTokenUnderJWTFix
sessionresource (app/init/resources/request.php): when the cookie secret doesn't resolve a session and anx-appwrite-jwtheader is present, fall back to the JWT'ssessionId. It is only used when the JWT'suserIdmatches the resolved user and the session is still active. That condition matters when a JWT and an account API key are combined, where the resolved user may not come from the JWT.sessionresource instead of callingsessionVerify()on the cookie:GET /account/sessions:currentflagGET,PATCHandDELETE /account/sessions/currentPATCH /account/password: invalidation of the other sessionsPOST /account/targets/push: linking the target to the session and rotating tokensImpersonation behaves as before:
sessionbelongs to the impersonator, so it never matches the target's sessions.Behavior changes
users.createJWTfor a session with too few factors. Those now getuser_more_factors_required, as a cookie request on the same session would.DELETE /account/sessions/currentwith a JWT deletes the JWT's session, which ends that JWT as well. Session cookies are only cleared when the request came with one.Left unchanged:
POST /account/jwts(JWTs can't create JWTs), the OAuth2 redirect (browser cookie flow) and function executions (the JWT is already forwarded as-is).Test Plan
AccountCustomClientTest --filter UnderJWT: 8/8 fail onmain, 8/8 pass with this PRAccount(119 tests) andUsers(58 tests) E2E suites pass locallyRelated PRs and Issues
Checklist