---
name: sh-kb-ssrf
description: "Knowledge base for finding Server-Side Request Forgery - when the server makes outbound requests to attacker-controlled destinations. Use when hunting SSRF or reviewing URL/host inputs that reach HTTP/network clients, renderers, or importers. CWE-918, OWASP A10:2021-SSRF."
---
# Server-Side Request Forgery (SSRF) - Hunter Knowledge Base
The server fetches a URL the attacker controls, letting them reach internal services, cloud metadata, or
the loopback interface from the server's trusted position.
## When to hunt this
Features that fetch remote resources: webhooks, URL preview/unfurl/oEmbed, image/PDF fetchers, import-from-URL,
SSO/OIDC discovery (`jwks_uri`, issuer, SAML metadata URL), PDF/HTML renderers, avatar-by-URL, proxy and
image-optimizer endpoints (e.g. Next `remotePatterns`), RSS/feed import, git/package fetch by URL,
integrations with user-set base URLs, XML/SVG with remote refs, media processing (ffmpeg/ImageMagick
reading `http`/playlist/`url(` references).
## Sources
Any user-supplied URL/host/IP/port: request params/body, redirect targets, `Location` following,
filenames that become URLs, hostnames in config uploaded by users, **stored URLs fetched later by a job or
worker** (second-order), headers used to build URLs (`Host`, `X-Forwarded-Host`, `Referer`), and URLs found
inside fetched content (HTML ``/`` that a renderer then loads).
## Sinks (grep targets)
- **Python**: `requests.get/post(`, `urllib.request.urlopen(`, `httpx.`, `aiohttp`, `urllib3`, `pycurl`.
- **JS/TS**: `fetch(`, `axios(`, `http.get/request(`, `got(`, `node-fetch`, `request(`, `puppeteer`/`playwright` `page.goto(`.
- **Java**: `URL(...).openConnection()`, `HttpClient.send(`, `RestTemplate`, `WebClient`, `OkHttpClient`, `Jsoup.connect(`.
- **Go**: `http.Get/Post(`, `http.NewRequest(`, `http.Client{}.Do(`. **PHP**: `curl_exec`, `file_get_contents($url)`,
`fopen`, `SoapClient`. **Ruby**: `Net::HTTP`, `open-uri` `URI.open(user)`, `Faraday`, `HTTParty`.
**.NET**: `HttpClient`, `WebClient`, `WebRequest.Create`.
- Also: SVG/XML parsers, PDF generators (wkhtmltopdf/headless Chrome - also `file://` and in-page JS fetches),
image libraries fetching remote, `git clone `, `curl`/`wget` shelled out.
## Detection recipe
1. `graft grep "requests\.|urlopen|fetch\(|axios|got\(|http\.Get|http\.NewRequest|HttpClient|RestTemplate|WebClient|curl_exec|file_get_contents|URI\.open|Net::HTTP|page\.goto" --json`.
2. Check whether the destination URL/host derives from user input (whole URL, host, or only a path - see filters).
3. Look for the (usually missing) allowlist / SSRF guard: DNS-resolve + IP range check, scheme check,
blocking of `169.254.169.254`, `127.0.0.1`, `::1`, `metadata.google.internal`, RFC1918, `.internal`.
4. Check redirect handling: Python `requests` and Go `http.Client` follow redirects by default, Node `fetch`
and axios do too, PHP curl only with `CURLOPT_FOLLOWLOCATION`, `httpx` does not by default. A guard on the
first URL alone is bypassed by a 302 to an internal address.
5. Check whether the response is returned to the user (full read), partly reflected (status/size/title), or
blind (only side effect/timing); it sets severity and the PoC style.
## Payloads / PoC
- Cloud metadata: `http://169.254.169.254/latest/meta-data/iam/security-credentials/` (AWS; IMDSv2 needs a
prior `PUT` for a token header, so a GET-only SSRF fails against IMDSv2-enforced hosts),
`http://metadata.google.internal/computeMetadata/v1/` (GCP, header `Metadata-Flavor: Google`),
`http://169.254.169.254/metadata/instance?api-version=2021-02-01` (Azure, header `Metadata: true`).
Others: ECS task credentials at `169.254.170.2`, Kubernetes API `kubernetes.default.svc`, kubelet `:10250`.
- Internal scan: `http://127.0.0.1:/`, `http://localhost/admin`, internal hostnames; unauthenticated
Docker API, Consul, Redis, Elasticsearch, admin consoles.
- Bypasses: `http://0/`, `http://0177.0.0.1`, `http://0x7f.1`, `http://127.1`, `http://2130706433` (decimal IP),
`http://localhost.` (trailing dot), wildcard DNS names that resolve to `127.0.0.1` (`127.0.0.1.nip.io`),
redirect chains (allowed host 302s to internal), DNS rebinding, `http://[::]`, `http://[::1]`,
`http://[::ffff:127.0.0.1]`, `http://[::ffff:7f00:1]` (IPv4-mapped IPv6), AAAA-only records when only A is checked.
- Non-HTTP schemes: `file://`, `gopher://` (craft raw TCP to Redis/SMTP), `dict://`, `ftp://`.
- **DNS rebinding**: a name with a very short TTL answers a public IP to the validator, then an internal IP
to the fetch (check-then-use gap). Real fix is to connect to the already-validated IP.
- **URL-parser confusion** (differential parsing, per Orange Tsai's research): if the validator and the
actual HTTP client parse the URL with different libraries/standards, craft a URL both parse differently -
e.g. `http://expected-host\@evil.com` (backslash before `@`): WHATWG-URL-based parsers normalize `\` to
`/` and treat `evil.com` as the host, while an RFC-3986-only parser may read `expected-host` as the
userinfo host. Also test embedded credentials (`http://expected-host@evil.com`), `http://evil.com#@expected-host`,
and mixed-case/percent-encoded hosts if the validator and the fetch call use different URL parsers.
- PoC: point the fetcher at a collaborator/attacker host and confirm the server connects (out-of-band).
## Variant hunting
- Grep the shared HTTP helper (`fetch_url`, `httpClient`, `download`) and every caller; one guarded entry
point with an unguarded sibling is the usual pattern.
- Sibling features that take a URL: webhook test button, import, avatar, preview, PDF/screenshot export,
OIDC/SAML config, "test connection" in integrations, plugin/theme install, link-checker, RSS/podcast.
- Same logic via other transports: shelled `curl`/`wget`/`git`, headless browser, XML/SVG/Office parsers (`xxe`).
- Second-order: URLs stored by one endpoint and fetched by a cron/queue worker with different (weaker) validation.
- Redirect-following clients elsewhere with the guard on the initial URL only.
## False-positive filters
- Destination is a hardcoded/allowlisted host or a fixed base URL with only a path from the user. Still check
that the user part cannot rewrite the host (`@`, `//`, `\`, `..`) or inject query/scheme changes.
- A real SSRF guard runs: scheme allowlist (`https` only) **and** resolved-IP range check **after** DNS
resolution (all A and AAAA records), with redirects disabled or re-validated per hop, and the request made
to the validated IP (validating the string before resolving is bypassable).
- The validation step and the fetch step use the **same** URL-parsing library/call to extract the host (no
parser-confusion gap) - if they differ (e.g. a regex/manual parse for the allowlist check vs. the
language's URL/HTTP-client parser for the actual request), still flag even with an allowlist present.
- Egress is network-restricted to specific hosts (note as mitigation, still flag if the code guard is absent).
- Weak guards that still count as findings: string blocklists of `127.0.0.1`/`localhost`, host checks with
`startswith`/`endswith`/`in` (`example.com.evil.net`, `evilexample.com`), checks of only A records, checks
only on the initial URL, port-only or scheme-only checks.
- Evidence for a real finding: user input reaches the host portion of the request, the client can reach
internal ranges from where the code runs, and no per-hop post-DNS IP check intervenes. A user-controlled URL
fetched only client-side (browser) is not SSRF.
## CWE / OWASP / severity
CWE-918. OWASP A10:2021. **critical** when it reaches cloud metadata/credentials or internal admin;
**high** for internal network access; medium if only blind/limited.
## Chaining hints
SSRF -> cloud metadata -> IAM credentials -> account/infra takeover; SSRF -> internal unauth admin API ->
RCE; SSRF + gopher -> Redis/DB command exec; pairs with `open-redirect` (to bypass allowlists) and XXE;
SSRF read of internal config -> `secrets`.
## Detection signals (for defenders)
- **Egress proxy / firewall / VPC flow logs** (source workload, destination IP and port, bytes): an
application or web-tier host connecting to link-local `169.254.169.254`, loopback aliases, RFC1918 ranges,
or ports like 2375, 6379, 9200, 10250 that it never uses; a burst of connections to many internal
addresses or ports from one workload (internal scan).
- **DNS logs** (query name, answer, TTL, client): the app resolving a name whose answer is private or
link-local; the same name returning different answers within seconds at a very low TTL (rebinding); lookups
of unfamiliar domains immediately after a request carrying a URL parameter (out-of-band callbacks).
- **Web/WAF logs**: URL-valued parameters containing IP literals, decimal/hex/octal hosts, bracketed IPv6,
`metadata`, `localhost`, or non-http schemes (`gopher://`, `file://`).
- **Cloud audit logs** (CloudTrail, GCP and Azure activity logs): instance-role or workload credentials used
from an IP outside the instance or its VPC, shortly after anomalous app traffic (credential theft via
metadata); IMDS token requests from a web server process (EDR process and network events).
- **Behavior-based ideas**: (1) baseline the destination set per app tier and alert on first-seen internal or
link-local destinations from a request-handling process; (2) alert when credentials issued to a role are
used from a new source network within minutes of a metadata-service access.
- ATT&CK: T1190 Exploit Public-Facing Application; T1552.005 Unsecured Credentials: Cloud Instance Metadata
API; T1046 Network Service Discovery (internal scanning); T1078.004 Valid Accounts: Cloud Accounts.
## Mitigation
Allowlist destinations (scheme + host); resolve DNS then verify every resolved IP (A and AAAA) is public
and not in blocked ranges, connect to that IP, and re-check on each redirect (or disable redirects); drop
non-HTTP schemes; isolate egress; use a dedicated metadata-blocking proxy; enforce IMDSv2 on AWS with a low
hop limit; do not return raw upstream responses to users.