Skip to content

Close a stored XSS and four cross-team realtime leaks - #114

Merged
imshashank merged 1 commit into
mainfrom
security-scopes
Aug 6, 2026
Merged

imshashank merged 1 commit into
mainfrom
security-scopes

Conversation

@imshashank

@imshashank imshashank commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Findings from an adversarial security review of main. Each was reproduced against the real stack before being fixed.

Stored XSS in the doc renderer

renderMarkdownWithHeadingIds sanitized the markdown and then re-opened the sanitized HTML with a regex to splice in an anchor id:

const HEADING_TAG = /<h([1-3])((?:\s[^>]*)?)>([\s\S]*?)<\/h\1>/gi;
return `<h${level}${attrs} id="${id}">${inner}</h${level}>`;

[^>]* stops at the first bracket, and the sanitizer legitimately keeps attribute values that contain one, because that is spec-legal HTML and neither serializer escapes it. So stored content of the form

<h1 title="a><img src=x onerror=alert(1)>">Release notes</h1>

survives sanitization as one inert h1, and then the splice puts id="..." in the middle of the title value, closing the quote early. The browser then sees a real <img> with a live onerror. There is no Content-Security-Policy on the app, so it executes as whoever opened the doc, in the app origin. Any member with doc:write could plant it.

Three changes, each sufficient on its own, kept together as layers: the pattern now understands quoted attribute values, the spliced result is sanitized again rather than trusted, and id is allowed only on heading elements so the second pass cannot be used to smuggle one onto anything else.

Four publishers attached an org scope to rows that are not org-wide

The hub authorizes an org: scope on organization membership alone, with no role or team test, and every signed-in browser subscribes to it. So an org scope means "everyone in the workspace".

Publisher What leaked
completeCycle every rolled-over issue, title and description, to the whole org instead of the owning team
removeMember the same, for every reassigned issue
markAttachmentReady file name, size, storage key and parent id for every upload
/api/attachments/presign the same, on every upload, including onto private docs

The sprint case is the worst of them: completing a sprint is routine, cycle:manage is a member permission rather than an admin one, and every unfinished issue rolls over, so a full sprint of another team's work went out on each close.

All four now use the scopes the rest of the codebase already uses (issueScopes, and a new attachmentScopes that derives from the parent rather than the organization). The catch-up path had every one of these right, filtering through visibleToPrincipal and readableDocIds, which is what shows these were bugs rather than intent: only the live publish path skipped the gate.

A live socket never re-read membership or role

ConnectionPrincipal.teamIds and .role were captured once at authentication and never refreshed. revalidateAffected returned early for everything except a member delete.

Two consequences. Someone removed from a team kept receiving that team's issue, comment and reaction deltas for as long as they left the tab open. And an admin demoted to guest kept role: 'admin' on the connection, which short-circuits scope authorization for team, project, issue and doc scopes, so they could subscribe to anything in the workspace after the demotion, not merely keep what they already had.

The hub now refreshes the principal on any team_member or member change and re-authorizes every scope the connection holds, dropping the ones that no longer pass. If the refresh throws, the connection closes rather than continuing on stale permissions.

Not in this PR

Six lower-severity findings from the same review are still open and tracked: team-restricted projects and their milestones carry an org scope, unshared saved views do too, signing out does not close the socket, the orbit.read MCP scope is not enforced, presigned uploads carry no server-side size cap, and the analytics CSV export does not escape formula-leading characters. The project and milestone ones need the owning teams computed rather than simply dropping the org scope, or list updates stop arriving, so they want their own change.

From an adversarial review of main. Every finding below was reproduced
before it was fixed.

Stored XSS in the doc renderer. renderMarkdownWithHeadingIds sanitized
first and then re-opened the result with a regex to splice in an anchor
id. The attribute chunk was captured with [^>]*, which stops at the
first bracket, and the sanitizer legitimately keeps attribute values
containing one, because that is spec legal HTML. So a heading written as
<h1 title="a><img src=x onerror=...>"> had the id spliced into the
middle of its own title value, closing the quote early and handing the
browser a live img element. There is no CSP, so that ran as the viewer.
The pattern now understands quoted values, and the result is sanitized
again afterwards rather than trusted, with id allowed only on headings.

Four publishers attached an org scope to rows that are not org wide. The
hub authorizes an org scope on membership alone, and every browser
subscribes to it, so anyone in the workspace received them:

- completeCycle sent every rolled over issue, title and description
  included, to the whole org rather than the owning team. Sprint
  completion is routine and cycle:manage is a member permission, so a
  full sprint of another team's work leaked on each close.
- removeMember did the same for every reassigned issue.
- markAttachmentReady and the presign route announced every upload with
  its file name, size and storage key, including uploads onto private
  docs and onto other teams' issues.

All four now use the same scopes the rest of the code already uses.
The catch up path had these right, which is what showed they were bugs:
only the live publish skipped the gate.

A live socket also never re-read membership or role. A person removed
from a team kept receiving that team's deltas until they disconnected,
and an admin demoted to guest kept role admin on the connection, which
short circuits scope authorization, so they could subscribe to anything
in the org afterwards. The hub now refreshes the principal on a
team_member or member change and drops every scope that no longer
authorizes, failing closed if the refresh throws.

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imshashank has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@vercel

vercel Bot commented Aug 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orbit Ready Ready Preview Aug 6, 2026 11:14am

Request Review

@coderabbitai

coderabbitai Bot commented Aug 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 28 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 21722aa2-79c2-4555-b8f8-2a49d48554eb

📥 Commits

Reviewing files that changed from the base of the PR and between d5c984a and 1764dba.

📒 Files selected for processing (10)
  • apps/web/src/app/api/attachments/presign/route.ts
  • packages/core/src/content/attachment-service.ts
  • packages/core/src/org/member-service.ts
  • packages/core/src/work/cycle-service.ts
  • packages/realtime-server/src/auth.ts
  • packages/realtime-server/src/connection.ts
  • packages/realtime-server/src/hub.ts
  • packages/services/src/markdown/index.ts
  • packages/services/src/markdown/sanitize.ts
  • packages/services/tests/markdown/heading-id-xss.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@imshashank
imshashank merged commit 41948dc into main Aug 6, 2026
7 checks passed
@imshashank
imshashank deleted the security-scopes branch August 7, 2026 18:54

This branch was successfully deployed

1 active deployment
Preview — 1764dbaf Deployed Aug 6, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant