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.254is also2852039166(decimal),0xa9fea9fe(hex),0177.0.0.1-style octal for127.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.com302s to169.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.4when you check and169.254.169.254when your fetcher connects. Fix it by resolving once and connecting to the validated IP — pass the original hostname throughHost/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 is169.254.169.254and 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:
- Scheme allowlist —
httpsonly if you can,httpat minimum; nothing else (file://,gopher://,ftp://all exist in URL parsers). - 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.
- Redirect re-validation — every hop re-checked, or
redirect: 'manual'and you handle it. - Egress filtering — default-deny outbound from whatever runs the fetcher; the metadata endpoint dies at the network policy even when code forgets it.
- 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.iohostnames — DNS wildcards resolve to whatever IP is in the hostname.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
Building a Production REST API With Node.js and Express
Build a REST API in Node.js and Express the way production systems need: input validation, JWT auth, refresh token rotation, status codes, rate limiting, idempotency keys, and centralized error handling.
GraphQL Over HTTP Is Finally a Spec. Your Server Probably Still Says 200.
The GraphQL over HTTP specification shipped its first edition on November 12, ending the decade of '200 Not OK.' Validation errors get 422, partial results get a new 294 status, and a dedicated media type tells clients the body is safe to parse.
Strings Are Lying to You: Unicode Length, Case and Normalization in PHP, Python and JavaScript
One family emoji is 18 bytes, 8 JavaScript code units, 5 Python characters and 1 thing a human sees. I ran the same Unicode tests through PHP 8.6, Python 3.15 and Node 26: each gave a different answer for length, case and truncation, a KELVIN SIGN lowercases into a real username, and PHP 8.6's...
PHP and WordPress Patched a Day Apart. Your Front End Decides Which PHP Bugs Reach You.
PHP 8.5.13, 8.4.28, 8.3.37 and 8.2.36 fix 18 CVEs, seven rated 9.2, and WordPress 7.1.5 fixes 20 more issues. Most of the PHP bugs only fire under specific settings, so I checked the official Docker images for each condition. The images were patched the same day, and the patch quietly turns off...