Fix scoped JWTs#679
Conversation
…() walked the route's declared scope and fell through to a workspace match, so a {w: ws-a, p: alice} token could act on any peer in ws-a.
WalkthroughThis PR rewrites JWT authorization logic to enforce token-scope-driven access control: ChangesJWT Authorization Scope Enforcement
🎯 3 (Moderate) | ⏱️ ~25 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/routers/webhooks.py (1)
40-41: 💤 Low valueOptional: Defensive workspace checks are now redundant.
The workspace validation on these lines is now performed by the
auth()function insrc/security.py(lines 199-200, 206-207, 214-215). These checks could be removed sinceauth()already enforces workspace scope matching.However, keeping them provides defense-in-depth and has no functional impact.
Also applies to: 64-65, 82-83, 96-97
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/routers/webhooks.py` around lines 40 - 41, Remove the redundant workspace validation checks that duplicate auth()'s scope enforcement: locate the exact conditional "if not jwt_params.ad and jwt_params.w is not None and jwt_params.w != workspace_id: raise AuthenticationException('Unauthorized access to resource')" in src/routers/webhooks.py (there are four occurrences) and delete those lines; rely on the existing auth() implementation in src/security.py to enforce workspace matching, or if you prefer defense-in-depth, wrap them with a clear comment referencing auth() to justify retention.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/routers/webhooks.py`:
- Around line 40-41: Remove the redundant workspace validation checks that
duplicate auth()'s scope enforcement: locate the exact conditional "if not
jwt_params.ad and jwt_params.w is not None and jwt_params.w != workspace_id:
raise AuthenticationException('Unauthorized access to resource')" in
src/routers/webhooks.py (there are four occurrences) and delete those lines;
rely on the existing auth() implementation in src/security.py to enforce
workspace matching, or if you prefer defense-in-depth, wrap them with a clear
comment referencing auth() to justify retention.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: cdb29c86-f115-4044-adaa-9cd388d5a267
📒 Files selected for processing (5)
src/routers/webhooks.pysrc/security.pytests/conftest.pytests/routes/test_scoped_api.pytests/test_security.py
Peer- and session-scoped JWTs were effectively workspace-scoped: auth…() walked the route's declared scope and fell through to a workspace match, so a {w: ws-a, p: alice} token could act on any peer in ws-a.
Summary by CodeRabbit
Bug Fixes
Tests