00->1
Learning pathStep 52 of 62Web application attacks and the OWASP Top 10 ← All writeups

Server-Side Request Forgery (SSRF), Explained

If you are reading this, you have probably seen "SSRF" in bug-bounty reports and cloud breach stories, and you want to understand how a server can be tricked into making requests for an attacker, why that is so dangerous, and what really stops it.

By the end you will be able to explain what SSRF is, name the features that cause it, describe the two classic targets (the server itself and internal systems) and the cloud metadata service, understand blind SSRF, see why simple filters fail, and apply the layered defences. SSRF was its own item (A10) in the 2021 OWASP Top 10 and is now part of A01 Broken Access Control in the 2025 edition; see the OWASP Top 10 overview. Everything here is for understanding and for practice on labs you own or are allowed to test.


1. What SSRF is

Many applications fetch a URL on behalf of a user. Examples:

Feature What the server does
Link preview (a chat app showing a title and picture) Fetches the page you pasted
Import by URL (profile picture, document, feed) Downloads the file from the address
Webhooks and callbacks Sends a request to an address you registered
Stock, price or API lookups Calls another service, sometimes with an address taken from the request
PDF or screenshot generators Loads a page and renders it
File parsers (for example XML) May fetch other files named inside the data

PortSwigger defines server-side request forgery as a web security vulnerability that allows an attacker to cause the server-side application to make requests to an unintended location.

Why it matters: the server's position

A request from the server is different from a request from a visitor, for two reasons:

  1. The server sits inside the organization's network, behind the firewall, where it can reach internal systems that the internet cannot.
  2. Other systems often trust the server and treat requests from it (or from localhost) as already approved.

So SSRF lets an attacker borrow the server's network position and trust. Compare CSRF, which borrows the browser's logged-in state.


2. The two classic targets

Against the server itself

PortSwigger's standard example is a shopping site that checks stock by asking another service. The browser sends a request with a parameter holding the address:

POST /product/stock
stockApi=http://stock.weliketoshop.net:8080/product/stock/check?productId=6&storeId=1

The server fetches that address and returns the result. An attacker changes the parameter to:

stockApi=http://localhost/admin

The server now makes a request to itself. Many applications have an administration interface that trusts local requests (for recovery, or because it assumes only trusted staff can reach it), so the page loads without any login. To the application, the request came from the server, not from a stranger.

Against other back-end systems

Organizations have internal systems with private addresses (for example in the ranges 10.x.x.x, 172.16.x.x–172.31.x.x and 192.168.x.x) that are not reachable from the internet. They are protected only by network position, so they often have weak or no authentication. The attacker supplies an address such as:

stockApi=http://192.168.0.68/admin

The vulnerable server can reach it, and relays the answer.


3. The code behind it

A vulnerable endpoint (Python, Flask):

import requests

@app.route("/fetch")
def fetch():
    url = request.args["url"]              # whatever the visitor sends
    r = requests.get(url, timeout=5)       # the server fetches it
    return r.content                       # and shows the result

Nothing limits where url points. This one function can be used to read internal pages, hit internal APIs and reach the cloud metadata address. The problem is the same pattern as every injection flaw: the application trusts input to decide where to connect.


4. The cloud metadata service

Cloud servers have a special internal address where they can ask for information about themselves. On Amazon Web Services (AWS), that is the instance metadata service, reachable at the link-local address 169.254.169.254. It can provide, among other things, temporary security credentials for the role attached to the instance. Other cloud providers have similar services.

For an attacker, the sequence is: find an SSRF, point it at the metadata address, read the temporary credentials, and then use them from outside to call cloud APIs with the server's permissions. What the attacker gets depends on how much power that role has, which is why over-privileged roles turn a small SSRF into a large breach.

AWS made the service harder to abuse with IMDSv2. Instead of answering a plain GET request, it first requires a PUT request to obtain a secret session token, and then requires that token as a header on later requests. AWS explains that this combination is more effective than requiring only a static header, and that it protects against most real SSRF flaws, which usually cannot make a PUT request or add arbitrary headers. AWS's documentation notes that, by default, both versions of the service can be used, and that you can configure an instance to require IMDSv2.

A real case: Capital One, 2019

Capital One reported in July 2019 that an outside security researcher had told it of a vulnerability on 17 July 2019 through its responsible disclosure programme, and that about 100 million individuals in the United States and 6 million in Canada were affected. Capital One's own notice calls the cause "a configuration vulnerability." The US Department of Justice, announcing the criminal complaint, said the intrusion occurred through a misconfigured web application firewall that enabled access to the data. Public technical analyses go further and describe the firewall being made to send requests to the AWS metadata service (an SSRF), which returned credentials for a role that could read stored data. Those mechanism details come from outside analyses rather than from the Justice Department statement, so treat them as reported, not official. The lesson holds either way: a misconfiguration, a request the server should not have made, and a role with more access than it needed all had to line up.


5. Blind SSRF

In a blind SSRF, the server makes the request but does not show the response to the attacker. PortSwigger describes these as flaws where the application can be induced to issue a back-end HTTP request to a supplied URL, but the response from that request is not returned.

They are harder to exploit, yet not harmless:

What an attacker can do How
Check whether the server can be steered Supply an address on a server they control and watch for a visit. Testers use out-of-band tools such as Burp Collaborator for this. A DNS lookup with no following HTTP request can mean outbound traffic is partly filtered. A visit alone is not yet a vulnerability (see below)
Map the internal network Try internal addresses and watch for differences in response time or behaviour
Attack unpatched internal systems Send payloads aimed at known vulnerabilities in back-end services
Attack the server's own software In some cases, achieve code execution through a malicious response

6. Why simple filters fail

Developers often try to block the dangerous addresses. PortSwigger shows why this is fragile.

Blocklists (deny the bad values such as 127.0.0.1 or localhost) can be bypassed with:

Trick Idea
Another way to write the same IP 127.0.0.1 can also be written as 2130706433 (decimal), in octal or in hexadecimal
A domain that resolves to the blocked IP An attacker registers a name whose DNS answer is 127.0.0.1
URL encoding Obfuscating characters so that the filter and the fetcher disagree
Redirects The allowed URL answers with "go to this other address", and the client follows it

Allowlists (permit only certain hosts) are stronger, but parsing differences still bite. The URL specification has features that confuse naive checks:

Trick Idea
@ in the address https://expected-host@evil.example/ has expected-host as a user name, not the host
# fragments Text after # is ignored by the server but may fool a check
DNS hierarchy expected-host.evil.example starts with the right words, but belongs to the attacker
Encoding confusion The check decodes the URL differently from the code that sends the request

A further trap is DNS rebinding: a name that resolves to a harmless address when your code checks it, and to an internal address a moment later when the request is actually made.


7. How to prevent SSRF

OWASP's SSRF Prevention Cheat Sheet separates two situations: the application only needs to talk to a known set of services (use an allowlist), or it must fetch arbitrary external URLs such as webhooks (an allowlist is impossible, so you need stronger layers).

Layer What to do
Do not take URLs from users if you can avoid it Let users pick an item from a list, and build the address on the server
Allowlist destinations Permit only the specific hosts, ports and protocols the feature needs. OWASP warns that deny-lists are bypass-prone and allow-lists should be preferred
Accept components, not whole URLs OWASP advises validating a hostname or IP and rebuilding the request yourself with a fixed scheme, port and path, since full URLs are hard to validate and parsers can be abused
Resolve DNS, then validate the result Look up the name, check that the resulting address is allowed (for external destinations: a public address, not private, loopback or link-local), and connect to that address so it cannot change between check and use
Restrict protocols Allow only http and https; do not follow file:, gopher: and other schemes
Turn off redirects OWASP: disable following redirects in the web client, which otherwise bypass the validation
Do not return raw responses Extract only what the feature needs, so attackers cannot read internal pages
Network controls (the strongest layer) Firewall rules and segmentation (see Network Defence) so the application server cannot reach internal admin systems or arbitrary addresses at all. OWASP highly recommends blocking illegitimate calls at the network level
Cloud: use IMDSv2 and disable IMDSv1 Makes metadata credentials much harder to steal through SSRF
Least privilege for roles and credentials If the server's role can only do a little, stolen credentials do little
Authenticate internal services Do not rely on "only the internal network can reach it"
Log and alert on unusual outbound requests Requests from a web server to internal ranges or the metadata address should be rare and alarming

A rule to remember: never rely on a single filter. Combine the allowlist in code with network rules and low-privilege credentials, so that a bug in one layer does not become a breach.


8. How testers find it

With permission:

  1. Find every feature that takes a URL, host or file location, including parameters named url, uri, dest, redirect, path, callback and webhook, and fetchers hidden in uploads and document formats.
  2. Point it at a server you control to see whether the application reaches out (the out-of-band method also finds blind cases). Treat a callback as a lead, not a finding: many features, such as webhooks, link previews and importers, are meant to fetch a URL the user supplies.
  3. Try internal targets such as localhost, private ranges and, in a lab cloud account, the metadata address.
  4. Compare responses (content, status, length, timing) to tell open from closed internal ports.
  5. Test the filters with alternative IP formats, redirects and the URL tricks above.
  6. Establish unintended access before reporting. PortSwigger's definition is a flaw that lets an attacker make the server send requests "to an unintended location." Show that the request reaches something it should not: an internal-only service, an address the feature is supposed to block, or data the attacker is not meant to get. A callback to your own server, by itself, shows only that the feature does what it was built to do.

Practise on PortSwigger Web Security Academy: SSRF, which has labs for the server itself, back-end systems, blocklist and allowlist bypasses, and blind SSRF.


9. Common mistakes

Myth The facts
"We block localhost and 127.0.0.1, so we are safe" Other spellings, DNS names and redirects bypass blocklists
"It only matters in the cloud" Internal admin panels and APIs are targets on any network. The cloud adds the metadata service and powerful credentials
"Blind SSRF is harmless" It still allows internal scanning and attacks on back-end systems
"We only fetch URLs from logged-in users" Any user, including a free account, can supply a URL
"Validation passed, so the fetch is safe" The address can change between validation and use (DNS rebinding), and redirects can move it
"Our internal systems are safe behind the firewall" SSRF turns your own server into the way through the firewall
"A WAF will catch it" Payloads can be disguised; fix the design and add network controls

Closing

SSRF is the flaw that lets someone else decide where your server connects. Because the server is trusted and sits inside the network, the attacker gets access to local admin pages, internal services and, in the cloud, the metadata service with its credentials. Filters that block particular addresses are routinely bypassed, so the defence is layered: avoid user-supplied URLs, allow only known destinations, validate the resolved address, switch off redirects, limit what the server can reach on the network, use IMDSv2, and give cloud roles only the access they need.

Keep these points:

  • SSRF = the server makes a request the attacker chose.
  • Targets: the server itself, internal systems, and the cloud metadata service.
  • Blind SSRF returns no response but still allows scanning and attacks.
  • Blocklists fail; use allowlists, resolve-then-validate, no redirects and network segmentation.
  • IMDSv2 and least-privilege roles limit the damage in the cloud.
  • Now part of A01 Broken Access Control in the OWASP Top 10:2025.