Skip to content

Unbound user JWT authenticates nobody instead of failing the request - #14002

Merged
loks0n merged 1 commit into
mainfrom
fix/unbound-jwt-no-user
Sep 29, 2026
Merged

loks0n merged 1 commit into
mainfrom
fix/unbound-jwt-no-user

Conversation

@loks0n

@loks0n loks0n commented Sep 29, 2026

Copy link
Copy Markdown
Member

Follow-up to #13992.

What

When a user JWT isn't bound to the request's project, the HTTP user resource and the realtime connection threw user_jwt_invalid. A function domain resolves to project console, and clients send their own project's JWT there for the function to read. Every such request now got a 401 before reaching the function.

An unbound JWT now authenticates nobody, and the request continues as a guest, which is what it did before #13992. A user is still never loaded from an unbound token, so cross-project and console replays still end in 401 (as a guest missing scope). The existing binding tests are unchanged and pass.

Tests

New FunctionsCustomServerTest::testFunctionsDomainServesRequestCarryingAnotherProjectsJwt calls a function domain with another project's JWT. Run locally:

  • on main: 401;
  • with this change: 200.

UsersCustomServerTest's cross-project, legacy, admin-mode and original JWT tests still pass (4/4).

🤖 Generated with Claude Code

#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 #13992.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@loks0n loks0n self-assigned this Sep 29, 2026
@ghost

ghost commented Sep 29, 2026

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The change is small and matches its stated intent. An unbound JWT never loads a user, and the later session check already handles an empty user.

An unbound user JWT no longer throws user_jwt_invalid in the HTTP user resource or the realtime connection. The JWT is now ignored and the request continues as a guest, and a user is loaded only when the JWT is bound to the project. A new e2e test calls a function domain with another project's JWT.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 3
File Change
app/init/resources/request.php Removed the throw for unbound JWTs. The user is loaded only when the JWT is bound to the request's project.
app/init/realtime/connection.php Same change for the realtime connection: an unbound JWT loads no user instead of throwing.
tests/e2e/Services/Functions/FunctionsCustomServerTest.php Added an e2e test that calls a function domain with another project's JWT and expects 200.

Reviewed a6d3fd7 · 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

@loks0n
loks0n merged commit f7e33f7 into main Sep 29, 2026
51 checks passed
@greptile-apps

greptile-apps Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 4/5

[Critical risk] Changes how unbound user JWTs are handled in authentication.

The PR appears safe to merge, though the regression test should cover the function’s ability to read the JWT.

Fix All in Claude CodeFindings

  1. P2 JWT forwarding goes untested ▶
Fix with agent prompt
### Issue 1
tests/e2e/Services/Functions/FunctionsCustomServerTest.php:3032
The test sends `x-appwrite-jwt` but checks only for a 200 response. The deployed `cookies` function reads the `cookie` header, not the JWT, so this test would still pass if the JWT were dropped before the function could read it. Assert the JWT value through the function response to cover the stated use case.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Summary

The PR changes HTTP and realtime authentication so a valid but project-unbound JWT leaves the request unauthenticated instead of rejecting it, and adds a function-domain regression test.

  • The new test covers successful request completion but does not verify that the function can read the supplied JWT.

Reviews (1) · Last reviewed commit: "fix(auth): an unbound user JWT authentic..."

'content-type' => 'application/json',
'x-appwrite-jwt' => $jwt['body']['jwt'],
]);
$this->assertEquals(200, $response['headers']['status-code']);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 JWT forwarding goes untested The test sends x-appwrite-jwt but checks only for a 200 response. The deployed cookies function reads the cookie header, not the JWT, so this test would still pass if the JWT were dropped before the function could read it. Assert the JWT value through the function response to cover the stated use case.

Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/e2e/Services/Functions/FunctionsCustomServerTest.php
Line: 3032

Comment:
**JWT forwarding goes untested** The test sends `x-appwrite-jwt` but checks only for a 200 response. The deployed `cookies` function reads the `cookie` header, not the JWT, so this test would still pass if the JWT were dropped before the function could read it. Assert the JWT value through the function response to cover the stated use case.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

Fix in Claude Code Fix in Codex

@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/unbound-jwt-no-user (after).

Metric Before After Change
🚀 Requests/sec 205.9 213.67 ⚪ +3.8%
⏱️ Latency P50 82.74 ms 79.85 ms ⚪ -3.5%
⏱️ Latency P95 197.36 ms 193.68 ms ⚪ -1.9%
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 79.85 193.68 13,509 213.67 -3.68
Account 161.81 305.49 711 11.86 -98.6
TablesDB 76.32 149.12 7,347 119.4 -11.16
Storage 74.3 164.21 3,555 59.18 -0.87
Functions 116.32 232.04 1,896 32.18 -5.3

Top API waits (after)

API request Max wait (ms)
account.prefs.update 514.06
account.name.update 459.09
functions.variables.update 402.86
functions.create 392.16
storage.buckets.create 343.67

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