SSRF in Tool Calls
Don't let the model phone home
SSRF lets a crafted URL make the model fetch internal services. URL tools must constrain protocol, hosts, and resolution paths so a model-picked link can't reach your metadata endpoint.
What you will learn
- Recognize SSRF in URL tools
- Enforce protocol/host allowlists
- Guard DNS and redirects
What is this?
SSRF (server-side request forgery) occurs when a model-chosen URL causes your server to fetch internal or metadata endpoints (169.254.169.254, localhost, internal CIDRs). Defenses: scheme allowlists (https only), host allowlists with DNS verification, blocking private/loopback ranges, and disallowing redirects that slip past checks.
Why do you need it?
- Models happily fetch whatever URL they're told to.
- Internal endpoints carry secrets metadata and config.
- Allowlists beat denylists against network creativity.
- Redirects and DNS tricks can bypass naive host checks.
Mental model
A phone that only calls white-listed numbers
SSRF control
You don't give a kid a phone that can dial any internal extension listed in the phone book on the caller's say-so. The device (tool) only permits whitelisted area codes, verifies the number against a registry, and drops reroutes. Open dialing is just deferred breaches.
How it works
- Scheme allowlist: https (or http-only for test).
- Host allowlist: exact domains / suffix rules.
- Resolution check: block loopback, link-local, private ranges.
- Redirect policy: refuse cross-host or cross-scheme redirects.
- Reverse DNS/pinned IP verify the resolved address.
Fetch gate.
In production
- Web tools allow only public product domains.
- Fetch tools block the cloud metadata address.
- Redirects cross-checked before following.
Best practices
- Scheme allowlist before any DNS.
- Check the RESOLVED address, not just the hostname.
- Block private/loopback/link-local address families.
- Vet redirects: scheme and host must re-pass the gate.
Common mistakes
- Host-string checks that DNS-rebindings evade.
- http:// allowed 'because it's just for testing'.
- Following redirects blindly to internal targets.
Common issues
Fetch tool reaches metadata endpointLink-local not blocked
Block 169.254.0.0/16, loopback, private ranges at resolve.
Allowlist too narrow blocks legit sitesStatic single domain
Suffix-style allowlist + review process for new hosts.
Debugging tips
- Internal IP hit → resolve-time check missing; pin the address.
- Rebinding bypass → resolver used a different IP than the check; single-resolve.
- Redirect leaked → forbid cross-host redirects.
Interview checkpoint
Quick quiz
The strongest SSRF control is…
Redirects can bypass host-only SSRF checks.