Server-Side Request Forgery (SSRF)
1. Definition
Server-Side Request Forgery (SSRF) is a vulnerability that allows an attacker to induce the server-side application to make HTTP requests to an arbitrary domain of the attackerâs choosing.
In a typical SSRF attack, the attacker might cause the server to make a connection to internal-only services within the organizationâs infrastructure, or force the server to connect to arbitrary external systems, potentially leaking sensitive data.
2. Technical Explanation
Modern applications often fetch resources from URLs provided by users (e.g., âImport from URLâ, âFetch previewâ, âWebhook callbacksâ).
If the server does not validate the destination, an attacker can:
- Access Internal Services: Request
http://localhost:6379(Redis),http://192.168.1.1/admin(Internal Admin), or cloud metadata endpoints. - Port Scanning: Use the server as a proxy to scan internal networks.
- Bypass Access Controls: Internal services often trust requests from âlocalhostâ and skip authentication.
Cloud Metadata Exploitation: Cloud providers (AWS, GCP, Azure) expose instance metadata at well-known URLs:
- AWS:
http://169.254.169.254/latest/meta-data/ - GCP:
http://metadata.google.internal/
These endpoints return IAM credentials, API keys, and configuration data.
3. Attack Flow
sequenceDiagram
participant Attacker
participant WebApp as Web Application
participant Meta as Cloud Metadata Service
participant Internal as Internal Database
Attacker->>WebApp: POST /fetch-url<br/>url=http://169.254.169.254/latest/meta-data/iam/
Note over WebApp: Server fetches the URL<br/>without validation
WebApp->>Meta: GET /latest/meta-data/iam/security-credentials/
Meta-->>WebApp: IAM Role Credentials JSON
WebApp-->>Attacker: Response contains AWS credentials
Note over Attacker: Attacker now has<br/>cloud infrastructure access4. Real-World Case Study: Capital One (2019)
Target: Capital Oneâs AWS Infrastructure. Vulnerability Class: SSRF leading to Cloud Metadata Access (CVE-2019-4872).
The Vulnerability: Capital One used a Web Application Firewall (WAF) that had an SSRF vulnerability. The WAF was configured with an IAM role that had excessive permissions.
The Attack:
- The attacker discovered the SSRF vulnerability in the WAF.
- They sent requests to
http://169.254.169.254/latest/meta-data/iam/security-credentials/ - Retrieved temporary AWS credentials assigned to the WAFâs IAM role.
- Used these credentials to access S3 buckets containing customer data.
Impact: Over 100 million customer records were exposed, including names, addresses, credit scores, and Social Security numbers. This resulted in an $80 million fine and became a landmark case for cloud security.
5. Detailed Defense Strategies
A. Input Validation and Allowlisting
Never allow user-controlled URLs to access arbitrary destinations.
- Allowlist: Only permit requests to known, trusted domains.
- Deny by Default: Block private IP ranges (10.x.x.x, 172.16-31.x.x, 192.168.x.x, 127.x.x.x, 169.254.x.x).
- Protocol Restriction: Only allow
https://- blockfile://,gopher://,dict://.
B. DNS Resolution Validation
Attackers can bypass IP blocklists using DNS rebinding or domain names that resolve to internal IPs.
- Mechanism: Resolve the hostname first, then validate the IP address before making the request.
- Re-check: Validate the IP again after DNS resolution (prevent TOCTOU attacks).
C. Network Segmentation
Isolate servers that need to fetch external URLs.
- Firewall Rules: Servers that fetch user-provided URLs should not have access to internal services or metadata endpoints.
- Dedicated Proxy: Route all outbound requests through a hardened proxy with strict allowlists.
D. Disable Cloud Metadata (or Use IMDSv2)
- AWS IMDSv2: Requires a session token obtained via PUT request, making SSRF exploitation significantly harder.
- Block Metadata: If not needed, use firewall rules to block access to 169.254.169.254.
# AWS: Enforce IMDSv2 on EC2 instances
aws ec2 modify-instance-metadata-options \
--instance-id i-1234567890abcdef0 \
--http-tokens required