Repository navigation
fix(realtime): end member sockets when their project team is deleted - #15335
Conversation
A realtime connection's roles, including team:{teamId}, are built once at connect time and only rebuilt when revalidateUser/resubscribe runs. teams.{teamId}.delete set permissionsChanged=false and endDeletedTeams only closed console admin-mode sockets (getTeamAdminConnections, matching the admin stash). So after a team inside a project was deleted, its members' live sockets kept the team:{teamId} role — and the team-scoped access it grants — until they happened to reconnect.
Add Realtime::getTeamConnections(), which finds every connection in a project still holding a team's role, and extend endDeletedTeams to close those member sockets on a project team delete (while keeping the console-organization admin-socket behavior). Closing forces a reconnect that rebuilds roles without the gone team, matching how the function already revokes admin sockets.
|
Review complete. 🟠 1 high 💬 Inline comments (1)
The patch fixes a security-relevant stale: websockets previously kept a deleted team's role until reconnect. Deletion events are now intercepted in
One high-severity issue limits the fix's coverage: team IDs may contain periods, and event parsing assumes exactly three dot-separated segments, so deletions of such teams still leak stale roles (see finding-001). Reviewed commit: f523f6e |
🟢 Tier S · Ready to mergeRealtime team deletion now closes project sockets that still hold the deleted team’s role, while preserving the existing console admin-socket handling. The handler identifies the deleted team from the event payload so dotted team IDs are supported and membership deletions are not mistaken for team deletions; tests cover both cases and ensure unrelated project sockets remain open. Latest changes: The follow-up derives the team ID from the deleted document payload, matches the exact team-delete event, and adds coverage for dotted IDs and membership-delete events.
📂 Walkthrough · 3
Reviewed the commits since |
There was a problem hiding this comment.
This PR closes realtime websocket connections holding stale team roles when a team is deleted, fixing permission revocation for both console and project team paths.
Key findings
- 🟠 Dotted team IDs evade team-delete event matching — Handler.php:602
Security rulesNo new WARNING or ERROR findings from security rules. 6 existing findings tracked in
|
Team ids may contain periods (CustomId/Key), so splitting the event name positionally missed teams.my.team.delete and left stale team roles on live sockets. Derive the team id from the deleted document's payload and confirm the message is that team's delete via the concrete teams.{id}.delete event, which handles dotted ids and does not mistake a membership delete (payload id is the membership) for the team's own delete.
✨ Benchmark resultsComparing
Per-scenario breakdown & investigation detailsMetrics below reflect the current branch (after). Δ P95 compares against the base.
Top API waits (after)
|
fix(realtime): end member sockets when their project team is deleted (cherry picked from commit f349dd7)
Problem
A realtime connection's roles — including
team:{teamId}andteam:{teamId}/{role}— are computed once at connect time (app/realtime.php→User::getRoles()) and stored on the connection. They are only rebuilt whenrevalidateUser→resubscriberuns (Realtime/Event/Handler.php).For a team delete,
Messaging/Adapter/Realtime.phpsetspermissionsChanged = ($parts[2] === 'create')— soteams.{teamId}.deleteyieldsfalse— andendDeletedTeamsonly closed console admin-mode sockets (getTeamAdminConnections, which matches theadminstash, not the normalrolesarray). So when a team inside a customer project was deleted, its members' already-open sockets kept theteam:{teamId}role, and the team-scoped realtime access it grants, until they happened to reconnect.This is the realtime sibling of the role-eviction that already works for membership removal and user/session changes (which do run
resubscribe).Fix
Realtime::getTeamConnections($projectId, $teamId), which finds every connection in a project still holding the team's role (mirrorsgetTeamAdminConnections, but scans the connectionroles).endDeletedTeamsto close those member sockets on a project team delete, while keeping the existing console-organization admin-socket behavior.Closing forces a reconnect that rebuilds roles without the deleted team — the same revocation mechanism
endDeletedTeamsalready applies to admin sockets, rather than a broad project-wide re-read (checkProjectdoes not rebuild roles). Only sockets actually holding the role are closed; others in the project are untouched.Test
Extends
HandlerTestwithtestDeletingAProjectTeamEndsOnlyItsMemberSockets: a member holdingteam:team1and a bystander holding only a user role are subscribed in one project; ateams.team1.deleteevent closes the member's socket and leaves the bystander's open.Found via the Strix pentest remediation engagement (finding #17).