SSRF Explained: How Servers Are Tricked Into Attacking

SSRF explained in plain terms means understanding the attack that turns a trusted server into a weapon against its own network, by tricking it into making requests it was never meant to make. The central question is how an attacker on the outside can reach systems that are hidden behind a firewall, and the answer is to ask the server to fetch a URL for them, and let the server’s own privileges do the rest.

SSRF, short for server-side request forgery, is a vulnerability in which an attacker causes a server to send a request to an internal system, or to a third-party system, chosen by the attacker. The server is trusted inside the network, so it can reach databases, admin panels, and cloud metadata services that no outsider can, and the attacker borrows that trust to scan, steal, or attack from the inside.

The idea is simple: the server fetches what it is told to fetch. Many applications accept a URL from the user, to fetch an image, check a link, or import a feed, and if that URL is not checked, an attacker can point it at an internal address instead, such as the cloud metadata service, and the server will obediently fetch it and return the result. This article explains what SSRF is, how it works, and where it is used.

Key takeaways

  • SSRF tricks a server into making requests chosen by an attacker.
  • The server’s trusted position inside the network is what makes it dangerous.
  • Cloud metadata services are the most valuable target.
  • It can be used to scan internal systems and steal credentials.
  • Allow lists and network segmentation are the main defences.

What SSRF is

SSRF happens wherever a server fetches a resource named by the user. Image uploaders that fetch a picture from a URL, link previewers that fetch a page to show a snippet, feed readers that import a remote feed, and webhooks that call back to a user-supplied address are all classic cases, because each one hands the attacker a way to choose the destination of a server-side request.

The attack works because the server sits inside the trust boundary. A request from the server to an internal address, such as a database admin panel or a service on localhost, is treated as trusted, where the same request from the internet would be blocked by the firewall. The attacker does not need to break through the firewall at all: they ask the server, which is already inside, to make the request for them.

The most valuable target is usually the cloud metadata service. On most cloud platforms, a server can fetch its own temporary credentials from a special internal address, and an SSRF that reaches that address returns credentials that let the attacker act as the server itself, reading data and calling cloud services with the server’s permissions. Our guide to XSS explains the attack that runs scripts in a victim’s browser, and our guide to CSRF explains the attack that forges requests from a victim’s browser.

How SSRF works

The attack starts with a feature that fetches a URL. The attacker supplies a URL pointing at an internal address, such as http://169.254.169.254/ on a cloud platform, which is the metadata service, or http://localhost:8080/admin, which might be an internal admin panel, and the server fetches it, believing it to be an ordinary user request.

The server’s response reveals what it found. In the simplest case, the application returns the fetched content to the attacker, who reads the credentials or the internal page directly. In a blind SSRF, the application returns nothing, but the attacker can still learn from timing, error messages, or a second request the server makes, such as a DNS lookup to a domain the attacker controls, which confirms that the address was reachable.

Once the attacker can reach internal systems, the attack expands. An internal admin panel can be used to change settings, an internal API can be called with the server’s credentials, and a scan of the internal network can map every service that answers, which gives the attacker a list of targets for the next stage of the intrusion.

Redirects and URL parsing tricks help the attacker bypass weak defences. A server that blocks the metadata address directly can be fooled by a redirect from an allowed address, by an encoded address such as 0xA9FEA9FE, by a decimal address, or by a DNS name that resolves to an internal address only after the check has passed, which is why allow lists must be checked after every redirect, not just once.

SSRF is not limited to HTTP. A server that fetches a URL can be tricked into speaking other protocols, such as Gopher or FTP, to services that expect them, which lets an attacker send crafted requests to databases and mail servers that were never meant to be reachable from the web at all.

A laptop on a dark desk with its screen showing a glowing green server sending a request through a firewall to an internal system
A laptop showing a glowing green server sending a request through a firewall to an internal system shows how SSRF works: the server asked to attack its own network.

Comparing SSRF with other web attacks

SSRF is one of several attacks that abuse trust, and each works differently. XSS runs scripts in a victim’s browser, CSRF forges requests from a victim’s browser, and SQL injection abuses a database query, but each has its own trade-offs.

The table below sets out the main contrasts between the leading approaches.

Aspect SSRF XSS CSRF
Victim The server itself The user’s browser The user’s browser
Trigger A URL the server fetches A script in a page A forged request from a site
Goal Reach internal systems Steal sessions, deface Perform actions as the user
Fix Allow lists, no metadata access Output encoding, CSP Anti-CSRF tokens
Best known for Cloud metadata theft Stored scripts Forged state changes

The practical result is that SSRF is the attack to worry about wherever a server fetches user-supplied URLs, XSS is the worry wherever user input is shown to other users, and CSRF is the worry wherever a site changes state on a simple request.

Where SSRF is used

Cloud credential theft is the best-known use. An attacker who finds an SSRF in a cloud-hosted application points it at the metadata service, reads the server’s temporary credentials, and uses them to read storage, databases, and other cloud resources, which has caused some of the largest data breaches of recent years.

Internal network scanning is a common use. An attacker who can make a server fetch arbitrary addresses can probe the internal network port by port, learning which services exist and where they run, which turns a single vulnerability into a map of the whole private network.

Admin panel access is a frequent goal. Many organisations protect their admin panels by IP address, allowing only internal systems to reach them, and an SSRF lets an attacker reach them through the trusted server, bypassing a control that was never designed to face a request from inside.

Attacking other systems is a further use. A server tricked into fetching a URL can be made to send requests to a third-party system, which makes the attack look as if it came from the victim’s server, hiding the attacker’s identity and letting them abuse the victim’s reputation and bandwidth.

Bypassing firewalls is the underlying purpose. A firewall that blocks the internet from reaching internal systems does nothing against a request that originates inside, and SSRF is the technique that turns a public-facing server into an insider, which is why it is treated as a serious vulnerability wherever it is found.

Strengths and limits

From the attacker’s side, the greatest strength of SSRF is the trust it borrows. The server is already inside the network, already allowed to reach internal systems, and already holding credentials, so a single vulnerability can open the whole internal environment, without the attacker ever needing to breach the firewall directly.

It is also a strength, for the attacker, that SSRF is easy to miss. A feature that fetches a URL looks harmless, and the vulnerability hides in the gap between what the developer intended, fetching a public image, and what the server will actually do, fetching anything it is told to, which is why it appears in so many applications.

The limits are real, though. SSRF needs a feature that fetches user-supplied URLs, which not every application has, and a well-defended server, with allow lists, network segmentation, and metadata protection, can stop the attack cold. It is also a noisy attack, since the server’s requests are logged, which gives defenders a chance to spot it.

SSRF checklist

  • Allow list the destinations a server may fetch, and deny everything else.
  • Resolve and check the address after every redirect, not just once.
  • Block private and link-local addresses, including the metadata service.
  • Use the cloud provider’s metadata protection, such as token headers.
  • Segment the network, so a web server cannot reach admin panels.
  • Give the server the fewest credentials it needs to do its job.
  • Log outgoing fetches, and alert on requests to internal addresses.
  • Test URL parsing, since encoded and decimal addresses bypass naive checks.
  • Fix SSRF quickly when found, since it is often the first step in a breach.

Frequently asked questions

What is SSRF in simple terms?

SSRF is an attack in which a server is tricked into making a request chosen by an attacker. Because the server is trusted inside the network, it can reach internal systems the attacker cannot, and the attacker uses it to scan, steal, or attack from the inside.

What is the cloud metadata service?

It is a special internal address that a cloud server can query for its own temporary credentials and configuration. It is reachable only from inside the cloud, which is why an SSRF that reaches it is so valuable to an attacker.

What is a blind SSRF?

It is an SSRF where the application does not return the fetched content to the attacker. The attacker still learns from timing, error messages, or a DNS lookup the server makes, which can confirm that an internal address was reachable.

How is SSRF different from CSRF?

SSRF forges a request from the server, using the server’s trusted position, while CSRF forges a request from a victim’s browser, using the victim’s logged-in session. One attacks from the inside out, the other from the browser in.

What is an allow list in SSRF defence?

It is a list of the only destinations a server is permitted to fetch. Everything not on the list is refused, which is far safer than a deny list, since an attacker cannot find a destination the defender forgot to block.

How do I know if my application has SSRF?

Look for any feature where the server fetches a URL supplied by the user, such as image fetching, link previews, feed imports, or webhooks. Test each one with an internal address, and check whether the server fetches it.

The bottom line

SSRF explained in one line is this: a server tricked into fetching a URL chosen by an attacker, using its trusted position inside the network to reach systems no outsider could touch.

It is one of the most consequential web vulnerabilities, because it turns a single careless feature into a breach of the whole internal network, and it is stopped by the simple discipline of deciding in advance what a server is allowed to fetch.

This article is general information about how SSRF works, not advice about securing a particular application.

Latest articles

Scroll to Top