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

Also available as: JSON · Markdown
92%Fix Rate
95%Confidence
3Evidence
2023-01-01First Seen

Version Compatibility

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

generic

Workarounds

  1. 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
  2. 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()
  3. 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:

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

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