Repository navigation
fix(realtime): reset connection authorization on re-authentication - #15064
Conversation
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The authentication message restored the connection's previous authorization, so roles granted to the old identity (admin-mode roles) kept applying to later messages from the new session. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Review complete. No issues found — approved ✅. This PR extends realtime e2e coverage for console-client authentication switching (impersonation): it verifies that after re-authenticating a live websocket connection, the connection's roles reflect the impersonated identity and subsequent presence/permission behavior matches. No behavioral production changes were identified.
Reviewed commit: f0ed689 |
🟢 Tier S · Ready to mergeThe realtime authentication handler now replaces the connection’s stored authorization when a session identity changes, preventing roles from the prior identity from being carried into later messages. An E2E test covers re-authentication from admin mode and verifies either that the switch is refused or that the new identity cannot share presence with an unrelated user role.
📂 Walkthrough · 2
Merged |
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
What does this PR do?
A realtime
authenticationmessage switches the connection to the identity of the session it carries. It re-subscribed the connection with the new identity's roles, but then put back the connection's previousauthorizationobject. Every later message builds its database authorization from that object plus the subscription roles, so roles held only by the previous identity still applied to the new one.A plain session connection's stored authorization holds only the default role, so in practice this affects connections opened in admin mode: those hold the console user's admin roles (
owner,developer, ...). After switching to a project user's session, that user still counted as privileged inside message handlers. For example, it could share its presence with roles it does not hold.This PR stores a fresh
Authorizationwhen the identity switches, the same object a session connection gets when it opens. The new identity's roles still come from its subscriptions, which the handler already rebuilds.Interaction with #15060: that PR refuses
authenticationon admin-mode connections outright, which closes the admin-mode case at its source. This change stays useful as a second layer: no path that switches identity can keep the previous identity's roles. The two diffs touch separate lines ofAuthentication.php, and the test below passes whichever PR merges first. It accepts either a refused switch or a switch without the admin roles.Tracking: appwrite-labs/cloud#7060
Test Plan
New e2e test
RealtimeConsoleClientTest::testAdminModeReauthenticationDropsAdminRoles:authenticationwith a project user's session.401,Permissions must be one of ...).Red/green on a local stack:
responseinstead oferror).RealtimeConsoleClientTest(20 tests) andPresenceRealtimeClientTest(12 tests) pass.RealtimeCustomClientTestfails the same three transaction tests with and without the change. Those failures come from the local stack and are unrelated.Related PRs and Issues
Checklist
🤖 Generated with Claude Code