Repository navigation
fix(api): authorize API-key clients on delete/cancel purchase permission check - #1491
Conversation
…ion check requireDeleteOrCancelPurchasePermission hand-rolled its own auth dispatch (admin API key -> session) and dropped the user-API-key branch that every other permission gate relies on via requirePermission/authorizeAPIKey. Scoped API-key automation clients presenting only an x-api-key header got a 401 "no authorization token provided" instead of being authorized against their key's granted verbs, even when the key held delete:purchases. Add requireAnyPermission/authorizeAPIKeyAny as the multi-verb counterparts to the existing requirePermission/authorizeAPIKey dispatch chain, and delegate requireDeleteOrCancelPurchasePermission to it so the delete/cancel gate cannot drift from the single-verb dispatch order used everywhere else. Also widen the verb set to include update-any so a custom group holding only that permission clears this entry gate before ownership is checked. Follow-up to #1421, which introduced the hand-rolled gate. Also updates a pre-existing sibling test (TestDeletePlannedPurchase_PermissionGate) whose mock set predates the update-any verb addition.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 58 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: defaults Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
@coderabbitai review |
✅ Action performedReview finished.
|
Summary
requireDeleteOrCancelPurchasePermission(gatingDELETE /api/purchases/planned/{id}) hand-rolled its own auth dispatch instead of using the sharedrequirePermissionpath, and in doing so dropped the user-API-key branch entirely. A scoped API-key automation client presenting only anx-api-keyheader (no bearer token) got a 401no authorization token providedon delete/cancel, even when the key helddelete:purchases.This is a follow-up to #1421, which introduced the hand-rolled gate while adding cancel-own support.
Fix
requireAnyPermission/authorizeAPIKeyAnyas multi-verb counterparts to the existingrequirePermission/authorizeAPIKeydispatch chain (principal-in-context -> admin API key -> user API key -> bearer-token session), so a multi-verb gate can't drift from the single-verb dispatch order every other endpoint relies on.requireDeleteOrCancelPurchasePermissionnow delegates torequireAnyPermissioninstead of hand-rolling dispatch.update-anyso a custom group holding only that permission clears this entry gate before the ownership check runs (documented in the code comment; doesn't widen the effective grant sinceupdate-anyalready passes the later ownership-scoped cancel check).authorizeAPIKeyandauthorizeAPIKeyAnyfail closed: an incomplete identity after a granted check is a hard error, and a denied-but-valid key returns 403 rather than silently falling through to bearer-token auth.Test plan
go build ./...— cleango vet ./...— cleango test ./...(full repo) — all packages pass, 0 failuresTestHandler_deletePlannedPurchase_UserAPIKey_Allowedverified to fail pre-fix (401no authorization token provided, reproducing the reported bug) and pass post-fixTestDeletePlannedPurchase_PermissionGatewhose mock set predated theupdate-anyverb additiongolangci-lint(CI-pinned v2.10.1) oninternal/api/...: 2 pre-existing findings, both outside this diff's changed lines (unrelated debt at handler_purchases.go:1832 and :2545)gocyclo -over 10on changed files: clean