Course contentsShow
← Security
Lesson 1934 of 3,05239. Cloud Security - Compute and ServerlessFree lesson

IMDSv1 vs IMDSv2 Security Improvements

Compare legacy IMDSv1 with IMDSv2's session-based approach, PUT request requirement, and hop limit protections.

IMDSv1 vs IMDSv2 Security Improvements

What you'll learn: How AWS improved IMDS security by replacing the wide-open IMDSv1 with session-based IMDSv2.

The Problem with IMDSv1

IMDSv1 uses a simple HTTP GET request to retrieve instance metadata—no authentication, no session tokens. Any process (or attacker) inside the instance can just call:

curl http://169.254.169.254/latest/meta-data/

This creates serious vulnerabilities:

  • SSRF attacks can trick your application into fetching metadata through simple GET requests
  • No hop limit enforcement means requests can be forwarded through proxies or misconfigurations
  • No request origin validation—anyone who can make an HTTP request wins

How IMDSv2 Fixes This

IMDSv2 introduces a session-based approach with three key protections:

1. PUT Request Requirement
You must first request a session token using an HTTP PUT:

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

Then use that token in subsequent requests. This breaks SSRF attacks because most SSRF vulnerabilities only support GET requests, not PUT.

2. Mandatory Token Header
Every metadata request must include the session token:

curl -H "X-aws-ec2-metadata-token: $TOKEN" http://169.254.169.254/latest/meta-data/

3. Hop Limit Protection
IMDSv2 enforces an IP packet TTL (time-to-live) of 1, preventing requests from being forwarded through containers, reverse proxies, or NAT gateways. The request must originate directly from the instance.

Analogy

Think of IMDSv1 as shouting your password across a crowded room—anyone can hear it. IMDSv2 is like requiring a two-way handshake with ID verification before whispering secrets, and only to someone standing right next to you.

Key Takeaway: IMDSv2 requires PUT requests for session tokens, enforces token headers, and limits network hops—dramatically reducing SSRF and credential theft risks compared to IMDSv1's open GET access.