fix(mcp): isolate OAuth request headers#33722
Open
rekram1-node wants to merge 2 commits into
Open
Conversation
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
requestInit.headersare used only for MCP resource requests, never OAuth PRM/authorization-server discovery, dynamic registration, token exchange, or refreshAuthorizationfields while preserving custom MCP resource headersAuthorizationas mutually exclusive with OAuth in connection, explicit auth, and debug pathsRelated issues
Security boundary
MCP resource headers may contain tenant credentials or other origin-scoped secrets. SDK 1.29 wrapped OAuth fetches with the complete resource
requestInit, allowing those headers to cross from the MCP resource origin to separately hosted protected-resource metadata, authorization server, registration, and token endpoints. The local SDK patch retains non-header request options for compatibility but removes resource headers from every OAuth-owned fetch. OAuth-generated metadata headers and client authentication remain intact.Compatibility
Authorizationcontinues to authenticate the MCP resource, but no OAuth provider is installed for that configurationAuthorizationTests
bun test test/mcp/oauth-header-isolation.test.tsbun test test/mcp/headers.test.tsbun typecheckfrompackages/opencodeThe integration coverage uses real loopback servers on ephemeral ports with distinct origins and no mocks, sleeps, or timers. It covers PRM and authorization-server discovery, DCR, authorization-code exchange, refresh, mixed-case
Authorization, resource canaries, and exactly one OAuth Basic client-auth header.