.NET: Add defense-in-depth for MCP cross origin request#6871
Open
TaoChenOSU wants to merge 2 commits into
Open
.NET: Add defense-in-depth for MCP cross origin request#6871TaoChenOSU wants to merge 2 commits into
TaoChenOSU wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR strengthens the .NET declarative-workflows MCP tool handler against credential leakage by pinning credential-bearing headers to the configured server origin and reducing transport/redirect-based cross-origin vectors.
Changes:
- Forces MCP transport to
HttpTransportMode.StreamableHttpto avoid legacy HTTP+SSE server-advertised message endpoints. - Disables
HttpClientHandlerauto-redirect and adds anOriginPinningHandlerthat strips credential headers on cross-origin requests. - Adds unit tests validating the origin-pinning behavior.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Workflows.Declarative.Mcp/DefaultMcpToolHandler.cs | Adds defense-in-depth origin pinning and tightens transport/redirect behavior to prevent cross-origin credential leakage. |
| dotnet/tests/Microsoft.Agents.AI.Workflows.Declarative.Mcp.UnitTests/DefaultMcpToolHandlerTests.cs | Adds regression tests for credential header stripping and handler behavior across origins. |
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.
Motivation & Context
A customer reported an origin-pinning weakness reachable through the declarative-workflows MCP handler. DefaultMcpToolHandler created its transport with HttpTransportMode.AutoDetect and passed caller-supplied credentials (including an Authorization: Bearer token) via HttpClientTransportOptions.AdditionalHeaders. Under AutoDetect, the client can negotiate down to the legacy HTTP+SSE transport, which trusts a server-advertised message endpoint. A malicious or compromised MCP server could advertise a cross-origin endpoint (or issue a redirect) and capture the bearer token, since the SDK re-stamps AdditionalHeaders onto requests built from that unverified URL. The owned HttpClient also left auto-redirect enabled, a second cross-origin leakage path.
Description & Review Guide
Behavioral note: the transport no longer negotiates down to legacy SSE. Servers reachable only via the legacy /sse + /message flow will need the standard Streamable HTTP endpoint. This is consistent with the MCP SDK's own default of disabling legacy SSE.
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.