SSRF: the server fetches someone else's address
SSRF is when the server, on a user's orders, makes a request to an address the user supplied and reaches internal resources unreachable from outside. In the cloud the metadata service with the role's credentials becomes a target too. Defence: an allowlist of hosts checked on the parsed URL, no redirects, an IP check after name resolution, IMDSv2 and least-privilege roles.
Pentest · OWASP Top 10
A service downloads a picture by link. What if the link leads not to the internet but inside the network?
A profile form has a field "Import a photo by link". The user pastes an address, the server downloads the file and stores it. Instead of a picture the tester pastes the address of an internal panel that cannot be reached from outside and sees its page in the response. This is SSRF (Server-Side Request Forgery): the server makes a request on someone else's orders. The lesson explains why it is more dangerous than it looks, how to test it and why a simple address check does not save you.
How it works and why. The application server sits inside a trust zone: it sees internal services, admin panels, databases and, in the cloud, the instance metadata service. From outside they cannot be reached, but a request from the server itself is considered "ours". Any function that fetches an address given by the user (import by link, webhooks, link previews, PDF generation from a page, XML with external entities) hands this trust to an attacker. The cloud instance metadata service at 169.254.169.254 holds, among other things, temporary credentials of the role, so SSRF often turns into access to cloud resources. In the OWASP Top 10:2025 SSRF is treated under Broken Access Control (A01).
What happens
Example: from vulnerable code to a fix. A typical vulnerable handler trusts any address:
// "Import an image by link"
app.get('/import', async (req, res) => {
const r = await fetch(req.query.url);
res.send(await r.text());
});
In an allowed test (on your own environment or in a lab) you check whether the server goes to addresses the user should not reach: loopback (127.0.0.1), private ranges (10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16) and link-local 169.254.0.0/16, which includes the metadata address. A finding can also be "blind": the response does not come back, but the server made the request, and that is visible in a log or an external callback (for example Burp Collaborator). The fix starts with an allowlist:
const ALLOWED = new Set(['img.example']);
const u = new URL(req.query.url);
if (u.protocol !== 'https:' || !ALLOWED.has(u.hostname)) {
return res.status(400).end();
}
const r = await fetch(u, { redirect: 'error' });
Here the address is parsed, the scheme and the exact host name are checked, and redirects are disabled. Not startsWith on the string: the address https://img.example.attacker.test/ also starts with "https://img.example", and https://img.example@attacker.test/ leads to the host after the "@".
A real case: Capital One, 2019. According to the indictment, a misconfigured web application firewall (WAF) in the cloud allowed commands to run on a server, and they returned credentials of a role. According to Capital One, the incident affected about 100 million people in the US and six million in Canada. That it was a request to the metadata service follows from public technical analyses, not from the indictment. The lesson for QA: one role permission that is too broad turns a configuration mistake into a data leak.
Limits and alternatives. Blocklists ("we block 127.0.0.1") are unreliable and OWASP recommends allowlists. Bypasses come through other IP notations (hexadecimal, octal, decimal forms), IPv6 and IPv4-mapped addresses, a redirect from an allowed address to an internal one, DNS rebinding (the name first points to a legitimate IP and at the second resolution to an internal one) and differences between address parsers. If addresses are arbitrary (webhooks), private ranges are blocked after name resolution, every record is checked and the connection goes to the validated IP. Egress network restrictions work as an extra layer, and in AWS a move to IMDSv2 (a session token is required) makes plain SSRF harder to exploit. Blind SSRF, where the response does not come back, is still dangerous: it triggers actions on internal services (state changes, port scans).
Typical mistakes.
- Checking the address string and not the parsed URL: startsWith, contains, regular expressions.
- Checking the host name but connecting after a second resolution: DNS rebinding slips between the two steps.
- Allowing redirects: an allowed address leads to an internal one.
- Blocking only 127.0.0.1 and forgetting 169.254.169.254, private ranges and IPv6.
- Returning the raw response of an internal service to the user.
Check yourself
An "import by link" function checks that the address starts with "https://img.example". Which address do you try in the lab to show a bypass and why does it pass?
Answer
https://img.example.attacker.test/a.png or https://img.example@attacker.test/a.png. The string starts with the allowed prefix although the host is different. The fix: parse the URL and compare the exact host name with a list.
The response to a blind SSRF does not come back to the application. How do you prove that the server made a request?
Answer
Give an address controlled by the tester (Burp Collaborator or your own listener in the lab) and see the incoming request from the server, or find a trace in the log of the target internal service.