Tissue Mast fetches URLs our customers type in, from servers we run. We pulled the code that keeps those fetches off our own network into a Rust crate called ssrf-guard, and it's open source under MIT or Apache 2.0.
An uptime check is a customer telling one of our servers to open a connection somewhere. You save https://shop.example.com/health, and as often as every 30 seconds we fetch it from a few places and compare notes. If that fetch could reach 127.0.0.1:8080, or a private address on the same network, or the cloud metadata service on 169.254.169.254, then anyone with a free account could poke at things that were never meant to face the internet and read the answers off their dashboard. That's server-side request forgery, SSRF.
It's an old bug and it still pays out. The Capital One breach in 2019 was an SSRF through a misconfigured firewall to the metadata service, which handed over the instance's role credentials, which opened the S3 buckets. About a hundred million people. This year LMDeploy, an LLM inference server, shipped a bug of the same shape: a crafted image URL made it fetch whatever address it named. Someone was using it against the metadata service within a day of the advisory.
The fix sounds like one line: don't fetch private addresses. Getting that line to hold took most of a crate.
use ssrf_guard::{Fetcher, Policy};
let fetcher = Fetcher::new(Policy::default());
let resp = fetcher.get("https://example.com/").await?;
println!("{} from {:?}", resp.status(), resp.remote_addr());
// Refused before any connection is made.
let err = fetcher.get("http://169.254.169.254/latest/meta-data/").await;
assert!(matches!(err, Err(ssrf_guard::Error::Denied { .. })));
The first thing anyone writes is a check on the form. Parse the URL, resolve the host, refuse it if the address is private, save it otherwise. That stops someone typing http://192.168.7.9/ and nothing else. A name that resolves to a public address when it's saved can resolve to 10.1.2.3 an hour later, because whoever owns the DNS for it can change the record whenever they like. The check has to happen on every fetch, and it has to look at the address the socket connects to, not the text of the URL.
So the second version resolves the name right before the fetch, checks what came back, and hands the URL to the HTTP client. We tried that against reqwest with a resolver that counts its lookups. One check and one fetch made two lookups. The client resolves the name again on its own, and nothing ties its answer to the one you checked. A DNS server with a zero TTL can answer with a public address the first time and a private one the second. That's DNS rebinding, and it's not a beginner's mistake. Memos shipped exactly this as CVE-2026-71272 this year: the webhook sender checked the resolved addresses and then dialled the hostname. PraisonAI fixed the same bug in its webhooks, and the fix was bypassed with a rebinding server. The client's API pushes you into it. Every client wants a URL and does its own lookup.
ssrf-guard resolves the name once per hop, checks every address it got back, and builds the client with those addresses pinned to the name. The client has no resolver of its own. If it asks for a name that wasn't pinned, the lookup fails instead of quietly going to the system resolver. The rebinding test in the repo hands out 127.0.0.1 first and 10.1.2.3 after that. The first request lands on the checked address, and when the server redirects back to the same name, the second lookup gets 10.1.2.3 and the fetch stops there.
If a name comes back with one private address among public ones, the whole name is refused. Dropping the bad one and connecting to the rest would also be safe. But a public name that answers with 10.1.2.3 is either broken or someone testing us, and we'd rather the check fail and say why.
A careful check before the first request doesn't help if the client follows redirects on its own. We pointed a stock reqwest client at a local server that answers 302 Location: http://127.0.0.1:<port>/admin. It followed, got a 200 and handed us the body. An attacker doesn't need their URL to resolve anywhere interesting. A public server they control and a Location header are enough. GitLab had this reported against its GitHub integration in 2018, with the metadata service as the destination.
So redirects are followed by hand, three at most by default, and each one goes through the whole check again: resolve, refuse if any address is denied, pin, connect. A redirect to anything but http or https can't be followed, and a switch between the two counts as another origin. A redirect with a user name and password in it is refused too, since the client would turn those into an Authorization header for whatever host the redirect names.
Mast checks can carry headers and a body, because a health endpoint often wants an API key. That raised a second question: what travels with a redirect. With a 307 to another port, stock reqwest dropped Authorization but sent our X-Api-Key header and the JSON body on to the new origin. curl does much the same without --location-trusted. This is a hard thing to get right in a general-purpose client. urllib3, which most of Python's HTTP goes through, shipped CVE-2023-43804 in 2023 for keeping the Cookie header across a cross-origin redirect, and another the next year for Proxy-Authorization. For a monitor, an API key in a custom header is the normal case, and no stripping list is going to know its name.
ssrf-guard follows a cross-origin redirect with none of the request headers or body the caller set. Only the User-Agent travels. And once a chain has left the first origin it doesn't get them back, even if a later redirect points home again. The other origin chose where the request went next, so the chain isn't the caller's any more.
reqwest reads HTTP_PROXY and ALL_PROXY from the environment. We set HTTP_PROXY, asked a stock client for http://203.0.113.9/, and the proxy got GET http://203.0.113.9/ HTTP/1.1. A proxy resolves and connects for you, after your check, so nothing above applies to it. ssrf-guard turns proxies off.
The other is time. Once you follow redirects yourself it's natural to give each hop its own request with its own timeout. With a 10 second timeout and three redirects, a slow server can hold one check for 40 seconds. ssrf-guard has one budget for the whole chain, and it includes reading the body. In the test for it each hop takes 300 ms and the budget is 800 ms, so the third hop runs out of time.
Loopback and RFC 1918 are the obvious ones. Link-local is where the metadata services live. 100.64.0.0/10 is carrier-grade NAT, and it's also where some overlay networks put their machines. 0.0.0.0 connects to the local host on Linux. Then multicast, broadcast, the documentation ranges, the benchmarking range and everything from 240.0.0.0 up.
IPv6 doubles it, and it's where the address checkers get caught. ::ffff:10.1.2.3 is 10.1.2.3 as far as the kernel is concerned, and so is 64:ff9b::a01:203 behind a NAT64 gateway. Node's ip package, which a lot of things call to ask "is this public", said yes to ::ffff:127.0.0.1 and to 127.1, and got CVE-2024-29415 for it after an earlier fix hadn't covered them. ssrf-guard judges an IPv6 address with an IPv4 one inside it by the IPv4 address. 6to4, Teredo and the local-use NAT64 block are refused outright, because where those packets come out depends on a relay you don't run. Link-local, unique local and the documentation ranges are refused the same way they are in IPv4.
If your own servers have public addresses you don't want fetched, deny adds blocks on top of the list and always wins. allow goes the other way, for a test server on loopback or a private network you mean to reach.
let policy = Policy::builder()
.deny("198.51.100.0/24".parse()?) // your own servers
.build();
let fetcher = Fetcher::new(policy);
// The same checks for something that isn't HTTP.
let stream = fetcher.connect("db.example.net", 5432).await?;
It only checks the addresses this process connects to. A NAT64 gateway, a VPN or a corporate proxy that routes public addresses somewhere private is invisible to it, and so is whatever a public server does with the request after it arrives. It doesn't restrict ports or match host names, it speaks HTTP/1.1 only, it needs a tokio runtime, and it builds a fresh client for every hop, which suits a prober and costs you on a hot path. A library shouldn't be your only layer either. A firewall rule for the process that fetches catches what a bug in the code lets through. What the library adds is a refused check that says why, instead of one that times out.
If you want to keep your own reqwest::Client, reqwest-ssrf-guard plugs into one through a DNS resolver and a redirect policy, and it can refuse ports and match host names. You wire up more of it yourself: a URL with a literal IP skips the resolver, so it needs that crate's URL check as well, and proxies are yours to turn off. http-acl-reqwest is the same idea with a fuller access list. url_jail does the address check without a client, from Python too. If the fetching happens in several languages, an egress proxy such as Stripe's Smokescreen puts the rule in one place.
Most of the bugs linked above were in Go, Python and Node services, because that's where the webhook senders and link previewers have been. Rust services are starting to do the same jobs. The code is at github.com/tissue-systems/ssrf-guard, and cargo add ssrf-guard gets you version 0.1.