fix(api): scope workspace API tokens to their workspace#369
fix(api): scope workspace API tokens to their workspace#369cavidelizade wants to merge 1 commit into
Conversation
A "workspace service token" set a WorkspaceID on the row, but UserFromAPIToken ignored it and returned the full user, so a token handed out as scoped to one workspace could reach every other workspace the owner belonged to, /users/me, and even mint more personal tokens. RequireAuth now enforces the scope: when a bearer token carries a WorkspaceID, the request must target that workspace (its :slug resolves to the token's workspace), otherwise it's 403. Personal tokens (no WorkspaceID) and cookie sessions are unchanged, so the blast radius is limited to workspace tokens. Covered by a test: a workspace token reaches its own workspace, is denied on another workspace and on /users/me, while a personal token still works everywhere. Closes Devlaner#325 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 36 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. 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 (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Summary
A "workspace service token" set a
WorkspaceIDon its row, butUserFromAPITokenignored it and returned the full user, so a token handed out as scoped to one workspace could reach every other workspace the owner belonged to,/users/me, and even mint more personal tokens. The scope column was decorative.Linked issues
Closes #325
Type of change
fix:)Surface
apps/api/)What changed
RequireAuthnow enforces the scope: when a bearer token carries aWorkspaceID, the request must target that workspace (its:slugresolves to the token's workspace), otherwise it returns 403. Personal tokens (noWorkspaceID) and cookie sessions are untouched, so the change only affects workspace-scoped tokens.auth.Service.UserFromAPITokenScopedreturns the token record alongside the user.auth.Service.SlugMatchesWorkspaceresolves the route:slugand compares it to the token's workspace.Why this approach
Doing the check in
RequireAuth, gated ontok.WorkspaceID != nil, keeps the common paths (sessions, personal tokens) on exactly their existing code path, so a mistake here can only affect the rarely-used workspace-token feature.Test plan
go build,go vet,go test ./...green, includingTestWorkspaceTokenScope: a workspace token reaches its own workspace, is denied on another workspace and on/users/me, and a personal token still works everywhere.AI assistance
Claude Code (Opus 4.8), commits carry aCo-Authored-By:trailer