Repository navigation
fix(realtime): authorize console tails with project read access - #14797
Conversation
A console live tail was authorized by the bare organization team role, which every member holds, while reading a project over HTTP needs a team owner or developer role or a role on that project. Authorize tails with the project's read permissions and keep those roles for revalidation. Console team and membership events were never published to realtime, so removing a member or changing their roles left their open console sockets with the old roles. Publish the teams group on the console project so these events run the existing revalidation, which drops tails the member can no longer read. Co-Authored-By: Claude <[email protected]>
|
Review complete. 🟠 1 high · 🟡 1 medium 💬 Inline comments (1)
📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to🟡 Medium — Commit phase ignores connection state after suspending authorization · Subscribe.php:137–154 · // src/Appwrite/Realtime/Message/Handlers/Subscribe.php
137 foreach ($parsedPayloads as $parsedPayload) {
138 $realtime->subscribe(
139 $projectId,
140 $connectionId,
141 $parsedPayload['subscriptionId'],
142 $roles,
143 $parsedPayload['convertedChannels'],
144 $parsedPayload['queries'],
145 );
146 }
147
148 // All tail channels passed authorization above — register them additively. TheThe authorization phase suspends at This PR introduces console-project tailing over realtime:
Reviewed commit: cb520fe |
🟢 Tier S · Ready to mergeConsole live-tail subscriptions authorize against each target project's read roles and retain those roles for later permission revalidation. Realtime team events trigger that revalidation, and the PR adds unit and end-to-end coverage for project-scoped access and membership revocation. Latest changes: The newest commit updates the Subscribe handler comment to describe role-change revalidation for registered tails.
📂 Walkthrough · 5
Reviewed the commits since |
There was a problem hiding this comment.
Adds role-snapshotted console realtime tail authorization with mid-connection revocation, plus e2e and unit tests; two authorization-lifecycle gaps remain.
Key findings
- 🟠 Tail survives project team transfer via stale role snapshot — Subscribe.php:131
- 🟡 Commit phase ignores connection state after suspending authorization — Subscribe.php:137
| // Carry the authorizing roles so the tail can be revoked if the viewer | ||
| // later loses access to the project. | ||
| $pendingTails[] = [$parsedPayload['subscriptionId'], $targetProjectId, $compiled, $readRoles]; |
There was a problem hiding this comment.
🟠 security · high
Tail survives project team transfer via stale role snapshot
The stored authorizing roles are a snapshot taken at subscribe time, and the comment claims the tail is revoked when the viewer later loses access (Subscribe.php:131-133). But EventTailRegistry::revalidateConnection only intersects that snapshot with the connection's current roles — it never re-resolves the project's read permissions — and projects.* events (including the transfer in Projects/Team/Update.php) are published with permissionsChanged false, so revalidation never even runs for a transfer. After a project moves to another team, old-team members keep streaming compact project event metadata on console.tail until disconnect, despite the project's permissions no longer granting them access.
📋 Prompt for AI Agents
In src/Appwrite/Realtime/Message/Handlers/Subscribe.php lines 131-133, the tail revocation guarantee is broken: EventTailRegistry::revalidateConnection (src/Appwrite/Realtime/EventTailRegistry.php, called from app/realtime.php around line 741) compares the roles snapshot stored at subscribe time against the connection's roles, so it never notices that the project's own read permissions changed (e.g. a team transfer via PATCH /v1/projects/:projectId/team, which rewrites $permissions but emits projects.* events with permissionsChanged=false). Fix by making the revalidation path re-fetch each tailed project from dbForConsole and recompute getPermissionsByType(PermissionType::Read), detaching entries whose stored authorization no longer intersects the project's current read permissions; additionally mark project permission-changing events (at minimum the projects.team.update case in Appwrite\Messaging\Adapter\Realtime::fromPayload) as permissionsChanged so the revalidation actually runs on transfer.
There was a problem hiding this comment.
Agreed that a transfer is not covered, and the PR description calls this out. It is not a regression: on main the tail stored team:<oldOrg>, which old members keep after a transfer too. Revalidating on transfer needs the transfer endpoint to publish a permission-changing event (console projects.* events are not published to realtime at all today), and that endpoint is being changed in a separate PR, so it is left out here to keep the two changes independent. I reworded the comment so it no longer implies transfers are handled.
There was a problem hiding this comment.
Thanks for the detailed explanation. Looking at the full evidence:
What the PR does fix (visible in the diffs):
Subscribe.php: switches from a single$requiredRolesnapshot to a$readRolesarray snapshot, andEventTailRegistryis updated to storeroles(array) and intersect against the connection's current roles inrevalidateConnection. This is a meaningful improvement over the old single-role snapshot.
What remains unaddressed (the core of the original finding):
revalidateConnectionstill compares the subscribe-time snapshot against the connection's current roles — it never re-fetches the project fromdbForConsoleto recompute current read permissions. So if the project's permissions change (e.g. transfer), the stored snapshot is stale and the comparison fails to detect the loss of access.- The
Realtime.phpdiff adds'teams'toCONSOLE_ALLOWLISTbut does not markprojects.team.update(or any project transfer event) aspermissionsChanged=true. SorevalidateConnectionis still never triggered on a transfer.
The user's reply acknowledges the transfer gap and states it will be handled in a separate PR. That is a reasonable decomposition, but neither half of the fix described in the original finding (re-fetching project permissions in revalidateConnection, and marking transfer events as permissionsChanged) is visible in this diff. The vulnerability — old-team members streaming tail data after a project transfer — remains open until both pieces land.
There was a problem hiding this comment.
Agreed: the transfer case is still open after this PR and will be handled together with the transfer endpoint change, which needs to publish a permission-changing event and have revalidation re-read the project's permissions. This PR covers subscribe-time authorization and revalidation when the member's own roles change.
There was a problem hiding this comment.
The assessment from the previous round still holds. The diff confirms that neither half of the required fix is present in this PR:
- No re-fetch in revalidation: 'EventTailRegistry.php' still compares the subscribe-time 'readRoles' snapshot against the connection's current roles — it never re-fetches the project from 'dbForConsole' to recompute current read permissions after a transfer.
- No permissionsChanged flag for transfers: 'Realtime.php' does not mark 'projects.team.update' (or any project transfer event) as 'permissionsChanged=true', so revalidation is never triggered on a transfer.
I understand the decomposition rationale — the transfer endpoint change is a separate PR — but both gaps from the original finding remain open here. Keeping this finding open until the companion PR (re-fetch + permissionsChanged flag) lands.
Co-Authored-By: Claude <[email protected]>
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
…project-access fix(realtime): authorize console tails with project read access (cherry picked from commit 6351799)
Summary
Console live tails (
console.tail.<projectId>) are now authorized with the project's read permissions (organization owner/developer, or aproject-<id>-owner/-developerrole) instead of the bare organization team role. Console team and membership changes now run the realtime revalidation path, so a removed member or a member whose roles changed loses tails they can no longer read without reconnecting.Changes
Realtime/Message/Handlers/Subscribe.php: authorize each tail against$project->getPermissionsByType(Read), resolved fresh, and store those roles with the tail.Realtime/EventTailRegistry.php: a tail keeps the list of roles that authorized it;revalidateConnection()drops it when the connection holds none of them.Event/Realtime.php: add theteamsgroup toCONSOLE_ALLOWLIST, so console team and membership events reach realtime withpermissionsChangedand trigger the existing re-resolve of the member's console connections.Tests
EventTailRegistryTestcovers any-of role revalidation, including a member who keeps the bare team role but loses access to the project.RealtimeConsoleTailTest, verified by CI): a member scoped to one project can tail that project but not a sibling; a member's tail stops streaming after their membership is removed.Related: appwrite-labs/cloud#6666