Advanced·16 min read·Updated 2026-10-15

Cloud Metadata SSRF Attacks: AWS IMDSv2, GCP & Azure Defense

Original WeSecureX guide for authorized testing of sites you own. Linked Sources are citations for verification - not copied articles. Ads are not served on this page.

Server-Side Request Forgery (SSRF) targeting the link-local cloud metadata address (`http://169.254.169.254`) has been the root cause behind some of the largest data breaches in cloud computing history. When web applications accept user-supplied URLs to generate image previews, fetch webhooks, or import remote documents without strict validation, attackers trick the server into issuing HTTP requests to internal cloud metadata services. In AWS, GCP, and Azure, the metadata service provides instance identity documents, temporary IAM security credentials, and bootstrap configuration scripts. This guide details cloud SSRF attack mechanics and engineering defenses, including AWS IMDSv2 session token enforcement and egress network filtering via the [WeSecureX Security Scanner](/scanner), [Surface Recon](/surface), and [Vulnerabilities Catalog](/vulnerabilities). Learn more about [The Anatomy of a Data Breach](/blog/the-anatomy-of-a-data-breach-how-attackers-find-and-exploit-vulnerabilities).

Quick Answer

Neutralize cloud metadata SSRF by mandating AWS IMDSv2 (requiring a PUT session token), setting metadata hop limit to 1 in containerized environments, resolving DNS to block RFC 1918 and link-local IP ranges (169.254.0.0/16) at the application layer, and enforcing strict egress firewall rules.

Key Takeaways
  • Cloud metadata services (169.254.169.254) provide temporary IAM credentials to local instances.
  • IMDSv2 requires an HTTP PUT session token, neutralizing simple GET-based SSRF.
  • DNS Rebinding bypasses naive hostname allowlists; resolve and pin IPs in code.
  • Continuous automated scanning ensures newly added webhook endpoints do not introduce SSRF.
Visual Diagram · Cloud Metadata SSRF Attack vs IMDSv2 Session Token Defense
1

1. User Input Injection

Attacker inputs user-controlled URL http://169.254.169.254/latest/meta-data/.

2

2. Backend Server Fetch

Vulnerable web application issues server-side HTTP GET request to link-local IP.

3

3. IMDSv1 Credential Leak

Under IMDSv1, metadata responds with temporary AWS IAM secret access keys.

4

4. IMDSv2 Token Defense

IMDSv2 requires pre-authenticated PUT session token, rejecting blind SSRF GETs.

ShareShare on XLinkedIn

1. The Cloud Metadata Service Architecture (169.254.169.254)

WeSecureX Scanner detecting cloud metadata SSRF endpoints
WeSecureX Scanner detecting cloud metadata SSRF endpointsWeSecureX Platform View

All major hyper-scale cloud infrastructure providers - including Amazon Web Services (AWS), Google Cloud Platform (GCP), Microsoft Azure, and DigitalOcean - implement an internal instance metadata service accessible strictly from within running virtual machines or container hosts. This service is universally hosted at the non-routable IPv4 link-local address 169.254.169.254 (defined by RFC 3927). The instance metadata service is designed to allow bootstrap initialization scripts, cloud-init daemons, and software agents to retrieve contextual operating parameters - such as the virtual machine's instance ID, availability zone, security groups, public IP address, and, most critically, temporary IAM role credentials.

Because the link-local address is physically isolated to the host instance and cannot be routed across the public internet, early cloud implementations (like AWS IMDSv1) operated under a flawed assumption of network trust: any process executing on the virtual machine was assumed to be an authorized system service. In legacy IMDSv1, querying metadata requires zero authentication: an HTTP GET request to http://169.254.169.254/latest/meta-data/iam/security-credentials/{role-name} immediately returns the active IAM role's AccessKeyId, SecretAccessKey, and Token session parameters.

When a web application hosted on that virtual machine contains a Server-Side Request Forgery (SSRF) vulnerability - such as an unvalidated profile image URL importer, a PDF generation tool that renders remote HTML stylesheets, or a webhook verification endpoint - an external adversary can supply http://169.254.169.254 into the target parameter. The backend server issues the request using its internal network privileges, retrieves the secret IAM credentials, and reflects them back to the attacker. With these credentials, the attacker can connect directly to AWS cloud APIs using the AWS CLI, downloading sensitive S3 buckets, snapshotting production RDS databases, and pivoting across the entire cloud tenant.

Audit your endpoints and test for cloud metadata exposures using the WeSecureX Security Scanner and inspect external subdomains on Attack Surface Management.

Important

Under legacy IMDSv1, any process running on an EC2 instance can query 169.254.169.254 with a simple GET request. An SSRF flaw in any web application hosted on that instance results in complete cloud IAM credential theft.

2. Mandating AWS IMDSv2 (Session-Oriented Metadata)

WeSecureX Attack Surface Management mapping cloud assets and perimeter defenses
WeSecureX Attack Surface Management mapping cloud assets and perimeter defensesWeSecureX Platform View

To eradicate the cloud metadata SSRF attack vector, AWS engineered the Instance Metadata Service Version 2 (IMDSv2). IMDSv2 replaces the unauthenticated GET model of IMDSv1 with a secure, session-oriented protocol that requires callers to perform a two-step cryptographic handshake.

Under IMDSv2, any client or software process attempting to access metadata must first issue an HTTP PUT request to http://169.254.169.254/latest/api/token, supplying a mandatory custom header: X-aws-ec2-metadata-token-ttl-seconds: 21600 (specifying the session token lifetime in seconds, up to a maximum of 6 hours). In response, the metadata service generates a cryptographically signed, unguessable session token. All subsequent metadata queries must include this token in an X-aws-ec2-metadata-token header.

Because the vast majority of real-world SSRF vulnerabilities (e.g., in PDF converters, image importers, and webhook dispatchers) are restricted to standard HTTP GET or POST requests and cannot forge custom HTTP PUT verbs or custom header attributes across network boundaries, IMDSv2 completely neutralizes metadata exfiltration. Furthermore, in containerized Docker or Kubernetes architectures running on EC2 hosts, setting the metadata response hop limit to 1 (http-put-response-hop-limit 1) guarantees that IP packets cannot traverse the Docker virtual network bridge, permanently barring containerized microservices from stealing the underlying EC2 host's IAM instance profile.

Enforcing IMDSv2 across all AWS launch templates, Auto Scaling groups, and standalone instances is considered an absolute security baseline in modern cloud architecture.

Audit your cloud instance metadata configurations and perimeter security with the WeSecureX Vulnerabilities Catalog and Attack Surface Reconnaissance.

bash
# Enforce IMDSv2 across existing AWS EC2 instances via AWS CLI
$ aws ec2 modify-instance-metadata-options \
    --instance-id i-0123456789abcdef0 \
    --http-tokens required \
    --http-put-response-hop-limit 1 \
    --http-endpoint enabled

3. Defending Against DNS Rebinding & URL Parser Discrepancies

WeSecureX Vulnerabilities Catalog showing SSRF remediation blueprints
WeSecureX Vulnerabilities Catalog showing SSRF remediation blueprintsWeSecureX Platform View

A widespread engineering mistake when mitigating SSRF is attempting to validate user-supplied URLs using regular expressions or performing a single hostname check before fetching the URL. Attackers easily bypass naive application-layer string filters using DNS Rebinding and IP obfuscation techniques.

In a DNS Rebinding attack, an adversary registers a custom domain (such as evil-rebind.com) configured on an authoritative nameserver that delivers responses with a Time-to-Live (TTL) of 0 seconds. When the application server executes its validation logic, it performs a DNS lookup: the nameserver responds with a harmless public IP address (such as 93.184.216.34). Because the IP is public, the validation check passes. A few milliseconds later, when the application's HTTP client opens a TCP socket to execute the request, the socket library performs a second DNS query because the TTL expired. At this instant, the nameserver responds with 169.254.169.254 or 127.0.0.1, coercing the server into connecting directly to the restricted internal metadata endpoint.

Building an impenetrable defense against SSRF requires a two-phase socket pinning architecture:

  1. Asynchronous DNS Resolution: Resolve the target hostname using the host DNS resolver to obtain all associated IPv4 and IPv6 addresses.
  2. CIDR Subnet Validation: Assert that none of the resolved IPs fall within private subnets (RFC 1918 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16), loopback space (127.0.0.0/8, ::1), or link-local metadata space (169.254.0.0/16, fe80::/10).
  3. Socket IP Pinning: Pass the pre-validated IP address directly into the HTTP client socket options so the outgoing TCP connection connects exclusively to the verified IP without performing a second DNS query.
  4. Disable Redirect Following: Configure HTTP fetch libraries with redirect: 'manual' to prevent attackers from using 301 redirects to jump to metadata endpoints.

Check your open ports and perimeter routing with the WeSecureX Open Port Scanner and verify DNS records using our DNS Record Lookup.

Tip

Always disable automatic HTTP redirect following in server fetch clients. An attacker can supply a trusted URL that returns a 301 redirect to 169.254.169.254, bypassing validation if redirects are followed automatically.

Apply it with WeSecureX

Add a hostname you own or are allowed to test, run a scan, and open the findings for that target. A confirmed result includes the request WeSecureX sent and the response the site returned, so you can reproduce it, fix it in your own application, and rescan the same host to confirm the issue is gone. WeSecureX is automated testing, not a manual penetration test, and a clean report is not a promise that every weakness is gone.

Checks that belong with this topic

  • Enforce AWS IMDSv2 (--http-tokens required) across all EC2 instances.
  • Set EC2 metadata hop limit to 1 in containerized Docker/Kubernetes environments.
  • Block link-local (169.254.0.0/16) and RFC 1918 private IP ranges in application network layers.
  • Enforce Metadata-Flavor: Google header checks on Google Cloud instances.
  • Validate user-supplied URLs using socket pinning to neutralize DNS Rebinding.
  • Audit endpoints for SSRF vulnerabilities in the [WeSecureX Vulnerabilities Dashboard](/vulnerabilities).

Actionable Checklist

WeSecureX Platform · Scanner Engine

Automated Vulnerability Scanner

Launch targeted or full-domain security audits to detect OWASP Top 10 vulnerabilities automatically.

Includes: OWASP Top 10 automated test suites · Real-time severity scoring (CVSS v3.1) · Instant remediation code snippets

Frequently Asked Questions

169.254.169.254 is an IPv4 link-local address reserved by cloud providers (AWS, GCP, Azure) to host the Instance Metadata Service (IMDS).

Setting the IMDSv2 hop limit to 1 ensures the packet cannot traverse a network bridge, preventing containers running inside EC2 from accessing the host instance's IAM credentials.

Launch an authorized test on your domain using the [WeSecureX Scanner](/scanner).

Authoritative Sources & References

  • AWS Documentation: Use IMDSv2Amazon Web Services (official)
    View Source

Continue exploring related technical architecture and defensive guides

Security Research & Engineering Articles

All articles