fix(server): scope personal access token deletion to the caller's tenant - #375
fix(server): scope personal access token deletion to the caller's tenant#375yuvrajjsingh0 wants to merge 1 commit into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
WalkthroughToken deletion now resolves the organisation and application scope, deletes only matching personal access tokens, and returns ChangesTenant-scoped token deletion
Estimated code review effort: 2 (Simple) | ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 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 |
62e3b0c to
3fe3bf4
Compare
Problem
delete_tokenresolved the caller's organisation and application, then threw both away:The delete predicate was the client id alone. A client id is an identifier, not a secret — it is returned by the create and list APIs and stored by clients. So the authorisation check ran against one tenant while the write landed on any tenant: an authorised admin or owner who learned another organisation's client id could delete that organisation's credential.
list_tokensalready filtered onusername+organisation+application, so the two paths disagreed about what a caller may touch.Audit reference: S7.
Change
scoped_token_deleteso the scoping is directly testable without a database.Deliberately not scoped by username
The audit suggested optionally also scoping by owning username. I did not do that: this endpoint is gated to org
owner/adminand appadmin, and revoking a compromised token that belongs to another user in your own tenant is a legitimate administrative capability. Narrowing to username would remove it. The cross-tenant hole is fully closed by the org/app scoping. Happy to add the username filter if you'd rather tokens be strictly self-service — it is a one-line change inscoped_token_delete.Testing
Two unit tests assert on the generated SQL via
diesel::debug_query, so they need no database:Both were verified non-vacuous — restoring the original unscoped predicate fails them with the vulnerable SQL printed:
The second test guards the filters staying
AND-joined, so a later edit cannot widen the predicate back out with anOR.cargo fmt --checkandcargo clippy --all-targets -- -Dwarningspass.Notes
This operation is not in the Smithy model and the docs only refer to token revocation generically, so no documentation or API-reference regeneration applies.
🤖 Generated with Claude Code
Summary by CodeRabbit