A server does not only serve the internet: it downloads a file from a user-supplied link, calls a webhook, fetches a page preview. If nothing validates that address, an attacker can put an internal one in place of an external site, and the server makes the request itself, with its own privileges and from inside the perimeter.
How the attack works
One function that takes a URL from outside is enough. The CWE-918 classification describes it like this: the server accepts an address from an upstream component and retrieves the content, but does not ensure that the request goes to the expected destination. From inside the network the server can see what is closed to the outside, so swapping the address opens up several targets at once.
| Target inside the network | What the attacker gains |
|---|---|
Cloud metadata service 169.254.169.254 | credentials and tokens the server uses to talk to the cloud |
| Services on the server itself | admin panels and APIs that listen only on localhost |
| Databases and internal services | requests that bypass the firewall |
Schemes such as file:// | reading the server’s local files |
The response is often visible in the interface, in a preview or a download. But a blind variant works too, where the response is not shown: from timing and errors, the server can be turned into a port scanner for the internal network.
How to defend against it
The best defence is not to accept a whole URL. If the destinations are known in advance, check the host against an allowlist and let the application build the request itself, setting the scheme, port and path.
- Block private and reserved addresses:
127.0.0.0/8,10.0.0.0/8,169.254.0.0/16and other internal ranges. - Check the resolved IP address at the moment of connection, not before it: otherwise DNS rebinding works. The name was validated, but by the time of the connection DNS answers with an internal address.
- Reject an address if two parsers read it differently: a string such as
http://example.com\@evil.comcan mean different hosts in different libraries. - In the cloud, require IMDSv2: the AWS metadata service answers only requests that carry a token, which is first obtained with a separate PUT request from the same server.
Sources
the term is written from these pages- CWE-918: Server-Side Request Forgery (SSRF)cwe.mitre.org/data/definitions/918.html(opens in a new tab)
- OWASP Server-Side Request Forgery Prevention Cheat Sheetcheatsheetseries.owasp.org/cheatsheets/Server_Side_Request_Forgery_Prevention_Cheat_Sheet.html(opens in a new tab)
- AWS — Configuring instance metadata optionsdocs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-options.html(opens in a new tab)
Verified 9 Nov