Skip to content

fix: resolve the current session under JWT auth - #13972

Merged
Meldiron merged 1 commit into
pr-13900-jwt-session-testsfrom
fix/jwt-session-resolution
Sep 29, 2026
Merged

Meldiron merged 1 commit into
pr-13900-jwt-session-testsfrom
fix/jwt-session-resolution

Conversation

@Meldiron

Copy link
Copy Markdown
Contributor

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.

  • session resource (app/init/resources/request.php): when the cookie secret doesn't resolve a session and an x-appwrite-jwt header is present, fall back to the JWT's sessionId. It is only used when the JWT's userId matches 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.
  • Account routes now use the session resource instead of calling sessionVerify() on the cookie:
    • GET /account/sessions: current flag
    • GET, PATCH and DELETE /account/sessions/current
    • PATCH /account/password: invalidation of the other sessions
    • POST /account/targets/push: linking the target to the session and rotating tokens

Impersonation behaves as before: session belongs to the impersonator, so it never matches the target's sessions.

Behavior changes

  • JWT requests are now subject to the MFA factor check. This includes JWTs minted server-side with users.createJWT for a session with too few factors. Those now get user_more_factors_required, as a cookie request on the same session would.
  • DELETE /account/sessions/current with a JWT deletes the JWT's session, which ends that JWT as well. Session cookies are only cleared when the request came with one.
  • MFA-protected routes, MFA update, challenge completion and authenticator verification now work with a JWT instead of returning 500.

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 it
  • Full Account (119 tests) and Users (58 tests) E2E suites pass locally
  • Pint and PHPStan pass on the changed files

Related PRs and Issues

Checklist

  • Have you read the Contributing Guidelines on issues?
  • If the PR includes a change to an API's metadata (desc, label, params, etc.), does it also include updated API specs and example docs?

🤖 Generated with Claude Code

@ghost

ghost commented Sep 29, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The updated session lookup and its account-route consumers are consistent with the existing authentication flow and covered by the repository's JWT E2E tests.

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.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 2
File Change
app/init/resources/request.php Adds a validated JWT fallback to the per-request session resource.
app/controllers/api/account.php Uses the session resource for current-session lookups, password invalidation, and push-target registration.

Reviewed 484b453 · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Tier S · Looks good to merge. Summary

@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Critical risk] Changes how the current session is resolved under JWT authentication.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR resolves the current session from a JWT when cookie-based resolution fails, then uses that session for account routes. The latest changes add a TOTP timing guard and verify the push-target rotation through the account response.

Reviews (2) · Last reviewed commit: "fix: resolve the current session under J..."

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]>
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing pr-13900-jwt-session-tests (before) → fix/jwt-session-resolution (after).

Metric Before After Change
🚀 Requests/sec 191.45 196.82 ⚪ +2.8%
⏱️ Latency P50 88.12 ms 89.3 ms ⚪ +1.3%
⏱️ Latency P95 216.36 ms 203.72 ms 🟢 -5.8%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 89.3 203.72 12,483 196.82 -12.64
Account 162.89 303.6 657 11.07 -46.96
TablesDB 87.39 161.85 6,789 110.8 -16.03
Storage 81.07 173.48 3,285 54.7 -4.68
Functions 126.54 239.92 1,752 29.73 -12.87

Top API waits (after)

API request Max wait (ms)
functions.create 433.23
account.name.update 431.41
functions.variables.update 400.89
account.prefs.update 384.12
functions.variables.create 356.3

@Meldiron
Meldiron force-pushed the fix/jwt-session-resolution branch from 8b0885c to 484b453 Compare September 29, 2026 09:56
@Meldiron
Meldiron merged commit 54cb9e3 into pr-13900-jwt-session-tests Sep 29, 2026
51 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant