SSRF Protection
How the http.request adapter and the network layer prevent agents from reaching internal services, cloud metadata endpoints, and unintended hosts.
Server-side request forgery (SSRF) is the risk that an agent, possibly steered by injected content, makes the gateway send requests to places it should not: cloud metadata services, internal admin panels, databases, or other tenants. AgentShield addresses SSRF at three independent layers.
Layer 1: Host allow-list
http.request reaches only hosts listed in the gateway's tools file. The check happens in Validate, before anything is claimed:
- Hosts are lowercase hostnames with an optional port. IP addresses are refused in the configuration, so an allow-list entry cannot point at an address range.
- The request's resource must use one of those exact hosts.
- HTTPS is required unless
allow_insecure_httpis set, which production refuses.
Layer 2: Address checks after DNS resolution
A hostname on the allow-list could still resolve to an internal address, either by misconfiguration or by DNS rebinding. The adapter's dialer therefore checks the resolved IP address immediately before connecting, in the socket's control hook. A hostname that resolves to a blocked address is refused even if DNS changes between lookups.
Blocked addresses include:
| Category | Ranges |
|---|---|
| Loopback | 127.0.0.0/8, ::1 |
| Private | 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, fc00::/7 |
| Link-local (including cloud metadata) | 169.254.0.0/16, fe80::/10 |
| Carrier-grade NAT | 100.64.0.0/10 |
| Unspecified and "this network" | 0.0.0.0/8, :: |
| Multicast | All multicast scopes |
| Documentation and benchmarking | 192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24, 198.18.0.0/15, 2001:db8::/32 |
| Reserved | 192.0.0.0/24, 240.0.0.0/4 |
| Transition mechanisms | NAT64 64:ff9b::/96, 64:ff9b:1::/48, 6to4 2002::/16 |
| Anything not global unicast | Rejected by the standard library check |
IPv4-mapped IPv6 addresses are unmapped before checking. A blocked connection is reported as 400 validation_failed: "resource host resolves to a blocked network address".
allow_private_networks disables these checks for local development. Production refuses it.
Layer 3: Request shaping
| Control | Prevents |
|---|---|
| Redirects are not followed. A 3xx is returned as the result | Bouncing through an allowed host to an internal one |
| Proxy environment variables are ignored | Routing through an unexpected intermediary |
| Canonical resource URLs only | Encoding tricks that bypass exact policy rules |
| No userinfo in URLs | https://allowed@internal/ confusion |
Agent cannot set Host | Virtual-host routing to a different backend |
Agent headers limited to Accept, Accept-Language, If-Match, If-None-Match | Header injection and credential smuggling |
| Response cap (256 KiB default, 4 MiB maximum) | Memory exhaustion |
Set-Cookie dropped, response headers filtered | Leaking session material back to the agent |
Layer 4: Network policy
On Kubernetes, the gateway's egress NetworkPolicy allows outbound HTTPS only to public ranges, excluding private, loopback, carrier-grade NAT, and link-local networks. This repeats the adapter's checks at a layer the gateway process cannot change. It requires a network plugin that enforces NetworkPolicy.
Policy as a final control
Even with network protections in place, use policy to restrict what agents may reach:
{
"permissions": { "allowed": ["http.get"], "denied": ["http.delete"], "approval_required": ["http.post"] },
"resource_rules": [
{ "effect": "allow", "action": "http.get", "resource": "https://api.github.com/repos/octo/hello" }
]
}Allow-listed hosts are trusted
SSRF protection keeps requests on the hosts you list. It cannot make a listed host safe. If an allowed host itself proxies arbitrary URLs, an agent can use it as a proxy. List only hosts whose behavior you understand.
Implementation references
Was this page helpful?
Replay Protection
How nonces, timestamps, idempotency keys, and execution claims together prevent a captured or repeated request from acting twice.
Secret Detection
How AgentShield keeps secrets out of storage with redaction and flags secrets leaving in tool arguments with deterministic detection rules.