# SSRF bypasses cloud metadata endpoint block via redirect or alternative IP representation

- **ID:** `security/ssrf-cloud-metadata-bypass`
- **Domain:** security
- **Category:** network_error
- **Error Code:** `SSRF_METADATA_BYPASS`
- **Verification:** ai_generated
- **Fix Rate:** 85%

## Root Cause

The application blocks direct requests to 169.254.169.254 but does not handle redirects to that IP or alternative representations such as decimal IP (2852039166), IPv6 mapped IPv4 (::ffff:169.254.169.254), or DNS rebinding, allowing SSRF to access cloud metadata.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| AWS IMDSv1 | active | — | — |
| GCP Metadata Server 2023 | active | — | — |
| Azure IMDS 2024-02-01 | active | — | — |

## Workarounds

1. **Use a DNS resolver that resolves all hostnames and validate that the resolved IP is not in the private or link-local range (169.254.0.0/16, 10.0.0.0/8, etc.) before making the request. Example in Python: import socket; ip = socket.gethostbyname(hostname); if ipaddress.ip_address(ip).is_private: raise Exception('Blocked SSRF')** (90% success)
   ```
   Use a DNS resolver that resolves all hostnames and validate that the resolved IP is not in the private or link-local range (169.254.0.0/16, 10.0.0.0/8, etc.) before making the request. Example in Python: import socket; ip = socket.gethostbyname(hostname); if ipaddress.ip_address(ip).is_private: raise Exception('Blocked SSRF')
   ```
2. **Disable redirect following in HTTP clients (e.g., requests.get(url, allow_redirects=False)) to prevent redirect-based SSRF** (85% success)
   ```
   Disable redirect following in HTTP clients (e.g., requests.get(url, allow_redirects=False)) to prevent redirect-based SSRF
   ```
3. **Use IMDSv2 with a session token that requires a PUT request, making it harder for SSRF to access metadata even if the IP is reached** (80% success)
   ```
   Use IMDSv2 with a session token that requires a PUT request, making it harder for SSRF to access metadata even if the IP is reached
   ```

## Dead Ends

- **** — Attackers can use decimal IP (2852039166), hex (0xA9FEA9FE), or DNS names that resolve to that IP. (90% fail)
- **** — Does not block alternative ports (e.g., 443) or redirects that come from other IPs. (70% fail)
- **** — Attackers can use IPv6 mapped addresses or DNS rebinding to bypass the deny list. (65% fail)
