Skip to content

Lesson 11 of 14 · 22m

SSRF: The 'Fetch This URL' Feature That Proxies Your VPC

Webhook URLs, image fetchers, and 169.254.169.254 — allowlisting that survives redirects, DNS rebinding, and weird IP spellings.

Your API has a "register webhook URL" feature. Or an avatar-by-URL importer, an oEmbed unfurler, a PDF renderer that fetches HTML, an RSS importer. Every one of them is the same feature with different branding: your server makes an HTTP request to an address the user chose. That's a proxy into your internal network with an API key to operate it, and the attacker's first request is always the same URL.

What they fetch

http://169.254.169.254/latest/meta-data/iam/security-credentials/ — the cloud instance metadata endpoint, link-local, reachable from any EC2 instance without credentials. In 2019 that's exactly what the Capital One breach ran: SSRF in a WAF-adjacent service → metadata → IAM credentials → S3 → ~100 million records. AWS's answer shipped months later: IMDSv2, which requires a PUT with X-aws-ec2-metadata-token first — a header a generic fetcher doesn't know to send. GCP answers at metadata.google.internal (which resolves to the same 169.254.169.254), Azure at 169.254.169.254/metadata/instance requiring a Metadata: true header. Enforce IMDSv2 — and don't count on it as your defense; it's the last line, not the first.

Then the internal estate: your Redis at 10.0.1.4:6379, your unauthenticated internal admin port, your Kubernetes API on the pod network. Anything your server can reach, the attacker can reach through it — and from the inside, requests arrive with your server's network identity, source IPs, and network-policy allowances.

The allowlist is harder than it looks

The naive fix is if "169.254.169.254" not in url: fetch(url). It fails in every direction:

  • Spellings: 169.254.169.254 is also 2852039166 (decimal), 0xa9fea9fe (hex), 0177.0.0.1-style octal for 127.0.0.1, [::ffff:a9fe:a9fe] (IPv6-mapped), 169.254.169.254.nip.io (DNS wildcard). A string-match list grows forever; parse the URL to an IP and range-check it.
  • Redirects: your allowlist checks example.com, example.com 302s to 169.254.169.254. Re-validate every hop or disable redirects — most fetch libraries follow them silently.
  • DNS rebinding / TOCTOU: the hostname resolves to 1.2.3.4 when you check and 169.254.169.254 when your fetcher connects. Fix it by resolving once and connecting to the validated IP — pass the original hostname through Host/SNI and TLS validation, or use a fetcher that supports resolving-and-pinning.
  • Parser differentials (the earlier lesson's theme): http://allowed.com@169.254.169.254/ — the host is 169.254.169.254 and the "allowed.com" is userinfo. Whatever URL parser validates must be the one that resolves.

The controls that actually hold

Layered, in order of what they stop:

  1. Scheme allowlist — https only if you can, http at minimum; nothing else (file://, gopher://, ftp:// all exist in URL parsers).
  2. Resolve-and-pin — resolve once, range-check every returned IP against RFC 1918, loopback, link-local, ULA, and your own internal ranges; connect to that IP directly.
  3. Redirect re-validation — every hop re-checked, or redirect: 'manual' and you handle it.
  4. Egress filtering — default-deny outbound from whatever runs the fetcher; the metadata endpoint dies at the network policy even when code forgets it.
  5. Isolation — run fetchers in a worker with no metadata access and no internal routes; a compromised fetcher gets nothing.

169.254.169.254 is the famous one; the list you actually block is longer — your VPC CIDR, your cluster ranges, your cloud's other magic IPs, anything you haven't published on purpose.

Try this

Threat-model your "register webhook" endpoint: what does the fetcher reach, what can it see, what happens on redirect? Then write the five exploit URLs: the decimal-encoded IP, the redirect hop, the DNS-rebind domain, the userinfo-confusion URL, the IPv6-mapped address. If any one lands, the feature is a proxy.

Pitfalls

  • String-matching the IP — spellings are infinite; parse and range-check.
  • Validating once, fetching twice — TOCTOU/DNS rebinding beats every check-then-fetch.
  • Trusting redirects — validate every hop or none.
  • Blocking only the metadata IP — internal networks are the actual target; egress policy catches what code misses.
  • nip.io/sslip.io hostnames — DNS wildcards resolve to whatever IP is in the hostname.

Was this lesson helpful?

Sign in to rate

Keep reading

Related articles from the SudoSecurity blog.