Server-Side Request Forgery
What is SSRF?
Section titled “What is SSRF?”Server-Side Request Forgery (SSRF) is a vulnerability where an attacker manipulates a web application into making an HTTP underlying network request to an unintended destination.
Instead of attacking the server from the outside (where firewalls and load balancers block traffic), the attacker forces the server itself to perform the attack on their behalf.
The Core Problem
Section titled “The Core Problem”Many modern web applications need to fetch data from external sources. For example:
- A social media platform fetching a preview image from a linked URL.
- A webhook integration pinging an external service on an event.
- A PDF generator taking a URL and rendering it.
If the application takes a URL from the user and blindly makes a server-to-server request without validating the destination, an SSRF vulnerability exists.
The Targets of SSRF
Section titled “The Targets of SSRF”When an attacker successfully controls the target URL, they typically attempt to access resources that are normally unreachable from the public internet.
1. Cloud Metadata Services (The Capital Attack)
Section titled “1. Cloud Metadata Services (The Capital Attack)”The most common and devastating SSRF target in a modern cloud environment (AWS, GCP, Azure, DigitalOcean) is the internal Instance Metadata Service (IMDS).
These services always sit on a non-routable Link-Local IP address: 169.254.169.254.
If an attacker forces an AWS EC2 instance running a vulnerable web app to request http://169.254.169.254/latest/meta-data/iam/security-credentials/role-name, the server will return the temporary AWS IAM access keys assigned to the instance. The attacker now has the credentials to pivot into the AWS account.
(Note: AWS introduced IMDSv2 to mitigate this, which requires a specific PUT request and a token, complicating but not entirely eliminating the risk if the SSRF allows header injection).
2. Internal Network Pivoting
Section titled “2. Internal Network Pivoting”Corporate networks often have internal administrative panels, monitoring dashboards (Prometheus, Grafana), or unauthenticated databases (Redis, Elasticsearch) running on localhost (127.0.0.1) or the internal subnet (e.g., 10.0.0.0/8).
An attacker can use cheap cloud instances to fuzz the internal network using SSRF, effectively port scanning the internal architecture.
http://localhost:8080/admin/deleteUser?id=1http://10.0.0.51:6379/ <-- Accessing an internal Redis node3. Blind SSRF
Section titled “3. Blind SSRF”In a standard SSRF, the backend server makes a request and returns the response directly to the attacker (e.g., the PDF generator outputs the AWS metadata).
In Blind SSRF, the request is made, but the HTTP response is never returned to the attacker. To exploit this, attackers usually rely on “Out-of-Band” (OOB) techniques, injecting URLs pointing to a server they control (like a Burp Collaborator payload) and observing what HTTP headers or IP address the incoming request possesses.
Mitigation Strategies
Section titled “Mitigation Strategies”Preventing SSRF requires strict control over outgoing network requests from your backend logic.
- Strict Whitelisting: If your application only needs to fetch data from
api.partner.com, hardcode that domain or use a strict whitelist. Never accept arbitrary domains if you can avoid it. - Network Segmentation (Egress Filtering): Implement strict egress firewalls. The backend application server should only be allowed to make outbound connections to specific IPs or domains it requires. It should never be allowed to talk to the Cloud Metadata IP (
169.254.169.254) unless absolutely necessary, and even then, use IMDSv2. - Disable Unused Protocols: Disable support for non-HTTP URIs (like
file://,ftp://, orgopher://), which can be used to exfiltrate local files or interact with internal binary protocols like Redis. - DNS Resolution Checks: If accepting user URLs, perform a DNS lookup before making the HTTP request to ensure the resolved IP address is not a private, local, or loopback block (e.g.,
127.0.0.1,10.x.x.x,192.168.x.x). Watch out for DNS Rebinding attacks.