You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Keep custom headers on the server's origin for the SDK's own OAuth requests - #3019
A server's custom headers no longer reach an authorization server on another origin through the OAuth work the SDK runs from inside the transport.
createTransportNode handed the headers to the SDK transport as requestInit.headers. The transport reads them there for its MCP requests, but it also builds the fetch for its own OAuth requests (discovery and token refresh behind a 401, when an authProvider is attached) as createFetchWithInit(fetch, requestInit) — so those inherited every header whatever their destination.
How
core/mcp/node/originScopedHeadersFetch.ts (new) — createOriginScopedHeadersFetch(fetch, origin, headers): a request to any origin other than origin is sent without the configured headers; a request to origin passes through untouched.
core/mcp/node/transport.ts — both HTTP transports are given that wrapper as their fetch. requestInit is unchanged.
core/mcp/node/fetchGuard.ts — CROSS_ORIGIN_HEADERS is exported, so the wrapper keeps the same negotiation headers the guard keeps on a cross-origin redirect hop.
It removes rather than adds because the SDK does more with requestInit.headers than send them (it unions a configured Accept with its own media types and deletes a configured Mcp-Session-Id from the handshake), so MCP requests are left exactly as the SDK builds them. The SDK's merge is { ...configured, ...own }; a configured header is taken off when the request still carries the configured value, i.e. did not set that name itself. Content negotiation / framing names (CROSS_ORIGIN_HEADERS + Content-Type) are left alone.
It does not reuse withServerOriginHeaders (#2985), which adds headers to the Inspector's own OAuth requests; here they are already merged in by the SDK and have to come off.
Affected paths
The CLI, mcpdo and the TUI, for a connection with stored tokens and no OAuth-specific settings (so directAuthRecovery is off and the SDK handles the 401). The web backend builds its transport through the same function but always intercepts auth challenges, so the SDK path never ran there.
Tests
clients/web/src/test/core/mcp/node/originScopedHeadersFetch.test.ts — the wrapper, plus both HTTP transports driven through a refresh against a cross-origin authorization server.
clients/web/src/test/integration/mcp/inspectorClient-transport-oauth-header-scope.test.ts — the same through InspectorClient as the Node clients build it, with and without a dedicated oauthFetch. Both fail on v2/main with x-api-key on the authorization server's metadata and token requests.
npm run local:gate passes. No UI change, so no screenshots.
…quests (#3018)
The server's custom headers were handed to the SDK transport as
requestInit.headers. The transport merges the whole requestInit into the
OAuth requests it makes itself (discovery and refresh behind a 401 when an
authProvider is attached), so an authorization server on another origin
received them.
They are now applied by a fetch wrapper on the transport's own fetch chain,
to requests for the MCP server's origin only, with the request's own headers
winning as before. MCP requests and same-origin requests are unchanged.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The transport changes can reintroduce stale MCP session IDs during initialization and drop configured Accept media types, risking connection failures and request incompatibility.
This PR closes the remaining custom-header leak in the shared Node transport: SDK-managed OAuth requests to another origin no longer inherit credentials configured for the MCP server.
Changes:
Adds an origin-scoped fetch wrapper that applies configured headers beneath each request’s own headers.
Uses the wrapper for Streamable HTTP and legacy SSE while removing headers from the SDK’s shared requestInit.
Adds wrapper, transport, and InspectorClient regression tests for cross-origin OAuth refresh.
File
Description
core/mcp/node/transport.ts
Applies origin-scoped headers to both HTTP transports.
…ding them (#3018)
Review: taking the headers out of requestInit changed what the SDK does with
them on MCP requests (the Accept union, the session-id removal on the
handshake). requestInit is left intact again, so MCP requests are built by
the SDK exactly as before, and the wrapper instead takes the configured
headers off any request that leaves the server's origin.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Copilot round 1 — both findings accepted, fixed in 01a0519.
Session ID restored on initialize and configured Accept dropped were both real regressions from moving the headers out of requestInit. Rather than mirror each SDK behaviour in the wrapper, the approach changed: requestInit.headers is left intact (MCP requests are built by the SDK exactly as on v2/main), and the wrapper only removes the configured headers from requests that leave the server's origin. Tests updated; the transport-level test now pins the Accept union. PR description updated to match.
Review: comparing through Headers joined a name configured under two
spellings into one value that matched neither removal condition once the
request overwrote one of them. The wrapper now weighs each key of the merged
record on its own, against every value configured for that name.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Copilot round 2 — one finding, accepted, fixed in f3f9f8c. A name configured under two spellings (or as repeated tuples) could survive removal because Headers joined the values before comparison. The wrapper now follows the SDK's raw-key merge: each key of the request is weighed on its own against every value configured for that name. Regression tests added for both inputs.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Cross-origin filtering can leak credentials when duplicate header names share identical values and strip SDK-owned OAuth authentication when it matches a configured value, breaking token refresh.
Do not strip matching OAuth Authorization credentials
core/mcp/node/originScopedHeadersFetch.ts:124
If a configured Authorization value equals the Basic authentication value the SDK independently generates for the OAuth client, this loop removes the SDK-owned header too, leaving the cross-origin token request unauthenticated and breaking refresh. Value equality cannot distinguish inherited headers from OAuth-owned authentication, so preserve that distinction before merging rather than exempting Authorization, which would restore the leak. Add a regression where the configured and OAuth-generated values are identical.
Review: two spellings of one name holding the same value were deduplicated
before the joined form was built, so a request carrying them already folded
("secret, secret") kept the header.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: cliffhall <cliff@futurescale.com>
Equal-value duplicate spellings (secret, secret) — accepted, fixed in 537b626, regression added (answered in its thread).
"Previously missed" (no thread): a configured Authorization identical to the Basic value the SDK generates for the OAuth client is removed too — declined. The observation is accurate and the header comment already states the limit: the SDK merges requestInit into its OAuth requests internally, so by the time a request reaches any fetch the Inspector can supply, an inherited value and an identical request-owned one are the same bytes. Preserving the distinction "before merging" means replacing the transport's private OAuth fetch (_fetchWithInit) — reaching into SDK internals that a version bump can rename silently — or a change in the SDK itself; neither is the contained Inspector-side change Custom headers reach a cross-origin authorization server through the SDK's transport-internal OAuth path #3018 asks for. The case also requires the user to have configured, as a custom header for the MCP server, exactly Basic base64(client_id:client_secret) of that server's OAuth client, and it fails closed: the refresh is refused and the user re-authorizes; nothing is disclosed. Exempting Authorization would restore the leak, as the finding itself notes.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because subtle header-normalization and credential-provenance interactions can expose cookies across origins or break OAuth token refresh.
Copilot review closed after round 4 — a clean round: no inline comments, no open issues, nothing suppressed. Rounds 1–3 raised four findings in threads (all fixed) and one without a thread (declined, reasoning above).
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
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.
Closes #3018
What
A server's custom headers no longer reach an authorization server on another origin through the OAuth work the SDK runs from inside the transport.
createTransportNodehanded the headers to the SDK transport asrequestInit.headers. The transport reads them there for its MCP requests, but it also builds the fetch for its own OAuth requests (discovery and token refresh behind a401, when anauthProvideris attached) ascreateFetchWithInit(fetch, requestInit)— so those inherited every header whatever their destination.How
core/mcp/node/originScopedHeadersFetch.ts(new) —createOriginScopedHeadersFetch(fetch, origin, headers): a request to any origin other thanoriginis sent without the configured headers; a request tooriginpasses through untouched.core/mcp/node/transport.ts— both HTTP transports are given that wrapper as theirfetch.requestInitis unchanged.core/mcp/node/fetchGuard.ts—CROSS_ORIGIN_HEADERSis exported, so the wrapper keeps the same negotiation headers the guard keeps on a cross-origin redirect hop.It removes rather than adds because the SDK does more with
requestInit.headersthan send them (it unions a configuredAcceptwith its own media types and deletes a configuredMcp-Session-Idfrom the handshake), so MCP requests are left exactly as the SDK builds them. The SDK's merge is{ ...configured, ...own }; a configured header is taken off when the request still carries the configured value, i.e. did not set that name itself. Content negotiation / framing names (CROSS_ORIGIN_HEADERS+Content-Type) are left alone.It does not reuse
withServerOriginHeaders(#2985), which adds headers to the Inspector's own OAuth requests; here they are already merged in by the SDK and have to come off.Affected paths
The CLI,
mcpdoand the TUI, for a connection with stored tokens and no OAuth-specific settings (sodirectAuthRecoveryis off and the SDK handles the401). The web backend builds its transport through the same function but always intercepts auth challenges, so the SDK path never ran there.Tests
clients/web/src/test/core/mcp/node/originScopedHeadersFetch.test.ts— the wrapper, plus both HTTP transports driven through a refresh against a cross-origin authorization server.clients/web/src/test/integration/mcp/inspectorClient-transport-oauth-header-scope.test.ts— the same throughInspectorClientas the Node clients build it, with and without a dedicatedoauthFetch. Both fail onv2/mainwithx-api-keyon the authorization server's metadata and token requests.npm run local:gatepasses. No UI change, so no screenshots.🤖 Generated with Claude Code