Skip to content

LearnWeb and API

SSRF and cloud metadata exposure review

Brief

An application that fetches a URL on a user's behalf runs that request from inside the cloud, where the metadata service hands out the host's credentials to anything that asks the right way. This review verifies the controls between the two (IMDSv2, header rules, egress filtering and the fetcher's own validation) from configuration and from one request to a URL we control, and never sends a request toward the metadata service.

Stage
Escalation
Reviewed
On this page
  1. Check first
  2. Where do the application's fetches come from, and do they follow redirects?
  3. Do AWS hosts require IMDSv2, and what is the hop limit?
  4. What do Azure and Google Cloud require, and which identity sits behind it?
  5. Does egress control stop the fetcher reaching link-local addresses?
  6. The defender sees
  7. Done when
  8. Not covered
  9. Tools
  10. Related research
  11. Where this page fits
  12. Reviewed

All commands

Cloud volume Chapter 18 of Cloud Penetration Testing, "The metadata endpoint from the application side", goes further than this page. The book is in production.

Situation
An application named in the scope letter with a feature that fetches a URL (webhooks, link previews, import from URL, PDF or image rendering), a test account that can use it, read-only access to the cloud accounts it runs in, and a logging endpoint we own that records requests and returns nothing useful. The only URLs we submit to the application point at that endpoint. Configuration is read through the review role; nothing in the accounts is changed.
Goal
A record per URL-fetching feature: where its requests leave from, whether it follows redirects, the metadata settings on the hosts behind it, the identity those hosts hold, and the egress and validation rules between them.
Outputs
The redirect log was captured on 4 Nov 2026 (UTC) against the Atarus Bench Web and API lab fixture, edition web-api-0.2, running on loopback, with one origin playing every host, renamed to the example domains and printed as https (the lab ran plain http), and the logging endpoint's source address renamed to a documentation address. The AWS step was captured on 8 Nov 2026 (UTC) in the Atarus lab AWS Organization from the Atarus Bench edition 2026.11-cloud-0.3, AWS CLI 2.39.3, in a member account through the lab's read-only review role atarus-review, with instance ids replaced by stable placeholders. The Azure, Google Cloud and kubectl outputs stay representative on placeholder accounts: they wait on the lab Azure subscription, the lab GCP project and the lab kind cluster.

Check first

  • Every feature that takes a URL from a user, including ones that take it indirectly: a webhook target, an avatar URL, a document with linked images, an SVG.
  • Which hosts run the fetcher: EC2 instances, containers on EKS or ECS, Azure VMs or App Service, Compute Engine or GKE.
  • What identity those hosts hold: an instance profile, a managed identity, a service account, and what it is allowed to do.
  • Whether the fetcher goes out directly or through an egress proxy, and that proxy's rules.
  • A logging endpoint we own, named in the scope letter, that records the request line, headers and source address.

Steps

Where do the application's fetches come from, and do they follow redirects?

Submitted as tester-a's webhook URL:  https://hooks.atarus-test.example/m/7f3a2c
Our endpoint answers that path with:  302 to https://hooks.atarus-test.example/m/7f3a2c-hop

Expected output

2026-10-28T15:00:00Z 198.51.100.24 GET /m/7f3a2c UA="app-fetcher/2.3"
2026-10-28T15:00:00Z 198.51.100.24 GET /m/7f3a2c-hop UA="app-fetcher/2.3"   # <- the fetcher follows a redirect without checking where it goes

One marker URL per feature, owned by us end to end. The log tells us the source address (a NAT gateway, a proxy, or the host itself), the client library, and whether a redirect is followed. The redirect stays on our own host; a fetcher that follows one to our second path would follow one anywhere, which is what turns a validated URL into an unvalidated one.

Negative result. Requests arrive from a dedicated egress proxy, and the redirect is either refused or checked against the same rules as the first URL.

Fix. Resolve the name, reject private, loopback and link-local addresses (including 169.254.169.254 and fd00:ec2::254) after resolution, pin the connection to the address that was checked, and either refuse redirects or validate every hop.

Do AWS hosts require IMDSv2, and what is the hop limit?

aws ec2 describe-instances --filters Name=tag:app,Values=webhooks \
  --query 'Reservations[].Instances[].[InstanceId,MetadataOptions.HttpTokens,MetadataOptions.HttpPutResponseHopLimit,MetadataOptions.HttpEndpoint]' --output text
aws ec2 get-instance-metadata-defaults --query 'AccountLevel' --output json

Expected output

i-0abc1234def567890	optional	2	enabled   # <- optional: the metadata service answers a plain GET on this host
i-0aaaa000000000001	required	1	enabled
{
    "ManagedBy": "account"   # <- no account default set: each launch request decides
}

With HttpTokens set to optional, the metadata service answers a plain GET, which is the shape most URL fetchers can send. IMDSv2 needs a PUT to get a session token first, and AWS rejects that PUT if it carries an X-Forwarded-For header. The hop limit is the IP time to live of the token response: 1 keeps it on the host, and a higher value lets containers on the host receive it. The account defaults show whether new instances will be any better. With none set, the call prints only ManagedBy, and account there means the setting is the account's own rather than an organization's declarative policy; each new instance then gets whatever its launch request or image asks for.

Negative result. Every instance required, a hop limit of 1 where containers do not need metadata, and account defaults that require and enforce IMDSv2.

Fix. Watch the MetadataNoToken CloudWatch metric until it reads zero for each instance, then set --http-tokens required, set the account default with HttpTokensEnforced enabled, and keep the hop limit at 1 unless a container on the host needs metadata. Disable the endpoint on hosts that never use it.

What do Azure and Google Cloud require, and which identity sits behind it?

az vm list --query "[?tags.app=='webhooks'].{name:name, identity:identity.type}" -o tsv
gcloud compute instances list --filter='labels.app=webhooks' \
  --format='csv[no-heading](name,serviceAccounts[0].email,serviceAccounts[0].scopes[0])'

Expected output

web-fetch-01	SystemAssigned
web-fetch-gce-1,123456789012-compute@developer.gserviceaccount.com,https://www.googleapis.com/auth/cloud-platform   # <- the default account with every scope

Azure's metadata service requires a Metadata: true header and refuses requests that carry X-Forwarded-For; Google's requires Metadata-Flavor: Google and also refuses X-Forwarded-For. A fetcher that only takes a URL cannot add those headers, but one that lets the user set headers, as many webhook features do, can. Either way, the identity behind the host decides what a leak would cost: the default Compute Engine account with the cloud-platform scope is the result we report first.

Negative result. No identity on hosts that do not need one, and a dedicated service account or managed identity with only the roles the fetcher uses.

Fix. Never let users set arbitrary request headers on outbound fetches, give fetcher hosts a dedicated identity with minimal roles, and on GKE use Workload Identity Federation so pods do not see the node's account.

kubectl get networkpolicy -n webhooks -o json \
  | jq -r '.items[] | .metadata.name as $n | .spec.egress[]?.to[]?.ipBlock | select(.) | "\($n) \(.cidr) except=\(.except // [] | join(","))"'

Expected output

allow-egress 0.0.0.0/0 except=10.0.0.0/8   # <- link-local 169.254.0.0/16 is not excluded

A review of policy, not a request. Where the fetcher runs on virtual machines, we read the egress proxy's rules or the host firewall configuration instead and look for the same exclusion.

Negative result. Egress limited to the proxy, or an except list that covers 169.254.0.0/16 and the private ranges.

Fix. Send all fetches through an egress proxy that denies private and link-local destinations, and add a network policy that excludes 169.254.0.0/16 from the fetcher's egress.

The defender sees

Our logging endpoint sees one request per feature and the client's side sees outbound requests to an unfamiliar host, which is worth an egress alert on its own. The configuration reads appear in CloudTrail, the Azure activity log and Cloud Audit Logs under the review role. In live use, MetadataNoToken above zero shows IMDSv1 still in use, and GuardDuty raises InstanceCredentialExfiltration.OutsideAWS when instance credentials are used from outside AWS. The AWS escalation page covers what such a role can reach.

Done when

Every fetching feature has sent one request to our logging endpoint and its source recorded, IMDS settings are read for every instance and launch template behind it, Azure and Google Cloud hosts are listed with their identities, and the fetcher's destination rules and network egress policy are reviewed.

Not covered

Sending any request toward a metadata or internal address, other internal services a fetcher might reach, and what a host's role can do (see cloud impact without damage).