Repository navigation
Bind user JWTs to the project that issued them - #13992
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
User JWTs now carry a projectId claim, and the HTTP and realtime user resources reject a JWT minted for another project. Tokens minted before the claim existed are still accepted when they name a session, since the session ID is server-generated and exists only in the minting project. Co-Authored-By: Claude Opus 5.5 <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
🟢 Tier S · Ready to mergeUser JWTs now carry a
📂 Walkthrough · 7
Reviewed |
|
| ->setStatusCode(Response::STATUS_CODE_CREATED) | ||
| ->dynamic(new Document([ | ||
| 'jwt' => $jwt->encode([ | ||
| 'projectId' => $project->getId(), |
There was a problem hiding this comment.
Admin JWTs are rejected When a console user creates a JWT in admin mode for a non-console project, this line stamps the managed project's ID on a token backed by the console session. HTTP and realtime authentication require
console as the token's project ID in admin mode, so the newly issued JWT is rejected when used for that same admin-mode project request.
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/controllers/api/account.php
Line: 3421
Comment:
**Admin JWTs are rejected** When a console user creates a JWT in admin mode for a non-console project, this line stamps the managed project's ID on a token backed by the console session. HTTP and realtime authentication require `console` as the token's project ID in admin mode, so the newly issued JWT is rejected when used for that same admin-mode project request.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Fixed in #13997: admin-mode account.createJWT now stamps console, matching what the admin-mode verifier expects.
| $response | ||
| ->setStatusCode(Response::STATUS_CODE_CREATED) | ||
| ->dynamic(new Document(['jwt' => $jwt->encode([ | ||
| 'projectId' => $project->getId(), |
There was a problem hiding this comment.
MQTT accepts cross-project JWTs A sessionless JWT minted for a user ID in project A can still authenticate over MQTT in project B if B has a user with the same ID. Unlike HTTP and realtime, MQTT loads the user from the connecting project without checking this new
projectId claim, leaving the cross-project replay possible. How this was verified: MQTT selects the connecting project's user database and authenticates the JWT's userId without comparing its projectId claim or requiring a session.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/Appwrite/Platform/Modules/Users/Http/Users/JWTs/Create.php
Line: 89
Comment:
**MQTT accepts cross-project JWTs** A sessionless JWT minted for a user ID in project A can still authenticate over MQTT in project B if B has a user with the same ID. Unlike HTTP and realtime, MQTT loads the user from the connecting project without checking this new `projectId` claim, leaving the cross-project replay possible. **How this was verified:** MQTT selects the connecting project's user database and authenticates the JWT's `userId` without comparing its `projectId` claim or requiring a session.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.There was a problem hiding this comment.
Valid. Fixed in #13997: MQTT's appwrite-jwt auth now applies the same binding, with an E2E case in MqttServerTest.
| // No sessions, so the JWT carries no session to check. | ||
| $jwt = $this->client->call(Client::METHOD_POST, '/users/' . $userId . '/jwts', [ | ||
| 'content-type' => 'application/json', | ||
| 'x-appwrite-project' => $attackerProject['$id'], | ||
| 'x-appwrite-key' => $attackerProject['apiKey'], | ||
| ]); | ||
| $this->assertSame(201, $jwt['headers']['status-code']); | ||
| $jwts[$userId] = $jwt['body']['jwt']; |
There was a problem hiding this comment.
Legacy JWT fallback lacks coverage This test only uses newly minted, sessionless JWTs. The validators also accept older JWTs without
projectId when they name an active session, but the test does not cover that acceptance or rejection after the session is invalidated. An unintended change to that compatibility behavior could therefore go unnoticed.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/Users/UsersCustomServerTest.php
Line: 50-57
Comment:
**Legacy JWT fallback lacks coverage** This test only uses newly minted, sessionless JWTs. The validators also accept older JWTs without `projectId` when they name an active session, but the test does not cover that acceptance or rejection after the session is invalidated. An unintended change to that compatibility behavior could therefore go unnoticed.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
…in-mode JWTs MQTT's appwrite-jwt auth decoded the same user JWT and loaded the user from the connecting project without the binding added to HTTP and realtime in #13992, so a sessionless JWT from another project still authenticated there. account.createJWT in admin mode stamped the managed project's ID on a token backed by a console session, which the admin-mode verifier then rejected; it now stamps console. Co-Authored-By: Claude Opus 5.5 <[email protected]>
appwrite#13992 threw user_jwt_invalid when a JWT was not issued for the request's project. A function domain resolves to the console, and clients send their own project's JWT there for the function to read, so every such request got 401 before reaching the function. The token still grants nothing: the request continues as a guest, as it did before appwrite#13992. Co-Authored-By: Claude Opus 5.5 <[email protected]>
What
User JWTs now carry a
projectIdclaim. They are minted byaccount.createJWT,users.createJWT, and function executions (HTTP and worker). The HTTP and realtimeuserresources only accept a JWT in the project it was issued for. In admin mode, that'sconsole.JWTs minted before this change have no
projectId. They're still accepted when they name a session, since a session ID is server-generated and exists only in the minting project. Old sessionless JWTs stop working. They last at most 3600s.Test
UsersCustomServerTest::testUserJWTIsBoundToItsProjectmints a sessionless JWT in one project and replays it against another project and againstconsole. Both must return 401, and the JWT must still work where it was minted.The first commit pushes the test alone so CI shows it failing. The fix follows.
🤖 Generated with Claude Code