Cloud & platform

IMDSv2

Instance Metadata Service version 2

The session-token version of the AWS EC2 metadata service, requiring a PUT-issued token that most SSRF bugs cannot obtain.

With IMDSv2 a client first sends PUT /latest/api/token with a TTL header, then passes the returned token in X-aws-ec2-metadata-token on every metadata request. Typical SSRF only controls a GET URL, so it cannot perform the PUT or set headers. IMDSv2 also rejects token requests carrying X-Forwarded-For, which stops open reverse proxies being used to fetch tokens.

The token response has an IP TTL (hop limit) that defaults to 1, so containers behind an extra network hop cannot reach it unless you raise the limit to 2, which is a deliberate trade-off.

Enforce it by setting HttpTokens=required on instances and launch templates, and with an SCP or Config rule so no one launches IMDSv1 instances. New instance types and some AMIs default to IMDSv2-only, but older fleets still need checking.

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

Learn it properly

Also used in

Related terms