Repository navigation
fix(server-legacy): serve the RFC 8414 issuer without a trailing slash - #3184
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
|
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). |
koriyoshi2041
left a comment
There was a problem hiding this comment.
At a85d2029, the root-issuer case is covered, but issuerIdentifierOf() also rewrites a configured path issuer ending in /. RFC 8414 §2 only forbids query and fragment components; §3 explicitly describes removing a terminating slash while constructing the well-known URL, which means the slash can be part of the issuer identifier itself. For example, issuerUrl: new URL('https://auth.example.com/tenant/') is currently advertised (and returned as RFC 9207 iss) as https://auth.example.com/tenant, changing the configured security identifier rather than only its discovery location.
Could the normalization be limited to the root URL serialization case, and could a path-issuer regression preserve /tenant/ byte-for-byte? The focused router/authorize suites otherwise pass locally (51/51).
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.