How it works
Many features need the server to fetch something from an address the user provides: importing an image from a link, calling a webhook, generating a PDF from a web page, reading a feed. Server-side request forgery (SSRF) happens when the server fetches whatever address it is given without checking where that address leads.
The danger comes from the server's position. It sits inside the network, behind the firewall. It can talk to databases, admin panels and internal services that are invisible from the internet. Those services often trust any request that comes from inside. An attacker who controls where the server sends a request borrows that position.
In the cloud the stakes are higher. Virtual machines can query an instance metadata service at the fixed address 169.254.169.254, which can return temporary credentials for the machine's cloud role. An SSRF flaw that reaches it can turn a small web bug into access to the cloud account.
What it looks like
A profile page lets users set an avatar by pasting an image link. The normal request names a public image. An attacker sends an internal address.
POST /api/profile/avatar HTTP/1.1
Host: app.acme.test
Content-Type: application/json
{"image_url": "http://10.0.0.12:8080/admin/status"}HTTP/1.1 400 Bad Request
Content-Type: application/json
{"error": "not an image", "received": "{\"service\":\"admin\",\"status\":\"ok\"}"}The server connected to an internal admin service and echoed part of the reply in its error message. The attacker has read a page that no outside user should reach.
Variants worth knowing:
- Blind SSRF. The response is not shown. The attacker learns from timing and error differences.
- DNS tricks. A hostname resolves to a public address when it is checked and to an internal address when it is fetched.
How to test for it
Find every place where the server makes a request on the user's behalf, then check where it can be pointed.
- List the candidates. Look for parameters that hold links or hostnames, and for features such as webhooks, importers, link previews and document converters.
- Confirm that the server makes the request. Supply the address of a host you control and watch for an incoming connection.
- Try internal destinations. Use loopback addresses, private ranges and the metadata address. Compare responses, status codes and timing for clues, even when no content comes back.
- Show the impact safely. Reading a harmless internal status page proves the flaw. Do not collect credentials or change internal systems unless the rules of the test explicitly allow it.
How to fix it
Decide where the server is allowed to connect, and enforce that at the moment of connection.
import ipaddress, socket
from urllib.parse import urlparse
def check_destination(url):
parts = urlparse(url)
if parts.scheme != "https":
raise ValueError("only https is allowed")
address = socket.gethostbyname(parts.hostname)
if not ipaddress.ip_address(address).is_global:
raise ValueError("internal addresses are not allowed")
return address # connect to this exact address, do not resolve againThis sketch shows the three ideas that matter: allow only the expected scheme, resolve the name and reject non-public addresses, and connect to the address you checked so a second lookup cannot return something different.
Around that:
- Prefer an allowlist. If the feature only needs a few known hosts, accept only those.
- Do not follow redirects, or validate every hop the same way.
- Isolate the fetcher. Run it in a network segment with no route to internal services, and block outgoing traffic to the metadata address from workloads that do not need it.
- Harden the metadata service. Use the version that requires a session token, which a simple forged request cannot obtain.
Blocklists of bad strings fail, because there are too many ways to write the same address.
How it differs from cross-site request forgery
In cross-site request forgery (CSRF), the attacker tricks a victim's browser into sending a request, using the victim's logged-in session. In SSRF, the attacker tricks the server into sending a request, using the server's network position. CSRF abuses a user's identity. SSRF abuses a machine's location.
SSRF had its own entry in the 2021 OWASP Top 10 and is part of broken access control in the 2025 edition.