-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(client): SEP-2352 per-authorization-server credential isolation #2348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
felixweinberger
merged 1 commit into
fweinberger/auth-1-sep2468-client
from
fweinberger/auth-5-sep2352-isolation
Jun 24, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| "@modelcontextprotocol/client": minor | ||
| "@modelcontextprotocol/server-legacy": minor | ||
| --- | ||
|
|
||
| SEP-2468 follow-up: `transport.finishAuth()` gains a `URLSearchParams` overload (preferred) that extracts `code`/`iss`, validates `iss` first, and on mismatch throws a sanitized `IssuerMismatchError` (no callback `error_description` text); callers remain responsible for `state`. **Behavior change for `@modelcontextprotocol/server-legacy`:** `mcpAuthRouter` now advertises `authorization_response_iss_parameter_supported` (default `true`; `ProxyOAuthServerProvider` reports `false`) and the bundled authorize handler appends `iss` (RFC 9207) to every `res.redirect(...)` your `OAuthServerProvider.authorize()` issues to the client's `redirect_uri`. If your provider redirects another way (`res.writeHead`, a separate consent-page response, or a standalone `authorizationHandler({provider})` without `issuerUrl`), append `params.issuer` as `iss` yourself or set `authorizationResponseIssParameterSupported: false` — otherwise RFC 9207-compliant clients (including this SDK) will reject the callback. | ||
|
Check warning on line 6 in .changeset/auth-iss-server-and-overload.md
|
||
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 On the no-code (error-shaped) callback path,
resolveAuthorizationCallbackParams()falls back to a freshdiscoverOAuthServerInfo(serverUrl, opts), but itsoptstype only accepts{ fetchFn, resourceMetadataUrl }, so the user-configuredskipIssuerMetadataValidationflag (which both transports hold and pass toauth()on the code-present leg one statement later) is never forwarded. For the documented known-misconfigured-AS opt-out case, the fresh discovery throwsIssuerMismatchError, the barecatchswallows it, and the genericUnauthorizedError('Authorization callback failed and the issuer could not be verified')replaces the AS's real OAuth error — inconsistent behavior between the two legs of the samefinishAuthoverload. Fix: addskipIssuerMetadataValidationto the resolver's opts and forwardthis._skipIssuerMetadataValidationfrom bothSSEClientTransport.finishAuthandStreamableHTTPClientTransport.finishAuth.Extended reasoning...
The gap. The new shared resolver
resolveAuthorizationCallbackParams(codeOrParams, iss, provider, serverUrl, opts)(packages/client/src/client/auth.ts:561-588) declaresoptsas only{ fetchFn?: FetchLike; resourceMetadataUrl?: URL }. On theURLSearchParamsoverload's no-code path (an error-shaped callback), when the provider has no recordeddiscoveryState, the resolver runs a freshdiscoverOAuthServerInfo(serverUrl, opts)to obtain an authentic issuer baseline before surfacing the callback's error params.discoverOAuthServerInfo()accepts askipIssuerMetadataValidationoption and forwards it todiscoverAuthorizationServerMetadataasskipIssuerValidation(auth.ts:1744/1777) — but the resolver's opts type doesn't even allow the flag, and neither transport passes it.\n\nThe inconsistency this PR introduces. BothSSEClientTransportandStreamableHTTPClientTransportholdthis._skipIssuerMetadataValidation(the documented opt-out for a known-misconfigured AS, per migration.md) and pass it toauth()on the code-present leg of the very samefinishAuthcall — one statement after theresolveAuthorizationCallbackParamscall that omits it (e.g. streamableHttp.ts:860-875, and the same pattern in sse.ts). So a user who explicitly opted out of the RFC 8414 §3.3 issuer-echo check gets it honored when the callback carries acode, but silently ignored when the same callback is error-shaped.\n\nCode path / step-by-step proof.\n1. A user connects to an MCP server whose AS publishes metadata with a mismatchedissuer(the documented known-misconfigured-AS case), and setsskipIssuerMetadataValidation: trueon the transport options.\n2. The AS rejects the authorization request (e.g. user denies consent, orunauthorized_client) and redirects back witherror=access_denied&error_description=...and nocode.\n3. The host callstransport.finishAuth(new URL(callbackUrl).searchParams)— the preferred overload this PR adds.\n4.resolveAuthorizationCallbackParamssees nocode; the provider has no cacheddiscoveryState(e.g. it doesn't implement the optional method, or state was lost across the redirect), so it callsdiscoverOAuthServerInfo(serverUrl, { fetchFn, resourceMetadataUrl })— without the flag.\n5.discoverAuthorizationServerMetadataruns the issuer-echo check, the misconfigured AS fails it, andIssuerMismatchErroris thrown (auth.ts:1682).\n6. The resolver's barecatch { metadata = undefined; }swallows it,metadatastaysundefined, and the function throws the genericUnauthorizedError('Authorization callback failed and the issuer could not be verified')— replacing the AS's realerror/error_description(e.g.access_denied) that the user opted in to receiving from this AS.\n\nWhy nothing else prevents it. The flag is threaded everywhere else on this surface: the transports pass it toadaptOAuthProvider()at construction and toauth()in bothfinishAuthlegs and the 401 path — only this new fresh-discovery fallback misses it. Providers that do implementdiscoveryState()and have cached metadata from the redirect leg avoid the fresh discovery entirely, which narrows the impact, but the resolver explicitly handles the no-cached-state case (its own comment says it mirrors whatauth()does on the code-present path — andauth()does receive the flag there).\n\nImpact. No security regression and no mainline functional break — the flow was failing anyway, and the failure mode is a degraded diagnostic: the operator/user sees a generic "issuer could not be verified" error instead of the AS's actual OAuth error, and the documented opt-out behaves inconsistently between the two legs of one overload. All three verifiers confirmed the trace; none refuted it.\n\nFix (trivial). AddskipIssuerMetadataValidation?: booleanto the resolver'soptstype, forward it intodiscoverOAuthServerInfo(serverUrl, opts)(it already accepts it), and passskipIssuerMetadataValidation: this._skipIssuerMetadataValidationfrom both transports'resolveAuthorizationCallbackParamscall sites — mirroring what they already do for theauth()call directly below.