fix(transport): validate redirect targets to prevent SSRF and protocol confusion (#2700) - #2725
Conversation
|
@modelcontextprotocol/client
@modelcontextprotocol/codemod
@modelcontextprotocol/core
@modelcontextprotocol/server
@modelcontextprotocol/server-legacy
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
b901a78 to
6d699d0
Compare
6d699d0 to
1e07b6a
Compare
|
This needs a transport-scoped approach before it is safe to merge.
Please avoid a generic manual-follow loop. Put an explicit redirect policy at the Streamable HTTP transport boundary, preserve existing Fetch semantics for callers that opt in to redirects, and add regressions for the default no-options path plus cross-origin authenticated 302/307 behavior. |
Summary
Fixes #2700 (mirroring the client security hardening from python-sdk #3358).
Under default
fetchbehavior,redirect: "follow"causes client transports to silently follow 3xx responses into internal loopback endpoints (127.0.0.0/8,localhost), cloud instance metadata (169.254.169.254,metadata.google.internal), and private subnets (RFC 1918).This PR introduces proactive redirect target validation in
createFetchWithInit:isSafeRedirectTarget/isPrivateOrLoopbackHost.allowLoopbackRedirectsoption for local dev and testing suites.redirect: 'manual'orredirect: 'error'.Motivation and Context
Fixes a security vulnerability where malicious MCP servers can redirect client requests into internal infrastructure or cloud metadata services.
How Has This Been Tested?
packages/core-internal/test/shared/transport.test.tsasserting:127.0.0.1,[::1],169.254.169.254, RFC 1918).allowLoopbackRedirects: true.1440/1440tests passed incore-internal,797/797tests passed inclient.pnpm -r typecheckclean.Breaking Changes
None.
Types of changes
Checklist