fix: prevent API keys from minting elevated-scope keys - #167
Open
Oluwasegun6921 wants to merge 3 commits into
Open
Conversation
|
@Oluwasegun6921 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR closes a privilege-escalation vulnerability in the API-key creation flow. The
apps/api/src/routes/api-keys.tsrouter is gated onapi-keys:manage, then blindly issues a key carrying whateverscopesarray the caller supplies. Because nothing checked that the requested scopes are a subset of the calling key's scopes, any combination ofALL_SCOPESwas accepted — includingofframp:initiate. A deliberately narrow integration key (e.g. scoped only toapi-keys:managefor credential rotation) was therefore effectively a root key. The escalation reaches money:POST /links/:id/cash-outaccepts a caller-suppliedpayoutFieldsobject that overrides the seller's saved payout destination for that cash-out with no re-confirmation, so a leaked narrow key could self-issueofframp:initiateand redirect proceeds.This PR enforces the subset rule: API-key-authenticated callers can only mint keys whose scopes are a subset of their own; any requested scope the calling key does not hold is rejected with
403and the offending scopes named. Wallet-session callers remain the authority and can still request any scope.Related Issue
Closes issue 6.6 — An API key can mint itself a more powerful key (tracked in
ISSUES.md)Changes
🔐 Subset Scope Enforcement
apps/api/src/routes/api-keys.ts403and names the offending scopes.ALL_SCOPESis accepted.🧭 Auth Principal Distinction
apps/api/src/middleware/auth.ts🛡️ Scope Validation Hardening
apps/api/src/services/api-keys.tsALL_SCOPESmembership.🧪 Regression Tests
apps/api/src/routes/__tests__/api-keys.test.tsofframp:initiate) →403with offending scopes named.Verification Results
offramp:initiatecannot create a key that has it403returned, offending scopes named in responseapi-keys.test.tsCloses #159