What is server-side request forgery (SSRF)?

Server-side request forgery (SSRF) is a vulnerability where an application fetches a URL or host supplied by a user without restricting where it goes. The user can then point the server at addresses only it can reach, such as an admin service on 127.0.0.1, a database on the private network or the cloud metadata service.

Part of the roadmap: Stage 5, Deeper web and APIs

Why it matters

MITRE files it as CWE-918. It had its own category, A10, in the OWASP Top 10:2021, and the 2025 edition lists it under A01, broken access control. That framing helps: the server has network access the user does not, and the bug lends it to them. Behind a firewall, internal services often trust any request from the web tier, so a request the server makes on a stranger's behalf arrives with that trust.

On cloud hosts the metadata service is the classic target, because it can hand out the instance's credentials. AWS added IMDSv2, which requires a session token from a PUT request, as defence in depth against exactly this. It reduces the damage; the fix is still in the code that fetched the URL.

Example: a link-preview endpoint, vulnerable and fixed

The usual places are link previews, import from URL, avatar upload by URL, webhooks, and HTML-to-PDF or screenshot services. In our own lab, a link-preview endpoint on localhost that called fetch on the user's URL returned the reply of a stand-in internal admin service on 127.0.0.1:9000, and that service's log showed the request coming from the app itself.

In your own app (https://your-app.example), find every handler where a value named url, link, callback or webhook reaches an HTTP client. The fix allows only the destinations you mean and refuses redirects:

// Vulnerable: any destination the user names
const page = await fetch(req.query.url);

// Safer: an allow-list of hosts, checked again on the resolved IP, no redirects
if (!ALLOWED_HOSTS.has(new URL(req.query.url).hostname)) return res.sendStatus(400);
const page = await fetch(req.query.url, { redirect: "error" });

If the app must fetch arbitrary public URLs, resolve the hostname yourself, refuse private, loopback and link-local addresses, and connect to the address you checked. Log every outbound fetch with its resolved IP: it is the log that answers where your server connected.

Common mistakes

  • Blocking the string localhost. 127.0.0.1, ::1, decimal IPs and DNS names that resolve inward all get through. Check the resolved address.
  • Checking the URL, then letting the client follow redirects. A public URL can redirect inward. Turn redirects off or check every hop.
  • Checking the hostname once and connecting later. DNS can answer differently the second time. Connect to the IP you validated.
  • Forgetting background jobs. A saved webhook or feed URL is fetched later, often from a host with more network access.

Related terms

Go deeper

Sources

Test only sites you own or have written permission to test. To practise without one, use CyberGym, a legal, deliberately vulnerable target. Practise on CyberGym.