Repository navigation
fix: resolve the current session under JWT auth - #13972
Conversation
🟢 Tier S · Ready to merge
This change resolves the current session from an active JWT-bound session when cookie authentication does not provide one. Account session, password, and push-target routes use that resource so JWT requests can identify their current session; the shared MFA checks also receive the resolved session.
📂 Walkthrough · 2
Reviewed |
|
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]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
8b0885c to
484b453
Compare
What does this PR do?
Stacked on #13900, which adds the failing tests. Only the last commit is new here.
Resolves the current session under JWT auth.
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 pass with the fix, 8/8 fail without itAccount(119 tests) andUsers(58 tests) E2E suites pass locallyRelated PRs and Issues
Checklist
🤖 Generated with Claude Code