A minimal, runnable reproduction of the bug class Microsoft fixed in
microsoft/mcp-gateway v1.0.1
(published 2026-11-16): an MCP tool gateway that follows HTTP redirects
coming back from a tool call.
An MCP gateway dispatches a tool call to a tool pod and returns whatever
that pod responds with as the tool result. If the gateway's HTTP client
follows redirects by default — which is the default behavior of most
HTTP clients, including Python's urllib for GET requests — then a tool
pod doesn't have to return data directly. It can return an HTTP 302 with
a Location header pointing anywhere the gateway can reach: a cloud
metadata endpoint, an internal admin API, a sidecar that was never meant
to be exposed through a tool call.
The gateway then requests that URL on the tool pod's behalf, and returns that response as the "tool result." The agent on the other end has no way to tell the difference between a legitimate tool result and a value smuggled out of the gateway's own network by a tool pod that is malicious, compromised, or just misconfigured.
This is a textbook SSRF / confused-deputy bug: the gateway has more network reach than the tool pod does, and following a redirect hands that reach to whatever the tool pod points at. It doesn't matter whether the tool pod meant it — the gateway's job is to not trust it either way.
Microsoft's fix in v1.0.1, from the release notes:
Tool calls no longer follow HTTP redirects returned by tool pods. Previously, the tool gateway and agent runs sent tool invocations with an HTTP client that followed redirects, so a tool pod could redirect the gateway to another host it can reach and have that host's response returned as the tool result. A redirect from a tool pod is now returned as a tool error, and the redirect target is never requested.
Three tiny stdlib-only Python servers, no dependencies, no containers:
internal_service.py— stands in for the internal-only service: a secrets endpoint the gateway host can reach but nothing else should.tool_pod.py— stands in for the tool: on/invokeit returns a 302 pointing at the internal service, instead of a real tool result.gateway.py— the gateway itself, runnable in two modes:vulnerable: the pre-1.0.1 shape of the bug — default redirect following, so the internal secret comes back as the tool result.fixed: the v1.0.1 shape — redirects are detected and rejected as a tool error, and the target is never requested.
demo.sh starts all three, calls the vulnerable gateway and shows the
leak, then calls the fixed gateway against the exact same tool pod and
shows the error instead.
Requires only Python 3 (stdlib) and curl. No pip installs, no Docker,
no Kubernetes — this bug lives in HTTP client defaults, not in cluster
config, so the demo doesn't need a cluster either.
git clone https://github.com/themsquared/mcp-gateway-redirect-ssrf-demo.git
cd mcp-gateway-redirect-ssrf-demo
./demo.shValidated output, vulnerable mode:
{
"mode": "vulnerable",
"tool_result": "{\"secret\": \"admin-rotation-key-7f3a9c\", \"note\": \"internal-only: reachable from the gateway host, never from a tool call result\"}"
}Validated output, fixed mode, same tool pod:
{
"mode": "fixed",
"tool_error": "tool response was a redirect; redirects are never followed",
"status": 302,
"location_seen_not_followed": "http://127.0.0.1:29001/secret"
}If ports 29001–29004 collide with something already running on your
machine, override them: INTERNAL_PORT=39001 TOOL_PORT=39002 GW1_PORT=39003 GW2_PORT=39004 ./demo.sh (see the top of demo.sh for the full list of override variables).
This isn't a knock on microsoft/mcp-gateway specifically — they found
it, fixed it fast, and published exactly how. The actual lesson is
architectural: any MCP gateway that proxies tool calls with a
general-purpose HTTP client needs to make an explicit decision about
redirects, because "follow redirects" is usually the client library's
default, not something anyone chose. The same question applies to
agentgateway and to any other MCP/tool gateway: does the HTTP client
used for outbound tool calls follow redirects, and if so, has anyone
actually decided that's safe for a response that was never meant to be
trusted in the first place?
- This demo reproduces the class of bug described in the public
release notes, using a minimal gateway built for this repo — it does
not run Microsoft's actual
mcp-gatewaybinary pre- and post-patch. Reproducing against the real binary would need its specific deployment shape (Azure template, container images); that's out of scope for a same-day demo. - Every command in this README was run against this repo's own code on 2026-11-18 and the output above is copied from that run.
Apache-2.0. See LICENSE.
GitHub topics: mcp, ssrf, ai-agents, security, agentgateway, kubernetes