fix(security): refuse an unresolvable session in requirePreviewAccess — Closes #205 - #210
Conversation
|
Warning Review limit reached
Next review available in: 55 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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
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. Comment |
9197a26
into
harsharajkumar-273:main
Closes #205
The guard
backend/src/routes/preview.routes.tsread the owner through an optional chain and guarded on truthiness:A falsy
ownernever reached the comparison, so execution fell through tonext(). That covered the case where the session was not in memory at all — which is not exotic, sincebuildExecutorholds sessions in a plainMapbehind a TTL timer with no persistence. Every restart and every expiry empties it, after which no session ID resolves.It leaked rather than merely failing open because the handler below does not need the in-memory session to serve files; it falls back to reading from disk. The documents were still there, and this check was the only thing between them and any other authenticated user.
After
The session is resolved once and refused when absent, rather than being reached through an optional chain that erases the difference between "no session" and "no owner".
404 rather than 403 for the missing case, matching
checkWorkspaceOwner: it does not reveal whether the ID ever existed, and 404 is already what these handlers return for a missing session.What this deliberately does not change
creatorLogin: nullstill passes for any authenticated user. That is the narrower hole flagged at the end of the issue, and it is a product question — sessions created outside an authenticated flow may be intended to be readable.checkWorkspaceOwnerinmiddleware/auth.tsretains the samecreatorLogin && .... Changing it here alone would make the two middlewares disagree about who may read what, which is worse than either behaviour consistently applied. If that case should also be refused, both need the same follow-up in a single change.The comment
The fix carries its reasoning inline, matching the one already on
checkWorkspaceOwner. The mechanism — in-memory Map, TTL expiry, disk fallback — is not visible from the three lines it explains, and this is the second time this exact guard has been written incorrectly in this codebase. The first fix did not stop the second occurrence; a comment at the site might.Verified
npx tsc --noEmitcleanpath.sepboundary check further down still runs, and was never the defectbackend/dev.dbuntouchedSecurity fix. Worth merging ahead of #203 and #204, both of which are hardening rather than a live leak.