IMDSv2

AWS’s session-token hardening for the EC2 Instance Metadata Service: a defense-in-depth control that kills GET-only SSRF against 169.254.169.254 but not SSRF primitives that control HTTP method and headers.

How it works

IMDSv2 makes metadata access session-oriented. A client must first PUT /latest/api/token with header X-aws-ec2-metadata-token-ttl-seconds (1–21600), then present the returned token as X-aws-ec2-metadata-token on every subsequent GET:

TOKEN=$(curl -X PUT "http://169.254.169.254/latest/api/token" \
  -H "X-aws-ec2-metadata-token-ttl-seconds: 21600")
curl -H "X-aws-ec2-metadata-token: $TOKEN" \
  http://169.254.169.254/latest/meta-data/iam/security-credentials/

The token is valid for up to 6h and only from the same instance where the session began. A bare GET to the metadata service on an IMDSv2-enforced host returns 401 Unauthorized. AWS explicitly frames this as defense-in-depth, not a complete SSRF fix.

Two further controls:

  • Hop limit — the PUT token response has a default IP TTL (hop limit) of 1, so a token request originating from a container behind the instance’s bridge/NAT is dropped before it returns. Platform teams routinely raise it to 2 so ECS/EKS SDKs work, which reopens the container path.
  • X-Forwarded-For rejection — token requests carrying X-Forwarded-For are refused, to stop misconfigured reverse proxies from fetching tokens.

What SSRF primitives can / can’t satisfy it

SSRF primitiveCompletes IMDSv2 flow?
Plain GET-only (?url=)No — cannot issue the PUT
Controls HTTP method + headersYes
CRLF / header injection in URLYes (smuggle PUT + token headers)
Method-forwarding proxyYes
Headless browser running attacker JS (fetch())Yes
gopher:// capable clientYes (craft raw PUT then GET)
Follows redirects, attacker controls method semanticsYes (303 converts POST→GET; see cases)

So IMDSv2 raises the cost but does not remove the class: any bug giving method + header control is sufficient.

IMDSv2 configuration / enforcement

  • Require it per-instance: HttpTokens=required; enforce fleet-wide with an Org policy / SCP. A launch-template default does not retrofit already-running instances — confirm the live setting rather than assuming a rollout date.
  • Keep hop limit at 1 unless a container genuinely needs IMDS.
  • Strongest control: HttpEndpoint=disabled where the workload never needs metadata (then task/pod/file/env credentials must come from elsewhere).
ModeBlocksDoes not block
IMDSv1 enablednothingany GET-capable SSRF
IMDSv2 required, hop limit 1GET-only SSRF + container-originated token requestshost-level method+header primitives
IMDSv2 required, hop limit 2GET-only SSRFheader-capable SSRF from containers too
IMDS disabledmetadata credential theft on that hosttask/pod/file/env credentials

Bypass research / notable cases

  • Confluence makeRequest (CVE-2019-8451) — Atlassian gadgets’ gadgets.io.makeRequest() accepts httpmethod, postData, headers params. Yassine Aboukir & Thái Vũ used these to issue the PUT (X-aws-ec2-metadata-token-ttl-seconds) and then the authenticated GET, fully defeating IMDSv2 on a target that initially returned 401. The classic proof that header control = game over.
  • HTTP 303 redirect trick — a user-controlled token_uri (BigQuery service-account cred) + a Python HTTP client that follows redirects by default: attacker server answers a POST to IMDS with 303, which implicitly rewrites POST→GET, letting a POST-only primitive retrieve IMDS credentials for the K8s worker node.
  • Open-WebUI SafePlaywrightURLLoader (CVE-2026-87996) — TOCTOU/DNS-rebinding: Python validates the IP, Chromium independently re-resolves at fetch time, rebinding to the metadata address and siphoning AWS/GCP/Azure credentials into the model chat context. Shows that a headless-browser SSRF primitive sets its own headers and thus satisfies IMDSv2.
  • Spring Boot /proxy?url= — a proxy that forwards arbitrary method/headers lets the attacker run the full PUT-then-GET token flow verbatim through the SSRF sink to harvest IAM creds and pivot past a VPC-endpoint-restricted S3 bucket.
  • IPv6 / Craft CMS (bypass of CVE-2025-68437) — denylists keyed on the IPv4 literal miss [fd00:ec2::254]; gethostbyname() only resolves A records, so an AAAA-only host returns the hostname string and passes the blocklist, reaching the IMDS IPv6 endpoint (IMDSv2 token rules still apply if enabled).

Sources