fix(server): do not burn pairing grants on a scope mismatch - #8426
fix(server): do not burn pairing grants on a scope mismatch#8426Adolanium wants to merge 1 commit into
Conversation
Token exchange consumed the one-time pairing grant, then rejected extra scopes. The QR was already gone. The caller had to mint another link. Check requested scopes against the grant first. Only consume after that check passes.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Comment |
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This is a narrowly scoped fix that preserves pairing grants after rejected scope requests and includes targeted tests. It changes production authentication behavior and touches the authentication package, so the auth safety rule warrants human review. You can add or adjust custom eligibility rules. Learn more. |
What Changed
Token exchange now checks requested scopes before it consumes the one-time pairing grant.
A client that asks for scopes the grant does not include still gets
ServerAuthScopeNotGrantedError. The grant stays unused, so a later exchange with allowed scopes still works.Why
Web and mobile always ask for standard client scopes. A constrained pairing plus that request burned the QR: one "invalid credential", mint another link. The unit test encoded the burn.
Checklist
Note
Medium Risk
Touches OAuth-style bootstrap token exchange in auth, but authorization rules are unchanged—only the order of scope validation vs. one-time consumption.
Overview
Bootstrap access-token exchange no longer consumes a one-time pairing grant when the client asks for scopes the grant does not allow.
exchangeBootstrapCredentialForAccessTokennow calls a newPairingGrantStore.inspect(read-only lookup with the same expiry, proof-key, and availability checks asconsume) beforeconsumewheneverrequestedScopesis set. Over-scoped requests still returnServerAuthScopeNotGrantedError, but the QR/link stays valid for a later exchange with permitted scopes.Tests now assert a failed over-scope exchange followed by a successful narrower exchange;
environment-auth.mddocuments that rejected scope requests leave the grant unused.Reviewed by Cursor Bugbot for commit 023d4e2. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Fix scope mismatch burning pairing grants in
exchangeBootstrapCredentialForAccessTokenPairingGrantStore.inspectto read a grant's scopes without consuming it, with proper error handling for unknown, consumed, revoked, expired, or proof-key-mismatched credentialsexchangeBootstrapCredentialForAccessTokennow callsinspectfirst; if requested scopes exceed the grant, it returnsServerAuthScopeNotGrantedErrorand leaves the grant usable for a subsequent valid exchangePairingGrantStore.consumeand issue a sessionMacroscope summarized 023d4e2.