
SSRF cloud metadata theft is a credential bug. The vulnerable fetcher sends requests from inside your network with your workload's identity, so one attacker-controlled URL pointed at 169.254.169.254 can return the role keys that open the cloud account.
The short answer
- SSRF cloud metadata attacks work because the fetcher runs inside your trust boundary. Steering it to a metadata or credential endpoint returns live role tokens.
- IMDSv2 raises the cost. It does not fix SSRF: any primitive that controls method and headers can complete the token flow.
- Blocklists fail against IP encodings, parser differentials, redirects and DNS rebinding. Resolve, pin, and route through an egress proxy.
- AI agents with URL tools are SSRF primitives where the model, or a prompt injection, picks the target. Give them a metadata-less sandbox with no production credentials.
Key takeaways
- SSRF severity depends on the identity behind the fetcher: instance, task, pod or managed-identity credentials.
- IMDSv2 defeats GET-only SSRF. Header-capable primitives, and a hop limit raised to 2, put metadata back in reach.
- String blocklists fail against encodings, parser differentials, redirects and DNS rebinding. Resolve, pin and proxy instead.
- Agent URL tools are SSRF primitives that prompt injection can steer. Isolate them from metadata and production credentials.
- Cloud SSRF against a privileged role is a critical finding. CVSS environmental metrics should reflect the data and infrastructure that role can touch.
Why does SSRF cloud metadata access beat a web-bug score?
SSRF is a cloud-compromise bug because the vulnerable code executes a network request inside your trust boundary. That request uses your workload’s network position and, indirectly, its credentials. The useful severity question is not what the response body contained but which IAM role, metadata token or internal control plane sits within reach of the fetcher.
CWE-918, CAPEC-664 and OWASP API Security Top 10 2023 category API7:2023 name the bug. They do not score blast radius, because blast radius depends on where the fetcher runs. The same avatar proxy is close to harmless on a locked-down host. On an EC2 instance with an over-scoped instance profile, it is account takeover.
Fetchers are easy to overlook:
- Image and avatar proxies, link unfurlers, OpenGraph and oEmbed previews
- PDF and screenshot rendering (wkhtmltopdf, Puppeteer, Playwright, headless Chrome)
- Webhook delivery, RSS import, and import-from-URL flows
- SVG with an external href, XSLT
document(), and XML parsers that resolve external entities - Agent tools that fetch, browse, download or ingest URLs
How does SSRF against AWS metadata steal instance role credentials?
SSRF steals AWS credentials by asking the Instance Metadata Service for the role on the instance. The service answers on 169.254.169.254. AWS also documents an IPv6 address, fd00:ec2::254, in unique-local space. Confirm that address is enabled on the instance types you run before you treat every host as dual-stack. IMDSv1 accepts a plain GET with no authentication.
The chain is two reads. The first fetches /latest/meta-data/iam/security-credentials/ and returns the role name. The second appends that name and returns an AccessKeyId, a SecretAccessKey and a session Token. Those temporary credentials call the AWS API like any other keys. MITRE tracks the technique as ATT&CK T1552.005, Cloud Instance Metadata API.
Capital One in 2019 is the reference case. A misconfigured ModSecurity WAF on EC2 relayed requests to IMDSv1. The instance role could list and sync S3 buckets holding roughly 100 million credit applications, reported as about 106 million affected people.
In that breach the WAF was the SSRF primitive. Remember that when a vendor offers a WAF rule as the fix. Alerts that fire only when keys are replayed from outside the provider also miss an attacker who stays inside the same cloud.

What does IMDSv2 actually stop, and where does the hop limit fail?
IMDSv2 stops SSRF primitives that can only issue a simple GET. It does not stop primitives that control the HTTP method and headers. A client must PUT to /latest/api/token with X-aws-ec2-metadata-token-ttl-seconds set between 1 and 21600, then send the returned token as X-aws-ec2-metadata-token on each GET.
A header-controlling primitive completes that flow. CRLF injection in the URL, a proxy that forwards arbitrary methods, a headless browser running attacker JavaScript, or a gopher-capable client all qualify. AWS describes IMDSv2 as defense in depth, not a complete mitigation.
The PUT response hop limit defaults to 1. A token request from a container behind a bridge or NAT dies before it reaches the caller, which is why the limit is easy to underrate. Platform teams often raise it to 2 so ECS or EKS works, and that reopens the container path.
AWS later moved new instance launches toward IMDSv2-required. Confirm the setting on your account rather than assuming a rollout date. A launch default does not retrofit instances already running. An organization policy that sets HttpTokens to required can enforce the check going forward. The strongest host control is HttpEndpoint: disabled on workloads that do not need IMDS.
| Mode | Blocks | Does not block | Operational cost |
|---|---|---|---|
| IMDSv1 enabled | No class of SSRF | Any GET-capable SSRF | None |
| IMDSv2 required, hop limit 1 | GET-only SSRF, and container-originated token requests | Host-level primitives that control method and headers | Old SDKs and agents may break |
| IMDSv2 required, hop limit 2 | GET-only SSRF | Header-capable SSRF from containers too | Low |
| IMDS disabled | Metadata credential theft on that host | Task, pod, file and environment credentials | Credentials must come from elsewhere |
Which blocklist bypasses still reach metadata, and how do clouds differ?
Almost every bypass works against string matching on the URL, which is what most blocklists do. A validator that checks text never learns where the connection actually lands.
- IP encodings: decimal
2852039166, hex0xA9FEA9FE, octal0251.0376.0251.0376, short forms like169.254.43518(= 169.254.169.254) and127.1, IPv4-mapped IPv6::ffff:169.254.169.254, plus bracketed and zone-ID forms. - Parser differentials: userinfo (
http://allowed.com@169.254.169.254/), a backslash before the at-sign, trailing dots, fragments and semicolons. Python urllib.parse, Java java.net.URL, Node’s legacy url.parse and the WHATWG URL standard disagree, so the validator and the fetcher can land on different hosts. - DNS names: any hostname that resolves to link-local or RFC1918 space.
- Redirects: a 302 from an allowlisted host to the metadata service. Most clients follow redirects by default, and most validators check only the first URL.
- DNS rebinding: a near-zero TTL resolves to a public IP at validation time and to 169.254.169.254 at fetch time. Rebinding services such as rbndr.us make this straightforward to test.
- Protocol smuggling: gopher, dict, file, ldap and tftp, depending on the client. curl supports gopher, dict and file. Python urllib supports file and ftp. Java URLConnection supports jar and file. requests, axios and fetch stay on http and https unless you extend them.
Teams also forget address ranges. Blocking RFC1918 while leaving loopback, 169.254.0.0/16, IPv6 ULA, Azure’s WireServer (168.63.129.16) and Alibaba’s metadata IP (100.100.100.200) open is the usual partial fix.
Each provider gates metadata with a header or a token. A header check only stops SSRF that cannot set headers.
| Provider | Endpoint | Required gate | Stops header-capable SSRF? |
|---|---|---|---|
| AWS EC2 | 169.254.169.254, fd00:ec2::254 | None on v1, or a PUT token on v2 | No |
| GCP | metadata.google.internal / 169.254.169.254, /computeMetadata/v1/ |
Metadata-Flavor: Google. Requests that carry X-Forwarded-For are rejected. |
No |
| Azure | 169.254.169.254, /metadata/instance?api-version= |
Metadata: true |
No |
| Oracle Cloud | 169.254.169.254 (v2 paths) | Authorization: Bearer Oracle |
No |
| Alibaba Cloud | 100.100.100.200 | X-aliyun-ecs-metadata-token (hardened mode, opt-in per instance) |
No |
| DigitalOcean | 169.254.169.254 | None | No: there is no gate to bypass |
GCP’s X-Forwarded-For rejection defeats some proxy-based SSRF and does nothing against a direct fetch. Do not treat GCP Metadata Concealment as a live control: GCP deprecated it in favor of Workload Identity for GKE. Alibaba’s token header applies only when hardened mode is on for that instance, so confirm the setting before you count it. Block Azure WireServer (168.63.129.16) at egress from application subnets wherever the platform allows it.
Can SSRF read task credentials, pod identity, and internal control planes?
On ECS, task role credentials are often broader than the instance profile. ECS serves them at 169.254.170.2 on the path in AWS_CONTAINER_CREDENTIALS_RELATIVE_URI, or at the URL in AWS_CONTAINER_CREDENTIALS_FULL_URI. The relative path is unguessable. A file read of /proc/self/environ hands it over.
- EKS Pod Identity runs an agent on a link-local address and requires a token from a projected file. A file read plus a header-capable fetch reaches it.
- IRSA and GKE Workload Identity put a projected service account token on disk. A file read steals that token. Blast radius is the pod’s role, not the node’s.
- Kubernetes service account tokens sit at
/var/run/secrets/kubernetes.io/serviceaccount/token. - Azure App Service and Functions expose managed identity through
IDENTITY_ENDPOINT, gated byIDENTITY_HEADER. Loopback SSRF that can set a header mints tokens even when 169.254.169.254 is blocked.
Workload identity federation limits how far a stolen token reaches. It does not remove SSRF as a way to steal that token.
After credentials, pivot to control planes that trust the network. The kubelet API listens on 10250, with a legacy read-only port on 10255. Also watch etcd on 2379, the Kubernetes API, Docker on 2375 or a proxied docker.sock, Consul on 8500, and Envoy admin on 15000 or 9901. Elasticsearch, Prometheus, Grafana, Jenkins and Kibana sit in the same class.
These services often trust any caller on the internal network. A GET to Consul or Elasticsearch leaks configuration and data. A client that can speak gopher to unauthenticated Redis can change host state. Even a GET-only bug reaches Envoy admin and Prometheus, which expose topology, internal names and sometimes secrets stored as labels.
How does SSRF show up in LLM agents, MCP servers, and RAG loaders?
Any agent tool that accepts a URL is an SSRF primitive. The model chooses the destination, and a prompt injection can choose it for the model. That includes fetch and browse tools, screenshot and download tools, search tools that open results, RAG URL loaders, and MCP servers that wrap a generic HTTP client or a browser.
There is no form field to validate. The URL arrives in a prompt, a retrieved document or a tool description. MCP does not enforce per-tool authorization or an egress policy, so both have to be built around the server.
Agents run as a Lambda execution role, a Cloud Run service account, a Functions managed identity or an ECS task role. Those roles are usually scoped for the whole application, so the SSRF blast radius equals the agent’s IAM permissions. We map that gap in the piece on the AI agent attack surface a web pentest misses.
An attacker-controlled page can tell a browsing agent to fetch http://169.254.169.254/latest/meta-data/iam/security-credentials/ and place the body in its summary, a markdown image URL or the next tool call. No memory-corruption bug is required. Indirect prompt injection, OWASP LLM01, supplies the instruction. Excessive agency, LLM06, supplies the network.
Simon Willison’s lethal trifecta is the triage test: private data, untrusted content and outbound requests. Remove any one and the exfiltration chain breaks. In prompt injection testing we plant instructions in pages, documents and tool outputs, then record which internal hosts the agent contacts.
How should you detect blind SSRF and score the cloud finding?
You detect blind SSRF through side effects, not through a response body. Point the fetcher at an out-of-band listener such as Burp Collaborator or interactsh. A DNS lookup or an HTTP hit confirms the primitive. Timing differences map open and closed internal ports. Error text and response length show which hosts exist.
Blind SSRF still supports internal port scanning, state changes on GET-driven internal APIs, and DNS exfiltration when a redirect is in the chain. Authoritative DNS logs that show a public answer and then a link-local answer for the same name are a rebinding signal. SSRFmap, Gopherus and Nuclei templates widen coverage. Parser-differential cases still need a person to confirm.
Score cloud SSRF as critical when the fetcher can reach a credential source tied to a privileged role. Triagers often call the same bug medium because they treat the impact as internal reconnaissance. If that role can read customer data or change infrastructure, confidentiality and integrity impact are high. CVSS environmental metrics exist for that adjustment.
A useful ticket names the reachable credential endpoints, the role ARN or service account, that identity’s effective permissions, and the bypasses that worked. State the fix as a network or identity control, not a regex. SSRF is not CSRF, where the victim’s browser sends the request, and it is not an open redirect, where no server-side fetch occurs.
A defensible design assumes the fetcher will be steered and makes the destination useless:
- Disable IMDS (
HttpEndpoint: disabled) where the workload does not need it. Elsewhere, require IMDSv2 with hop limit 1. - Deny 169.254.0.0/16, fd00:ec2::254, loopback, Azure WireServer (168.63.129.16) and Alibaba metadata (100.100.100.200) at the network layer, not only in application code.
- Force outbound fetches through an egress proxy with a domain allowlist.
- Resolve the hostname, reject private and link-local answers, then connect to that pinned IP. Do not resolve a second time.
- Disable redirects, or re-validate every hop.
- Allow only http and https. Check the headless browser and any curl wrapper.
- Replace broad instance roles with narrow workload identity: IRSA, GKE Workload Identity, or Azure Workload Identity.
Agents need two more controls. Run URL tools in a sandbox with no metadata service, no production credentials and its own allowlist. Require approval for hosts outside that list, and scan tool output for credential-shaped strings before it re-enters the model context.


FAQ
What is 169.254.169.254 and why do attackers target it?
169.254.169.254 is the link-local address where AWS, GCP, Azure, Oracle Cloud and DigitalOcean serve instance metadata. On AWS IMDSv1, a GET there returns temporary credentials for the instance role, so SSRF to that address is often cloud account access.
Does IMDSv2 prevent SSRF?
No. It blocks SSRF that can only send a simple GET. Primitives that control the method and headers, including CRLF injection, method-forwarding proxies, headless browsers and gopher clients, can still complete the token flow. A hop limit of 1 also blocks many container-originated token requests until someone raises it.
Is blind SSRF exploitable in the cloud?
Often, yes. Blind SSRF supports internal port scanning, state-changing requests to internal APIs and DNS-based exfiltration. Confirm the primitive with an out-of-band listener such as Burp Collaborator or interactsh, then map which credential and admin ports answered.
How do I stop DNS rebinding in an SSRF filter?
Resolve the hostname once, reject private, loopback and link-local results, and connect to that exact IP. Validating a name and letting the HTTP client resolve it again at fetch time is what rebinding exploits. Re-check every redirect hop the same way.
Can an AI agent be used for SSRF?
Yes. Any agent tool that fetches URLs lets the model choose the destination, and indirect prompt injection in retrieved content can point it at metadata endpoints and carry the response out. Run fetch tools in a sandbox with no metadata service and no production credentials.
Which OWASP category covers SSRF?
SSRF is API7:2023 in the OWASP API Security Top 10 and CWE-918. For agents, the matching LLM Top 10 entries are LLM01 Prompt Injection and LLM06 Excessive Agency: untrusted content chooses the URL, and the tool is allowed to send it.
If your applications or agents fetch URLs from cloud workloads, we can show you which credentials those fetchers reach. See our AI agent penetration testing for agent fetch tools and MCP servers.