1. The Cloud Metadata Service Architecture (169.254.169.254)

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.
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)

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.
# 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 enabled3. Defending Against DNS Rebinding & URL Parser Discrepancies

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:
- Asynchronous DNS Resolution: Resolve the target hostname using the host DNS resolver to obtain all associated IPv4 and IPv6 addresses.
- 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).
- 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.
- 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.
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.
WeSecureX modules for this topic
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
Related Guides
Continue exploring related technical architecture and defensive guides
SSRF · OWASP
SSRF (Server-Side Request Forgery): Detection, Impact & Prevention
Learn how SSRF lets attackers coerce your servers into calling internal services and cloud metadata endpoints - and how to block it with allowlists and DNS-safe validation.
OWASP Top 10 · web application security
OWASP Top 10 Web Application Security Risks Explained
The definitive architectural guide to the OWASP Top 10: comprehensive breakdown of all 10 vulnerability categories, root causes, exploit patterns, and remediation code.
API · BOLA
API Security in 2026: The Biggest API Vulnerabilities and How to Prevent Them
APIs are the product. Focus on object-level auth, least data, strong authn, and automated testing in 2026.