Repository navigation
fix(oauth): refresh an expired token behind an insufficient_scope challenge - #2738
Merged
Merged
Conversation
…llenge Some resource servers answer an expired access token with 403 insufficient_scope. checkAuthChallengeSatisfied() tested only scope for that reason, so it reported the challenge satisfied, the transport replayed the same dead token, and recovery gave up without trying the refresh token: the gap #2051 closed for token_expired. insufficient_scope now also requires a provably unexpired token. Callers that have just completed a grant pass { scopeOnly: true }: the refresh, re-mint and forced re-authorization legs in handleAuthChallenge, the runner after its callback, and the web client on OAuth resume. A freshly issued opaque token has no readable exp, so the liveness test would reject it. An EMA challenge whose scope storage already covers skips the step-up confirm, since re-minting it broadens nothing. Closes #2724 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: cliffhall <[email protected]>
2 tasks done
There was a problem hiding this comment.
🟡 Changes recommended
Tokens with omitted scope still bypass valid refresh tokens despite sufficient persisted scope.
1 open issue
What changed in this PR
Updates shared OAuth recovery for servers that report expired tokens as insufficient_scope, addressing #2724.
Changes:
- Requires token-liveness evidence before skipping recovery.
- Adds scope-only checks after grants and avoids unnecessary EMA consent prompts.
- Updates regression tests and authentication documentation.
| File | Description |
|---|---|
| specification/v2_auth_mid_session.md | Documents revised recovery behavior. |
| core/mcp/oauthManager.ts | Adds liveness checks and adjusts recovery. |
| core/mcp/inspectorClient.ts | Forwards challenge-check options. |
| core/auth/node/runner-interactive-oauth.ts | Uses scope-only checks after callbacks. |
| core/auth/challenge.ts | Defines scope-only check options. |
| clients/web/src/test/core/mcp/oauthManager.test.ts | Adds expired-token recovery regressions. |
| clients/web/src/test/core/auth/runner-interactive-oauth.test.ts | Checks runner option forwarding. |
| clients/web/src/hooks/useOAuthRecovery.ts | Uses scope-only checks after OAuth resume. |
| clients/web/src/hooks/useOAuthRecovery.test.tsx | Checks resume option forwarding. |
Review effort: Balanced
A token response may omit `scope` when it equals the request. The forceReauthorization decision compared the challenge only with the token's own scope, so a covered challenge on an expired token with no token scope forced interactive authorization instead of using the refresh token. Use resolveEffectiveGrantedScope, as checkAuthChallengeSatisfied does. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Signed-off-by: cliffhall <[email protected]>
Member
Author
|
Copilot round 1: 1 finding, fixed.
No suppressed comments. Requesting round 2. |
Member
Author
|
Copilot review loop closed: round 2 was clean (no inline comments, no suppressed findings; it reports the round-1 finding resolved). Stopping on the first clean round. |
2 tasks done
This was referenced Oct 21, 2026
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.

Closes #2724
Problem
Some resource servers (the reporter's case is an AWS Bedrock AgentCore Gateway) answer an expired access token with
403 insufficient_scopeinstead of401 invalid_token.OAuthManager.checkAuthChallengeSatisfied()tested only scope coverage for that reason. So it reported the challenge satisfied,handleAuthChallengetold the transport to retry, the same dead token was replayed, andstartWithRecoverygave up after one identical 403. The refresh token was never tried. This is the gap #2051 closed fortoken_expired, never carried over toinsufficient_scope.Change
Follows the approach agreed in the issue thread, with one addition (the external post-grant callers, below).
insufficient_scopenow also requires a provably unexpired token (isAccessTokenProvablyUnexpired, the same JWTexptesttoken_expireduses). An expired JWT or an opaque token with covered scope now returnsfalse, sohandleAuthChallengereachesmcpAuth. Scope is covered, so this is an ordinary refresh (forceReauthorization: false), not a forced re-auth.{ scopeOnly: true }(newCheckAuthChallengeSatisfiedOptions). A token that was just minted is live because the grant produced it, and a freshly issued opaque token has no readableexp, so the liveness test would turn a successful refresh into a failure. That applies to:handleAuthChallengethe thread identified (standard refresh, EMA silent re-mint,tryForceReauthorizationForStepUp)runner-interactive-oauth.ts) after its OAuth callback, and the web client's OAuth-resume check inuseOAuthRecovery. Without this, the gate's CLIoauth-interactiveintegration test failed, because a real step-up completed and was then rejected as "required scopes were not granted".step_up_confirm, a modal asking the user to approve a broader scope when nothing broader is requested. If storage already covers the challenge's scope, it now goes straight to silent re-mint. (Side effect 2 in the thread.)specification/v2_auth_mid_session.md: theinsufficient_scopebullet and both strategy tables are updated. The standard-OAuth "Silent: N/A" cell the thread called stale is now filled in.Accepted trade-off (same as #2051, agreed in the thread): for opaque-token servers,
insufficient_scopeloses the free short-circuit, including the in-mutex re-check after a concurrent step-up, and costs one extra silent refresh.Out of scope (per the thread): a same-token-retry fallback in
RemoteClientTransport.startWithRecovery().Tests
oauthManagertests (insufficient_scope challenge retry doesn't detect expired access token, gives up after one identical retry #2724 block), all failing on the unfixed source: expired JWT + covered scope is not satisfied; opaque + covered scope is not satisfied;handleAuthChallengerefreshes rather than replaying and accepts a refreshed opaque token; EMA re-mints withoutstep_up_confirm.{ scopeOnly: true }is passed.npm run local:gateis green.oauthManager.tscoverage: 99.66 / 99.07 / 100 / 99.65.No UI change, so no screenshots.
🤖 Generated with Claude Code