Skip to content

fix(collab): authorize against the team session, not the build session (Closes #187) - #191

Merged
harsharajkumar-273 merged 1 commit into
harsharajkumar-273:mainfrom
SakethSumanBathini:fix/187-authorize-collab-against-team-session
Aug 4, 2026
Merged

fix(collab): authorize against the team session, not the build session (Closes #187)#191
harsharajkumar-273 merged 1 commit into
harsharajkumar-273:mainfrom
SakethSumanBathini:fix/187-authorize-collab-against-team-session

Conversation

@SakethSumanBathini

Copy link
Copy Markdown
Contributor

Closes #187

Restores real-time collaboration, which has been closing every connection since #147 merged.

Cause

buildCollaborationRoomId composes team:<code>:<path> and is the only producer of room IDs in the client. The authorization check looked that string up in buildExecutor's map, which is keyed by 16-hex IDs from crypto.randomBytes(8). A team: string can never match, so getSession always returned undefined and every connection closed with 1008 'invalid session' — the room creator's included.

isValidRoomId only checks type and length, so the malformed lookup wasn't caught earlier.

Change

Room IDs beginning team: resolve their code through teamSessionStore, which is where the room's identity actually lives. Anything else falls back to the previous build-session creator check, so no other caller shape is affected.

The code is taken from between the first two colons and passed through normalizeTeamSessionCode, matching how /team-sessions/join treats it. Verified against the cases that matter:

team:ABC123:chapters/ch1.ptx  -> ABC123
team:abc123:a:b.ptx           -> ABC123     (colons in the path ignored)
team::x.ptx                   -> ""         (rejected)
1234567890abcdef              -> build-session path

What "authorized" means here, and why

You assigned this before answering the membership question I raised, so I looked into it: TeamSession has no joiner list. It records code, repo, hostName, hostLogin, createdAt, updatedAt — nothing that identifies who has joined. So there is no per-user membership available to test.

That leaves possession of a valid, unexpired invite code as the boundary. Restricting to hostLogin instead would deny every invited collaborator, which defeats the purpose of a team session entirely.

To be explicit about where that sits: it is weaker than per-user membership, and stronger than what existed before #147. An authenticated caller must still hold a code that resolves to a live session, so the guessed-16-hex-room-ID attack from #140 stays closed — guessing an invite code is the remaining exposure, and codes are short.

If you want a tighter check, the prerequisite is recording joiners on the team session at /team-sessions/join. That's a schema and lifecycle change rather than a fix to this function, so I've left it out — happy to open it separately. It would also close CodeRabbit's outstanding "does not recognize authorized members" note on #147.

Verification

npx tsc --noEmit clean; room-ID parsing exercised against the cases above.

I could not run a live two-client collaboration session from my environment. Given this restores a broken feature rather than hardening a working one, it's worth one manual check before merging: open a team session in two browsers and confirm edits propagate. I'd rather flag that than imply I've verified it end to end.

Ordering

Touches collaborationServer.ts, as does my open #146 branch — that one changes ensureRedisSubscription, this changes attachCollaborationServer. They should merge, but worth landing one and re-checking.

@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@SakethSumanBathini, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 88e915e9-cfcf-41b0-8314-2f316d5524ca

📥 Commits

Reviewing files that changed from the base of the PR and between 4c403cd and 1aeaba4.

📒 Files selected for processing (1)
  • backend/src/services/collaborationServer.ts

Comment @coderabbitai help to get the list of available commands.

@harsharajkumar-273 harsharajkumar-273 added ELUSOC Required Tracking VETERAN Advanced (50 pts) labels Aug 4, 2026
@harsharajkumar-273
harsharajkumar-273 merged commit 94c6412 into harsharajkumar-273:main Aug 4, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ELUSOC Required Tracking VETERAN Advanced (50 pts)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Security/Regression] Collaboration WebSocket rejects all connections — roomId is a team-session key, not a build session ID

2 participants