Bookmarks

SSRF — server-side request forgery

An attack in which a server sends a request to an address chosen by the attacker, giving them a route to internal resources that are not reachable from outside.

Also: SSRF attack, server-side request forgery attack

checked 9 Nov

All terms

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 networkWhat the attacker gains
Cloud metadata service 169.254.169.254credentials and tokens the server uses to talk to the cloud
Services on the server itselfadmin panels and APIs that listen only on localhost
Databases and internal servicesrequests 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/16 and 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.com can 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

Verified 9 Nov

Not to be confused with

what it is mixed up with and how it differs

  • CSRFcross-site request forgery

    CSRF makes the victim’s browser send a request to a site on their behalf; SSRF makes the server itself send a request wherever the attacker points.

  • CORScross-origin resource sharing

    CORS is a browser mechanism that restricts where a script may read responses from; SSRF is a vulnerability in server-side code and does not involve the browser.

In depth in the references

where the topic is covered in detail