Repository navigation
fix(server-legacy): serve the RFC 8414 issuer without a trailing slash - #3184
Open
Alter-Igor wants to merge 2 commits into
Open
Alter-Igor wants to merge 2 commits into
Alter-Igor wants to merge 2 commits into
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
…ing the metadata issuer
Author
|
Filed the companion issue per CONTRIBUTING preference: #3186 (contains the runnable reproduction and the iss-parameter second half of the fix that this PR's first CI run surfaced). |
This branch has not been deployed
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.
Summary
createOAuthMetadatawroteissuer: issuerUrl.href, andnew URL('https://host').hrefnormalizes tohttps://host/— so an authorization server constructed from a slash-less origin string advertised a slashed issuer.RFC 8414 §2 forbids a trailing slash on the issuer identifier, and §3.3 requires the metadata
issuerto be byte-identical to the URL the well-known document was fetched from. The practical break: an SDK server and an SDK client could not complete discovery against each other for root issuers — the client's ownIssuerMismatchErrorvalidation (metadata echo check) throws because the discovery URL has no slash while the metadata does. Other strict RFC 8414 clients fail the same way; we hit this in production (Central Agent Service atagent.alterspective.com.au: strict clients could not connect any OAuth-protected MCP behind it).The fix
Serve the issuer identifier slash-less: a small
issuerIdentifierOf()strips the single trailing slashnew URL()added, inpackages/server-legacy/src/auth/router.ts. Both spellings ofissuerUrl(with or without/) now produce the same compliant metadata. Endpoint URLs are unaffected — they resolve against the fullissuerUrlas before.mcpAuthMetadataRouter's PRMauthorization_serversentry inherits the corrected issuer automatically.Validation
packages/server-legacy/test/auth/router.test.ts: issuer served slash-less for bothnew URL('https://host')andnew URL('https://host/')clientpackage: 1076 passed; 2 pre-existing Windows-local failures intest/client/stdio.test.ts(timeouts, unrelated to OAuth — fail identically on a clean tree)eslint+prettierclean on both changed files;tsc --noEmitcleanissuerserved slash-less, and previously-failing strict clients now complete discoveryNotes
discoverAuthorizationServerMetadataalready validates the echo and (on main) tolerates a slashed discovery URL against a slash-less metadata issuer.resourceindicator; this is the server-sideissuerfield, still unfixed on main.