fix(auth): deduplicate concurrent auth() calls to prevent rotating refresh token race#1803
Open
lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
fix(auth): deduplicate concurrent auth() calls to prevent rotating refresh token race#1803lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Conversation
OAuth 2.1 §3.2 requires token endpoint requests to use application/x-www-form-urlencoded regardless of grant type. Add an explicit header.set() call immediately before the fetch in executeTokenRequest() to prevent any addClientAuthentication implementation from accidentally overriding the Content-Type. Fixes modelcontextprotocol/inspector#1160
…en race When two requests receive a 401 simultaneously, both call auth() which each call refreshAuthorization() with the same rotating refresh token. OAuth servers that implement RFC 6819 §5.2.2.3 replay detection revoke the entire token family on seeing a reused refresh token — permanently breaking the session until manual re-authorization. The fix adds a pending-auth Map that tracks in-flight auth Promises per provider. Concurrent callers receive the same Promise and wait for one refresh instead of each triggering their own, which is safe for both rotating and non-rotating token schemes. Fixes modelcontextprotocol#1760.
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
When two requests receive a 401 simultaneously, both call \�uth()\ which each call
efreshAuthorization()\ with the same rotating refresh token. OAuth servers that implement RFC 6819 §5.2.2.3 replay detection revoke the entire token family on seeing a reused refresh token — permanently breaking the session until manual re-authorization.
Fix
Adds a \pendingAuth\ Map that tracks in-flight \�uth()\ Promises per provider. Concurrent callers for the same provider receive the same Promise and wait for one refresh instead of each triggering their own. Safe for both rotating and non-rotating token schemes.
\\ s
// Before: race condition
const [r1, r2] = await Promise.all([
auth(provider, options), // both call refreshAuthorization()
auth(provider, options), // with the same rotating token
]);
// After: only one refresh runs
const pending = pendingAuth.get(provider);
if (pending !== undefined) return pending; // wait for in-flight instead
\\
Fixes #1760.