Repository navigation
fix(realtime): bind account-key impersonators to the console project - #14040
ArnabChatterjee20k merged 1 commit into
Conversation
The user resource authenticates x-appwrite-key + x-appwrite-user against the platform database on any project, but the impersonator binding used the connection's project unless in admin mode or on the console. A console impersonator using an account key on a custom project was bound to that project: their console block, delete or session end never closed the socket, while events for a project user with the same ID could close it. Co-Authored-By: Claude Opus 5.5 <[email protected]>
There was a problem hiding this comment.
Your trial has ended. Reactivate Greptile to resume code reviews.
🔵 Tier A · Mergeable after minor fixes
Updates realtime impersonator bindings to use the console project when authentication supplies both account-key headers. This aligns the binding with the platform database used to authenticate account keys, while retaining existing admin-mode and console-project behavior.
Fix with agent prompt### Issue 1
app/init/realtime/connection.php:394-395
**Add coverage for account-key impersonator project isolation**
The existing `testConnectionEndsWithImpersonatorSession` only authenticates a custom-project actor with a session, so it still passes if this account-key condition is removed. Please add a fixture-backed regression covering a console account-key actor on a custom project: console block/delete should close the socket, while events for a custom-project user with the same ID should not.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.📂 Walkthrough · 1
Reviewed |
| || (!empty($request->getHeaderLine('x-appwrite-key', '')) && !empty($request->getHeaderLine('x-appwrite-user', ''))) | ||
| ) ? 'console' : $project->getId(), |
There was a problem hiding this comment.
Add coverage for account-key impersonator project isolation
The existing testConnectionEndsWithImpersonatorSession only authenticates a custom-project actor with a session, so it still passes if this account-key condition is removed. Please add a fixture-backed regression covering a console account-key actor on a custom project: console block/delete should close the socket, while events for a custom-project user with the same ID should not.
Prompt To Fix With AI
This is a comment left during a code review.
Path: app/init/realtime/connection.php
Line: 394-395
Comment:
**Add coverage for account-key impersonator project isolation**
The existing `testConnectionEndsWithImpersonatorSession` only authenticates a custom-project actor with a session, so it still passes if this account-key condition is removed. Please add a fixture-backed regression covering a console account-key actor on a custom project: console block/delete should close the socket, while events for a custom-project user with the same ID should not.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.🟡 Minor · testing · Reply if this doesn't apply.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
97a1f58
into
fix/realtime-impersonation
Stacked on #14024. Addresses #14024 (comment).
Why
#14024 binds an impersonated connection to the impersonator (
projectId,userId,sessionId) so the impersonator's block, delete or session end closes it. The binding'sprojectIdwasconsoleonly in admin mode or on the console project.But the realtime
userresource also authenticatesx-appwrite-key+x-appwrite-user(account keys) against the platform database on any project. A console impersonator using an account key on a custom project was therefore bound to that custom project:users.*events are published underconsole, so a console block/delete never reached the binding and the socket stayed open;users.*event for an unrelated project user with the same ID matched the binding and could close it.What
impersonatorUsersetsprojectIdtoconsolewhen both account-key headers are present as well. That's exactly when theuserresource loaded the user from the key: it throwsUSER_API_KEY_AND_SESSION_SETwhen a key and a session/JWT are both sent, and a failed key leaves the user empty, which yields no impersonator.Tests
No e2e regression: account keys can't be created through the API (there's no endpoint or mock for user-owned keys), and the scenario also needs a separate console user to block. Lint and PHPStan pass on the file.
🤖 Generated with Claude Code