Cybersecurity Topics: Threats, Defences and Careers · Course book
Chapter 10: Server-Side Request Forgery
Many web applications fetch things from other places on a user's behalf. A social network fetches a preview of a link you paste, a document tool imports an image from a web address, and an online service sends notifications to an address you configure. Each of these features means the server itself makes a request to a location chosen, at least partly, by the user. Server-side request forgery (SSRF) occurs when an attacker abuses such a feature to make the server send requests to places it should never contact, most dangerously to internal systems that are hidden from the internet but trust the server completely. This chapter explains how SSRF works, why it is particularly serious in cloud environments, the main types of SSRF including blind SSRF, a real-world case that shows its impact, and the layered defences that prevent it.
What SSRF is
In most attacks, the attacker sends requests directly to the target. In SSRF, the attacker persuades a server to send requests for them. This matters because of where the server sits. A web server is usually inside the organisation's network, or inside a cloud environment, with access to internal services such as databases, administration panels, monitoring tools and configuration services. Those internal systems are often protected only by the fact that outsiders cannot reach them. They may require no password at all for requests that come from inside the network. SSRF turns the trusted server into a proxy that carries the attacker's requests past the network's outer defences.
SSRF is common enough to have its own category, A10, in the 2021 OWASP Top 10 list of web application risks. It became more prominent as applications moved to the cloud and began relying heavily on internal web-based services, many of which assume that any request reaching them is legitimate.
The features that create SSRF risk are often genuinely useful, which is why the flaw keeps reappearing. Webhooks let customers give a service an address to notify when an event happens, such as a payment completing. Link previews fetch a page's title and image when someone pastes a link into a chat. Import tools pull data from a feed or a file stored elsewhere, and document converters may follow references to images and fonts embedded in uploaded files. In each case the developer's attention is on making the feature work for honest users, and the question "what if the address points somewhere internal?" is easily forgotten. Threat modelling at the design stage, asking where every outbound request could go, is the most reliable way to catch these designs before they are built.
How an SSRF attack works
Imagine a website that lets users upload a profile picture by entering the web address of an image. The server takes the address, downloads the image and stores it. Normally a user enters the address of a picture on a public website. An attacker instead enters an address that points inside the network, such as an internal administration page that is reachable only from the server's own network, or a special local address that refers to the server itself. The server, following its instructions, makes the request and may return the response, or part of it, to the attacker.
Attackers aim SSRF at several kinds of target. Internal services such as administration interfaces, internal application programming interfaces and databases with web front ends may reveal data or accept commands. The server's own local services, reached through the special address that means "this machine", may expose management functions. Internal network scanning becomes possible, because the attacker can learn which internal addresses and ports respond by observing how the server reacts to different requests. And in cloud environments, the most valuable target is often the instance metadata service.
Why the cloud raises the stakes
Cloud providers give each virtual server a metadata service: a special internal address, reachable only from that server, that supplies information about its configuration. On several major platforms it is the link-local address 169.254.169.254. Crucially, the metadata service may also hand out temporary credentials that let software on the server access other cloud resources, such as storage buckets and databases, with whatever permissions the server has been granted. An SSRF flaw that can reach the metadata service may therefore let an attacker obtain those credentials and use them from anywhere.
This is not a theoretical concern. In 2019, the American bank Capital One suffered a breach affecting about 100 million people in the United States and around six million in Canada. The attacker exploited a misconfigured web application firewall running in the bank's cloud environment, used it to make requests to the metadata service, obtained credentials and then copied data from cloud storage. The case became a standard example of how SSRF, combined with overly broad permissions, can turn one configuration mistake into a very large data breach. In response, cloud providers strengthened their metadata services; for example, newer versions require a session token obtained with a special request before they will release credentials, which blocks many simple SSRF attacks.
Types of SSRF, including blind SSRF
SSRF vulnerabilities are usually classified by how much the attacker can see.
| Type | What the attacker sees | What they can still achieve |
|---|---|---|
| Basic (in-band) SSRF | The full response from the internal request is returned | Read internal pages, data and credentials directly |
| Partial SSRF | Some of the response, such as error messages or file sizes | Infer information piece by piece |
| Blind SSRF | Nothing from the response | Trigger actions on internal systems; map the network by timing; confirm the flaw using an outside server they control |
In blind SSRF the server makes the request but never shows the result. It might seem harmless, but attackers can still use it. They can point the server at a system they control on the internet and watch for the incoming connection, which confirms the vulnerability. They can measure how long requests take to learn which internal addresses exist. And if an internal service changes something in response to a simple request, such as restarting a process or deleting a record, they can trigger that action without ever seeing a response. Blind SSRF is harder to exploit but should be fixed with the same urgency.
Attackers also try to get around weak filters. A filter that blocks the word "localhost" may miss other ways of writing the same address, such as numeric forms or domain names that resolve to internal addresses. A filter that checks an address once, before the request, may be fooled if the name later resolves to a different address, or if the target replies with a redirect to an internal location. This is why simple "blocklists" of forbidden addresses are not enough.
Preventing SSRF
The most effective defences combine several layers. First, avoid the feature where possible: if users need to supply images, let them upload files rather than giving the server a web address to fetch. Where the server must fetch addresses, use an allowlist of permitted destinations, such as a fixed set of trusted partner domains, rather than trying to list everything that is forbidden. Accept only the protocols that are needed, normally HTTPS, and reject others.
Second, validate at the network level, not just in text. The application should resolve the destination name to an address and check that the address is public, not private, loopback or link-local, and it should repeat the check for every redirect, or simply not follow redirects. Third, use network segmentation: servers that fetch external content can run in a restricted zone whose firewall rules forbid connections to internal systems and the metadata service. Fourth, harden internal services so that they require authentication even for requests from inside the network, in line with the Zero Trust principle that location alone is never proof of trust. Fifth, in the cloud, use the strongest metadata service settings, such as session-token requirements, and give each server's credentials least privilege, so that even stolen credentials unlock very little. Finally, monitor outbound requests from servers; a web server suddenly contacting internal administration pages or the metadata service is a clear warning sign.
Testing should check for SSRF deliberately. Authorised testers try internal addresses, alternative ways of writing them, redirects and names that resolve to private ranges, and they watch an outside server they control for signs of blind requests. Developers can add automated tests that confirm the application refuses private and link-local destinations, so that a later change cannot quietly reintroduce the flaw.
Check your understanding
- Explain in your own words why SSRF lets an attacker reach systems that a firewall would normally protect.
- Give three legitimate application features that could contain an SSRF vulnerability.
- Why is the cloud metadata service such a valuable SSRF target?
- Describe the sequence of events in the 2019 Capital One breach and identify two controls that could have limited it.
- What can an attacker achieve with blind SSRF, even though they never see the response?
- Explain why an allowlist is safer than a blocklist for preventing SSRF.
This course book is available to read online only at chrysolites.org.