security
ssrf
ai_generated
true
SSRF attack accesses cloud metadata endpoint (169.254.169.254) via user-supplied URL
ID: security/ssrf-metadata-endpoint-cloud
92%Fix Rate
95%Confidence
3Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| any | active | — | — | — |
Root Cause
Cloud instances (AWS/GCP/Azure) have a metadata endpoint at 169.254.169.254 that returns IAM credentials, API keys, and instance configuration. If your app fetches user-supplied URLs, attackers can read cloud credentials via SSRF.
genericWorkarounds
-
92% success Require IMDSv2 (token-based) on all cloud instances
aws ec2 modify-instance-metadata-options --instance-id i-xxx --http-tokens required # blocks simple SSRF
-
90% success Resolve DNS and validate the IP address is not private/link-local before fetching
import ipaddress; ip = socket.getaddrinfo(hostname, port)[0][4][0]; if ipaddress.ip_address(ip).is_private: reject()
-
88% success Use network-level controls: block metadata endpoint access from application subnets
iptables -A OUTPUT -d 169.254.169.254 -j DROP # or use VPC network policies to block metadata access
Dead Ends
Common approaches that don't work:
-
Block 169.254.169.254 in URL validation regex
85% fail
Attackers bypass with: decimal IP (2852039166), IPv6 (::ffff:169.254.169.254), DNS rebinding, redirects from allowed domains, or alternate representations.
-
Use URL parsing to extract hostname and block known-bad IPs
82% fail
URL parsers are inconsistent. http://[email protected], http://[::ffff:a9fe:a9fe], and http://0xa9fea9fe all resolve to the metadata endpoint.