Server-Side Request Forgery (SSRF) Explained
Server-side request forgery, or SSRF, is a vulnerability that lets an attacker coax a server into making network requests to destinations of the attacker's choosing. Instead of attacking the server directly, the adversary uses it as a proxy to reach systems it can access but the attacker cannot, such as internal services, cloud metadata endpoints, and databases behind a firewall. Because the request originates from a trusted server, it often bypasses network controls that would block an outside connection.
How SSRF Works
Many applications fetch remote resources as part of normal operation: importing a document from a URL, generating a link preview, calling a webhook, or retrieving an image for processing. When the destination is derived from user input and is not properly restricted, an attacker can substitute an internal address.
Consider a feature that fetches a URL supplied by the user:
POST /api/fetch HTTP/1.1
Host: app.example.com
url=http://169.254.169.254/
Instead of an external site, the attacker points the server at the cloud instance metadata address, a link-local endpoint reachable only from the host. The server dutifully makes the request and may return sensitive data, such as temporary cloud credentials, in the response.
Common SSRF Targets
- Cloud metadata services that expose instance credentials and configuration to the host.
- Internal-only services such as admin panels, message queues, and databases not exposed to the internet.
- Loopback addresses that reach services bound to the server itself.
- Link-local and private ranges used inside corporate or cloud networks.
Blind SSRF
Sometimes the response is not returned to the attacker. In blind SSRF, the attacker confirms the request happened through side channels, such as a DNS lookup or an HTTP callback to a server they monitor. Even without a readable response, blind SSRF can be used to map internal networks or trigger actions on internal services.
How to Prevent SSRF
SSRF is best addressed with a combination of application and network controls, because any single layer can be bypassed.
Validate Destinations with an Allowlist
Where possible, restrict outbound requests to a strict allowlist of approved domains or endpoints. Allowlisting is far more reliable than trying to block known-bad addresses, because blocklists miss alternate encodings, redirects, and obscure address formats.
Block Internal Address Ranges
Resolve the destination hostname and verify the resulting IP address is not in a private, loopback, or link-local range before connecting. Perform this check after DNS resolution and re-check on any redirect, because a hostname can resolve to an internal address even when it looks external.
Restrict Schemes and Ports
Allow only the protocols the feature actually needs, typically HTTP and HTTPS, and reject schemes like file, gopher, or ftp that can reach unexpected services. Limit destination ports to those you expect.
Do Not Follow Redirects Blindly
An allowed URL can redirect to an internal one. Either disable automatic redirect following or validate each redirect target with the same rules applied to the original request.
Protect the Metadata Service
In cloud environments, require the hardened version of the instance metadata service that mandates a signed token, and apply strict outbound rules so workloads cannot reach the metadata address unless they genuinely need it.
Segment the Network
Treat SSRF as inevitable and limit its blast radius. Place services that make outbound requests in segments that cannot reach sensitive internal systems, and enforce egress filtering so the server can only contact approved destinations. This connects to the broader risks in the OWASP Top 10.
Beware DNS Rebinding
An attacker may return a benign IP when you validate a hostname, then switch to an internal IP when the connection is made. Mitigate this by resolving the host once, validating that address, and connecting to the same address, rather than resolving twice.
Detecting and Testing for SSRF
In authorized testing, SSRF is probed by supplying URLs that point at addresses only the server can reach and watching for differences in response content, status codes, or timing. A monitored external host that records incoming DNS or HTTP requests reveals blind SSRF where no response is returned to the tester. On the defensive side, log outbound requests from any service that fetches user-supplied URLs, and alert on connections to internal ranges so that an exploited endpoint is caught quickly rather than discovered after data has been exposed.
SSRF, CORS, and the Browser
SSRF is a server-side issue and is unrelated to browser controls such as CORS, which governs cross-origin requests made by browsers. Relying on browser-enforced policies does nothing to stop a server from making a forged request, so server-side validation is essential.
Key Takeaways
- SSRF makes a trusted server issue attacker-controlled requests, often reaching internal systems a firewall would otherwise protect.
- Cloud metadata endpoints and internal services are prime targets, and blind SSRF works even without a readable response.
- Allowlisting destinations is more reliable than blocklisting, and address checks must run after DNS resolution.
- Restrict schemes and ports, avoid blind redirect following, and harden the cloud metadata service.
- Network segmentation and egress filtering contain the impact when application controls are bypassed.