HACKORY
Language · English
← All chapters
HACKORY / Open library

Server-side request forgery (SSRF)

Some apps visit an address for you: for example, they download the image from a URL you paste. SSRF is the flaw where that visit, made by the server, reaches places it should never go.

New here? Try the first lesson without an account

How it works

The server sits at a different network position from your browser: it lives inside the company’s network, like an employee inside the building, and can reach internal services that are invisible from outside. A typical one in the cloud is the metadata service, which tells the server about its own configuration and sometimes hands out credentials. Also, the final destination can change through a redirect or through the way the URL is interpreted.

Expected behavior

The app downloads images only from allowed destinations and checks the final URL after finding out which address it points to.

What can go wrong

A parameter containing a URL leads the server to an internal destination, sometimes after a redirect.

What to observe

Record which host the server requests and the final path it visits; the fictional lab host is interno.test.

Common false positive

localhost in your browser is your device; localhost in a request made by the server is the server itself: they are different machines.

Why it matters

It depends on which destinations the server can reach and what it can send to or read from them: from confirming that an internal service exists to obtaining its data.

How to fix it

Allow only defined destinations, check the destination again after every redirect, and find out which IP address the name points to before connecting, so internal networks and metadata can be blocked.

Understand it step by step

Who visits the URL

When uploading an image, your browser sends the site a URL. Then the site’s server makes its own request to that URL. That second request leaves from the server and can reach destinations your browser cannot see. What you control is the URL; the effect depends on which address the server resolves it to and what it does with the response.

Redirect and final destination

A redirect is a response, for example with code 302, that says “go to another address”; the new address travels in the Location header. If imagenes.test/redirigir responds with Location: http://interno.test/estado, the final destination is interno.test/estado. The lab uses interno.test as a fictional name and states so in the case. Writing another host, such as test.test, describes another destination and does not prove that the scenario’s internal service was reached.

Why localhost is confusing

localhost in the URL the server requests points to the server itself; localhost in your address bar points to your device. Some practice environments represent internal services with different fictional names and accept only those names. To conclude there is SSRF, identify which host the server actually visited, after redirects and normalization, and which data or action was exposed.

Recommend this chapter to a friend