fix(auth): guard against silent subpath loss when AS metadata discovery fails#1807
Open
lanxevo3 wants to merge 3 commits intomodelcontextprotocol:mainfrom
Open
fix(auth): guard against silent subpath loss when AS metadata discovery fails#1807lanxevo3 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
…ry fails
When discoverAuthorizationServerMetadata() returns undefined, the SDK falls back
to constructing /authorize, /token, or /register from the authorizationServerUrl.
new URL('/authorize', 'https://example.com/admin') silently resolves to
https://example.com/authorize — the '/admin' subpath is completely lost.
This affects servers with non-root AS URLs (e.g. PRM returns
https://example.com/admin but the actual endpoints are at /admin/oauth/authorize).
The fix adds a guard at all three fallback locations: if pathname !== '/',
throw an informative error explaining the discovery failure and pointing to
the correct metadata endpoint, instead of silently producing a broken URL.
Fixes modelcontextprotocol#1716.
|
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
discoverAuthorizationServerMetadata()returns undefined (AS metadata endpoint returns 4xx or is unreachable), the SDK falls back to constructing authorization URLs using root-path defaults:The problem:
new URL('/authorize', 'https://example.com/admin')silently resolves tohttps://example.com/authorize— the/adminsubpath is completely lost. The actual correct endpointhttps://example.com/admin/oauth/authorizeis never reached, and no error is thrown.Reproduction
authorization_servers: ["https://example.com/admin"]https://example.com/.well-known/oauth-authorization-server/adminreturns 404new URL('/authorize', 'https://example.com/admin')→https://example.com/authorizeFix
Added a guard at all three fallback locations (
/authorize,/token,/register):The guard throws an informative error instead of silently producing a broken URL. The root-path fallback is kept for legitimate cases where the AS is at the domain root.
Fixes #1716.