Skip to content

mcp: restrict client transport redirects to the endpoint origin - #1437

Closed
granzer69 wants to merge 1 commit into
modelcontextprotocol:mainfrom
granzer69:cursor/http-transport-redirect-hardening-4064
Closed

granzer69 wants to merge 1 commit into
modelcontextprotocol:mainfrom
granzer69:cursor/http-transport-redirect-hardening-4064

Conversation

@granzer69

Copy link
Copy Markdown

Fixes #1429.

Streamable HTTP and SSE client transports currently use http.DefaultClient (or a user-provided client) without a redirect policy, so a malicious or compromised endpoint can redirect MCP POSTs to another origin and leak session headers and JSON-RPC bodies.

This change wraps the transport HTTP client when CheckRedirect is unset:

  • Allow redirects only to the same origin as the configured Endpoint (scheme + host).
  • Reject redirects that change the HTTP method of the original request.
  • If the caller sets HTTPClient.CheckRedirect, use it as-is (no extra policy).

Includes httptest-based tests for both transports (cross-origin blocked, same-origin redirect still works, custom CheckRedirect respected).

go vet ./... and go test ./... pass.

Wrap Streamable HTTP and SSE transport HTTP clients so that, when the
caller has not set CheckRedirect, redirects stay on the configured
endpoint origin and do not change the HTTP method. Callers that supply
their own CheckRedirect keep full control.
@guglielmo-san

Copy link
Copy Markdown
Contributor

Duplicate of #1440

@guglielmo-san guglielmo-san marked this as a duplicate of #1440 Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mcp: HTTP client transports follow redirects outside the endpoint origin

2 participants