Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(client,server-legacy): SEP-2468 server iss emission + finishAuth(URLSearchParams) overload#2357
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
v2-2026-07-28
from
fweinberger/auth-4-sep2468-serverJun 24, 2026
Uh oh!
There was an error while loading. Please reload this page.
Merged
feat(client,server-legacy): SEP-2468 server iss emission + finishAuth(URLSearchParams) overload #2357
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
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. | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -540,6 +540,69 @@ export function isStrictScopeSuperset(union: string | undefined, current: string | ||
| return false; | ||
| } | ||
| /** | ||
| * Shared `finishAuth` resolver for the `(code, iss?)` and `(URLSearchParams)` overloads. | ||
| * | ||
| * For the `URLSearchParams` form, only `iss` and `code` are read up front. When a `code` is | ||
| * present the returned values flow into {@linkcode auth}, which runs | ||
| * {@linkcode validateAuthorizationResponseIssuer} against freshly-discovered metadata before | ||
| * the code is redeemed — so on mismatch the thrown {@linkcode IssuerMismatchError} carries no | ||
| * `error`/`error_description`/`error_uri` text from the callback (those are attacker-controlled | ||
| * in a mix-up). When no `code` is present (an error-shaped callback), `iss` is validated here | ||
| * against the provider's recorded discovery state — or, when the provider does not implement | ||
| * `discoveryState`, against freshly-discovered metadata mirroring what {@linkcode auth} does on | ||
| * the code-present path — **before** the callback's error parameters are read; only after that | ||
| * passes are they surfaced as an {@linkcode OAuthError}. When no issuer baseline can be | ||
| * obtained either way, a generic {@linkcode UnauthorizedError} is thrown without surfacing the | ||
| * callback's `error`/`error_description`/`error_uri`. | ||
| * | ||
| * @internal Exported for the transport `finishAuth` overloads; not part of the public barrel. | ||
| */ | ||
| export async function resolveAuthorizationCallbackParams( | ||
| codeOrParams: string | URLSearchParams, | ||
| iss: string | undefined, | ||
| provider: OAuthClientProvider, | ||
| serverUrl: string | URL, | ||
| opts?: { fetchFn?: FetchLike; resourceMetadataUrl?: URL } | ||
| ): Promise<{ authorizationCode: string; iss: string | undefined }> { | ||
| if (typeof codeOrParams === 'string') { | ||
| return { authorizationCode: codeOrParams, iss }; | ||
| } | ||
| const issParam = codeOrParams.get('iss') ?? undefined; | ||
| const code = codeOrParams.get('code'); | ||
| if (code) { | ||
| return { authorizationCode: code, iss: issParam }; | ||
| } | ||
| // No code → error response. Gate the (potentially attacker-supplied) error params on the | ||
| // issuer first. Prefer the provider's recorded discovery state; when absent, mirror auth()'s | ||
| // code-present path and run a fresh discovery so the iss gate has an authentic baseline. | ||
| const discoveryState = await provider.discoveryState?.(); | ||
| let metadata = discoveryState?.authorizationServerMetadata; | ||
| if (!metadata) { | ||
| try { | ||
| const serverInfo = await discoverOAuthServerInfo(serverUrl, opts); | ||
felixweinberger marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| metadata = serverInfo.authorizationServerMetadata; | ||
| } catch { | ||
| metadata = undefined; | ||
| } | ||
| } | ||
| if (!metadata) { | ||
| // No authentic baseline → cannot prove the error params came from our AS. Do NOT surface | ||
| // attacker-controllable `error`/`error_description`/`error_uri` here. | ||
| throw new UnauthorizedError('Authorization callback failed and the issuer could not be verified'); | ||
| } | ||
| validateAuthorizationResponseIssuer({ | ||
| iss: issParam, | ||
| expectedIssuer: metadata.issuer, | ||
| issParameterSupported: isIssParameterSupported(metadata) | ||
| }); | ||
| const error = codeOrParams.get('error'); | ||
| if (error) { | ||
| throw new OAuthError(error, codeOrParams.get('error_description') ?? error, codeOrParams.get('error_uri') ?? undefined); | ||
| } | ||
| throw new UnauthorizedError('Authorization callback contained neither `code` nor `error`'); | ||
| } | ||
| export type ClientAuthMethod = 'client_secret_basic' | 'client_secret_post' | 'none'; | ||
| function isClientAuthMethod(method: string): method is ClientAuthMethod { | ||
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.
Uh oh!
There was an error while loading. Please reload this page.
Oops, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
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.
Uh oh!
There was an error while loading. Please reload this page.