Skip to content

Bind MQTT user JWTs to their project; console claim for admin-mode JWTs - #13997

Merged
loks0n merged 5 commits into
mainfrom
fix/jwt-project-binding-followup
Sep 29, 2026
Merged

loks0n merged 5 commits into
mainfrom
fix/jwt-project-binding-followup

Conversation

@loks0n

@loks0n loks0n commented Sep 29, 2026

Copy link
Copy Markdown
Member

Follow-up to #13992, from review on that PR.

What

  • MQTT: app/init/mqtt/connection.php (appwrite-jwt auth) decodes the same user JWT but never got the project binding. It now applies the same rule as HTTP and realtime: the projectId claim must match the connecting project, and a JWT without one must name a session.
  • Admin mode: account.createJWT stamped the managed project's ID on a token backed by a console session, and the admin-mode verifier expects console. It now stamps console in admin mode.

Tests

  • MqttServerTest::testJwtFromAnotherProjectConnectRejected: a sessionless JWT connects in the project that minted it, and gets CONNACK 0x87 in another project that has a user with the same ID.
  • UsersCustomServerTest::testLegacyJWTWithoutProjectClaimIsBoundBySession signs the payload shape used before Bind user JWTs to the project that issued them #13992 and checks:
    • it's accepted in its own project while the session lives;
    • it's rejected in another project with a same-ID user;
    • it's rejected without a session;
    • it's rejected once the session is deleted.

The test commit is pushed first so CI shows the MQTT case failing; the fix follows.

🤖 Generated with Claude Code

loks0n and others added 2 commits September 29, 2026 18:35
…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]>
@loks0n loks0n self-assigned this Sep 29, 2026
@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/jwt-project-binding-followup (after).

Metric Before After Change
🚀 Requests/sec 181.85 193.56 🟢 +6.4%
⏱️ Latency P50 93.53 ms 88.8 ms 🟢 -5.1%
⏱️ Latency P95 226.13 ms 211.08 ms 🟢 -6.7%
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 88.8 211.08 12,312 193.56 -15.06
Account 168.33 356.35 648 10.77 +10.82
TablesDB 85.44 170.27 6,696 108.17 +1.78
Storage 81.95 182.34 3,240 53.58 -11.34
Functions 124.84 258.45 1,728 29.33 -13.36

Top API waits (after)

API request Max wait (ms)
account.name.update 552.67
tablesdb.rows.get 551.77
functions.variables.create 546.61
account.prefs.update 481.16
functions.create 448.4

@loks0n
loks0n marked this pull request as ready for review September 29, 2026 18:02
@loks0n

loks0n commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

@hansi-codes review

@loks0n

loks0n commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

@greptileai review

@ghost

ghost commented Sep 29, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The MQTT binding matches the existing HTTP and realtime logic, the mode injection resolves, and the new behavior has tests.

The MQTT appwrite-jwt auth now applies the same project binding as HTTP and realtime. A JWT with a projectId claim must match the connecting project, and one without it must name a session. account.createJWT now stamps console as projectId in admin mode. E2E tests cover the MQTT cross-project case, legacy JWTs without a project claim, and admin-mode JWTs.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
app/controllers/api/account.php createJWT injects mode and stamps console as projectId in admin mode.
app/init/mqtt/connection.php The appwrite-jwt path rejects tokens whose projectId claim doesn't match the project, or that have neither a claim nor a session.
tests/e2e/Services/Mqtt/MqttServerTest.php Adds a test that a sessionless JWT from another project gets CONNACK 0x87.
tests/e2e/Services/Users/UsersCustomServerTest.php Adds tests for legacy JWTs without a project claim and for admin-mode JWT binding to the console.

Reviewed 6b7a67f · 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 A · Looks good to merge. Summary

Comment thread app/controllers/api/account.php Resolved

@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 A · 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 JWT validation for MQTT connections and admin-mode token claims.

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR binds MQTT user JWTs to their issuing project and stamps admin-mode JWTs with the console project ID. It adds cross-project, legacy-token, and admin-mode authentication tests.

Reviews (3) · Last reviewed commit: "Revert TEMP: restore admin-mode console ..."

Comment thread app/controllers/api/account.php Resolved
@greptile-apps

This comment has been minimized.

@loks0n

loks0n commented Sep 29, 2026

Copy link
Copy Markdown
Member Author

@hansi-codes review

@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 03b761c into main 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