Most MCP security reviews ask about OAuth first. The finding that surprises teams comes later: a tool that accepts a URL and fetches it. The agent chooses the URL. The agent may have read that URL in an email, a ticket, or a web page an attacker wrote. The request leaves from inside your network, with your server's network identity. That is server-side request forgery (SSRF), and an MCP tool makes it easier to reach than a normal API does.
This tutorial covers the controls a reviewer expects on any tool that makes an outbound request based on model-supplied input. It is the detailed version of the SSRF bullet in our post on network boundaries, egress, and secrets.
Why MCP changes the threat model
In a conventional API, a URL parameter comes from a developer-written client. In an MCP server, the argument comes from a model. The model is steered by content it has read, including content from third parties. OWASP lists SSRF as its own category in the Top 10 (A10:2021), and the MCP tool surface adds a path for it. Treat every URL, hostname, and file reference in a tool argument as attacker-influenced, even when the authenticated user is honest.
Typical tools that carry this risk:
- "Fetch this page and summarize it", "import from URL", "attach a document by link".
- Webhook or callback registration.
- Tools that follow a link returned by a downstream API, such as a pre-signed download URL.
- Tools that accept a hostname for a connection test.
If a tool does not need arbitrary URLs, remove the capability. Replace a free-form URL with an identifier your server resolves itself. This is the strongest control and the cheapest.
What the attacker wants
The targets are predictable:
- Cloud metadata endpoints. The link-local address 169.254.169.254 serves instance credentials on several clouds. Prefer the hardened metadata modes your provider offers (for example, session-token-required metadata) and block the address at the network layer as well.
- Internal services. Admin consoles, databases with HTTP interfaces, and other services that trust the internal network.
- Loopback and the server's own endpoints, including the token endpoint or health and debug routes.
- Information from error messages. Timing and error text can reveal which internal hosts exist.
Control 1: Allowlist first
If the set of destinations is known, enforce it. Match on the exact scheme, host, and port. Do not use substring or suffix matching on strings such as "ends with example.com"; "example.com.attacker.net" and "attacker.net/example.com" both defeat naive checks. Allow https only unless you have a stated reason otherwise. Refuse file:, gopher:, ftp:, and any other scheme.
When the destination set is not known, because the tool is genuinely a fetcher, you need Control 2 as the primary defense.
Control 2: Validate after resolution, not before
Checking the hostname string is not enough. The check that matters runs on the IP address the connection will use.
- Resolve the hostname.
- Reject if any resolved address is loopback, link-local, private (RFC 1918), unique local (fc00::/7), multicast, or unspecified. Cover IPv4-mapped IPv6 addresses and alternate encodings of IPv4 (decimal, octal, hex). Use your language's IP parsing library and its classification methods rather than regular expressions.
- Connect to the validated address, not to the hostname again.
Step 3 is where most implementations fail. If you validate with one DNS lookup and connect with a second, an attacker's DNS server can answer with a public address the first time and an internal one the second. This is DNS rebinding. Pin the connection to the address you validated, and send the original hostname in the Host header and TLS server name so certificate checks still work.
Control 3: Redirects are new requests
A public URL can respond with a 302 to an internal address. Either disable redirects, or follow them manually, applying the full allowlist and address validation to each hop. Cap the number of hops. Do not let the HTTP client library follow redirects on its own with a validated first hop and an unvalidated rest.
Control 4: Bound the response
The fetch is also a resource-consumption path. Set:
- A connect timeout and a total timeout.
- A maximum response size, enforced while streaming, not after buffering.
- An allowed content-type list for the tool's purpose.
- A decompression limit, to stop a small compressed body from expanding without bound.
Do not return raw upstream error bodies to the model. Return a short, fixed error category. A verbose error is both an information leak and a prompt injection channel.
Control 5: Do not forward credentials
The outbound request should carry no ambient authority. Specifically:
- Never attach the user's MCP access token to the outbound request. That is token passthrough, which the MCP authorization specification forbids, and here it would also hand the token to a third party.
- Do not attach service credentials to a request whose destination the model chose.
- Run the fetcher in a separate process or network segment with no access to secrets, so a bypass lands in an empty room.
Control 6: Egress at the network layer
Application checks fail eventually. Put a second control underneath them. The workload that performs fetches should run in a subnet whose route table and firewall allow outbound traffic only through a proxy or NAT you control, with rules denying private ranges and the metadata address. Many teams use a forward proxy that applies the same address checks centrally. Whichever you choose, the application and the network should each be sufficient to stop the common cases alone.
Control 7: Log what the reviewer will ask about
Emit an audit event for each outbound request made on behalf of a tool call. Include the tool name, the authenticated user and tenant, the requested URL, the resolved address, the policy decision (allowed or denied and why), the response status, and the byte count. Denials matter more than successes. A burst of denied requests to 169.254.169.254 from one user is an incident signal your customer's SIEM should be able to alert on. Our post on audit events for MCP servers gives a schema to extend.
Redact query strings and fragments in logs if they can carry tokens or signed-URL secrets.
Test it before the reviewer does
Add these cases to the authorization regression suite described in our CI post, and to the pre-handover plan in our adversarial testing post:
| Input | Expected result |
|---|---|
http://169.254.169.254/ | Denied, logged |
http://127.0.0.1:<admin port>/ and http://[::1]/ | Denied, logged |
http://2130706433/ (decimal form of 127.0.0.1) | Denied |
| A hostname that resolves to a private address | Denied |
| A hostname that alternates between public and private answers | Connection pinned to the validated address |
| A public URL that redirects to an internal address | Denied at the redirect hop |
file:///etc/passwd | Denied by scheme |
| A response larger than the limit | Truncated or aborted, error category returned |
| A request carrying the user's bearer token to the destination | Never occurs; assert on captured outbound headers |
Run the DNS rebinding case against a controlled resolver you operate, not against third-party infrastructure.
What to put in the evidence pack
Reviewers want a short, checkable statement. Include which tools make outbound requests, the destination policy for each (allowlist or validated fetcher), the address classes blocked, the redirect and size limits, where the fetcher runs, and a sample audit event showing a denial. This belongs in the control matrix alongside the items in our evidence pack tutorial.
Limits of this advice
This covers outbound requests initiated by tool arguments. It does not cover SSRF inside your downstream dependencies, or the client-side fetching of discovery metadata that MCP clients perform, which is the client implementer's responsibility. If your server only calls fixed first-party endpoints and never accepts a URL from the model, you likely have nothing to do here beyond confirming that, and a reviewer will accept a one-line statement saying so.