HackproofHacks
Web App Security 15 min read

Server-Side Request Forgery (SSRF): How It Works, Impact, and Prevention

A deep, practical guide to SSRF — how attackers trick a server into making requests on their behalf, why cloud environments make it so dangerous, and the layered defences that actually prevent it.

Hassan Ansari

Hassan Ansari

A code card showing an SSRF payload targeting the cloud metadata endpoint

Server-side request forgery (SSRF): the complete guide

Server-side request forgery went from a mid-tier vulnerability to a headline-grabbing one over the last few years, largely because of the cloud. It earned its own dedicated place in the OWASP Top 10 (OWASP documents the class in full on its SSRF page), and it has been the root cause of several of the largest data breaches on record.

This guide explains exactly how SSRF works, why cloud infrastructure makes it so severe, and the layered defences that genuinely stop it.


What is SSRF?

Most web applications make outbound requests as part of normal operation. They fetch an image from a URL you provide, generate a PDF from a link, deliver a webhook, or call a third-party API. In all of these, the server is the one making the network request.

SSRF happens when an attacker can control where that server-side request goes. Instead of the server fetching a legitimate resource, the attacker points it at something else: an internal system, a cloud metadata endpoint, another service on the private network.

The reason this is so powerful comes down to position and trust. The attacker, sitting on the public internet, cannot reach internal systems directly. Firewalls block them. But the server can reach them, because it lives inside the trusted network. By hijacking the destination of the server’s request, the attacker borrows the server’s privileged network position.

A simple example. An application lets you set a profile picture by URL:

POST /api/profile/avatar HTTP/1.1
Host: app.example
Content-Type: application/json

{"image_url": "https://cdn.example/pics/me.png"}

The server dutifully fetches that URL and stores the image. But what if the attacker sends this instead?

{"image_url": "http://169.254.169.254/latest/meta-data/"}

Now the server is making a request to the cloud metadata service on the attacker’s behalf. If the application returns any of that response, or even behaves differently based on it, the attacker has a foothold into the internal environment.


Why the cloud made SSRF critical

The single biggest reason SSRF became a top-tier vulnerability is the cloud instance metadata service.

Cloud providers give each virtual machine an internal endpoint (classically at the link-local address 169.254.169.254) that returns information about the instance: its configuration, its network, and, in many setups, temporary security credentials for the cloud role the machine is running as.

This is by design and is normally safe: only code running on the instance can reach that address. But SSRF breaks that assumption. If an attacker can make a vulnerable application on that instance request the metadata endpoint, they can potentially retrieve those temporary credentials, then use them to access cloud storage buckets, databases, and anything else the instance’s role is permitted to touch.

This exact pattern (SSRF reaching the metadata service to steal cloud credentials) was a central element of several major breaches, including large incidents affecting financial and technology companies. It’s why cloud providers introduced hardened metadata schemes (such as AWS’s IMDSv2, which requires a session token and blocks naive SSRF), and why locking down that endpoint is now a baseline control.


What an attacker can do with SSRF

The impact of SSRF ranges from information disclosure to full compromise, depending on what the server can reach:

  • Steal cloud credentials from the metadata service, leading to broad cloud account access.
  • Access internal services: admin panels, databases, message queues, and internal APIs that were “protected” only by not being reachable from the internet.
  • Scan the internal network. By observing response times and errors, an attacker can map which internal hosts and ports are alive, using the server as a proxy.
  • Reach non-HTTP services. With certain URL schemes, SSRF can interact with services that never expected untrusted input, sometimes escalating toward remote code execution.
  • Bypass access controls. Internal endpoints often trust requests coming from inside the network and skip authentication, exactly the trust SSRF exploits.

Because the server frequently sits at a trusted crossroads inside the infrastructure, a single SSRF can unlock a great deal.


In-band vs blind SSRF

SSRF comes in two flavours based on whether the attacker can see the result.

In-band (basic) SSRF returns the response of the forced request to the attacker within the application. If the avatar-fetching feature above displays or leaks the fetched content, the attacker reads internal responses directly. This is the easiest to exploit and confirm.

Blind SSRF makes the server send the request, but the response is never shown to the attacker. It’s harder to exploit but far from harmless. Testers confirm blind SSRF using an out-of-band technique: they point the server at a system they control and watch for the incoming connection. Even without reading responses, blind SSRF can map internal networks by timing, trigger state-changing internal endpoints, and serve as a component in a larger chain.


Where SSRF hides

When testing an application, always within authorised scope, look anywhere the server fetches a URL you influence:

  • Webhooks: “send events to this URL” is a direct invitation.
  • Import from URL: importing data, documents, or feeds from a supplied link.
  • URL preview generators: features that fetch a link to show a title and thumbnail.
  • PDF, screenshot, and document generators: these render a supplied URL server-side and are notorious SSRF sinks.
  • Image and file fetchers: avatar-by-URL, remote file processing, media proxies.
  • Third-party API integrations where you supply the endpoint.

If your input becomes a destination the server visits, test it carefully. For API-heavy applications, pair this with the methodology in the API security testing guide.


How to prevent SSRF: defence in depth

SSRF is stubborn because naive filters are easy to bypass: alternate IP encodings, redirects, DNS rebinding, and unusual URL schemes all work around them. Effective prevention layers several controls.

1. Enforce a strict allowlist

The strongest defence is to not accept arbitrary destinations at all. If your feature only ever needs to reach a handful of known domains, allow exactly those and reject everything else. Allowlisting is far more robust than trying to blocklist every dangerous address, because you don’t have to anticipate every trick. Anything not explicitly approved is denied.

2. Validate the resolved destination, not just the string

Attackers bypass string checks with redirects and DNS rebinding: a hostname that passes validation but resolves to an internal address a moment later. Validate the destination after DNS resolution, verify the resolved IP is in your allowlist, and be wary of following redirects to new hosts without re-validating.

3. Block internal and reserved IP ranges

Reject requests whose resolved address falls in private or reserved ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16, loopback 127.0.0.0/8, and, most importantly, the link-local 169.254.0.0/16 range that includes the metadata endpoint. (This site’s own subdomain finder applies exactly this kind of IP guard on any URL it resolves, precisely to avoid becoming an SSRF vector.)

4. Disable unused URL schemes

If your feature only needs http and https, reject everything else. Schemes like file://, gopher://, dict://, and ftp:// are common escalation vectors and are almost never legitimately needed.

5. Harden the cloud metadata service

Enforce the hardened metadata scheme your provider offers, for example require IMDSv2 on AWS so that a simple SSRF can’t read the metadata endpoint. Apply least-privilege to the instance’s cloud role so that even stolen credentials are limited.

6. Segment the network

As a final layer, restrict what the application server is allowed to reach at the network level. If the server has no route to sensitive internal systems in the first place, an SSRF has far less to work with. Defence in depth means assuming one layer will fail and making sure the next one holds.


Key takeaways

  • SSRF lets an attacker make a server send requests to destinations they choose, borrowing the server’s trusted internal position.
  • The cloud metadata service turned SSRF into a critical vulnerability capable of yielding cloud credentials and major breaches.
  • It hides anywhere the server fetches a user-supplied URL: webhooks, importers, PDF generators, image fetchers.
  • Prevention is layered: strict allowlisting, validating the resolved destination, blocking internal IP ranges, disabling unused schemes, hardening metadata, and network segmentation.

SSRF rewards attackers who understand networks and defenders who assume their internal systems are reachable. Treat every “fetch this URL for me” feature as a place where that assumption gets tested.

The OWASP SSRF Prevention Cheat Sheet covers allowlisting and network-layer controls in implementation detail, and PortSwigger’s free SSRF labs cover the cloud metadata and filter-bypass cases hands-on. Note that RFC 1918 defines the private address ranges your allowlist has to account for.

Continue learning with the OWASP Top 10 breakdown, test real header and TLS posture with our free security tools, or build these skills directly through hands-on training.

#SSRF #server-side request forgery #web security #OWASP #cloud security #vulnerability
Free newsletter

Liked this? I write one like it every week.

One practical security lesson in your inbox each week, explained the same simple way. Join 10,000+ readers. Unsubscribe anytime.

From the article

Need a security assessment?

HackproofHacks provides web application and API penetration testing — using the same techniques covered in this article, with your explicit authorisation.

Book a free scoping call

More on Web App Security.

All articles →
FAQ

Questions about this topic.

What is SSRF (server-side request forgery) in simple terms?

SSRF is a vulnerability where an attacker tricks a server into making network requests to destinations the attacker chooses. Think of it like sending a letter to a company's mailroom and convincing the clerk to walk into restricted internal offices and bring you back whatever is there. The attacker can't reach those internal systems directly, but the server can — so by controlling where the server sends its request, the attacker borrows the server's trusted position inside the network to reach things they should never be able to touch.

Why is SSRF especially dangerous in cloud environments?

Cloud platforms expose a special internal metadata service — reachable at an address like 169.254.169.254 — that returns configuration data and, in some setups, temporary credentials for the machine's cloud role. A server is allowed to query it; an outside attacker is not. If an attacker can force a vulnerable server to request that metadata endpoint via SSRF, they may retrieve credentials that grant access to cloud storage, databases, and other resources. This turned SSRF from a moderate bug into one of the most impactful web vulnerabilities, and it contributed to several large, well-known cloud breaches.

What is the difference between SSRF and CSRF?

They sound similar but target opposite sides. CSRF (cross-site request forgery) abuses a victim's browser to send unwanted requests to a site where the victim is logged in — it operates client-side. SSRF abuses the server, forcing it to send requests to destinations the attacker picks — it operates server-side. SSRF is generally more dangerous because the server often sits inside a trusted network with access to internal services, cloud metadata, and databases that a browser could never reach.

What is blind SSRF?

Blind SSRF is a variant where the attacker can make the server send a request but cannot see the response in the application's output. It's harder to exploit but still dangerous. Testers confirm it by pointing the server at a system they control — an 'out-of-band' collaborator server — and watching for the incoming request. Even without reading responses, blind SSRF can be used to map internal networks, hit internal endpoints that trigger actions, or, in chained attacks, still reach sensitive services.

How do you prevent SSRF attacks?

The strongest defence is a strict allowlist: only permit the server to make outbound requests to a small, explicitly approved set of domains or IP addresses, and reject everything else. Validate the destination after resolving DNS, not just the raw string, to defeat tricks and DNS rebinding. Block requests to internal and reserved IP ranges (including link-local addresses like 169.254.169.254), disable unused URL schemes such as file:// and gopher://, and lock down the cloud metadata service (for example, enforce IMDSv2 on AWS). Network segmentation that limits what the server can reach is a valuable additional layer.

Where does SSRF usually hide in an application?

Anywhere the application fetches a URL on the user's behalf. Common hotspots include webhook configuration, 'import from URL' features, URL preview generators, PDF and screenshot generators that render a supplied link, image or file fetchers, and integrations that call third-party APIs using a user-supplied endpoint. Any feature where you hand the application a URL and it goes and retrieves something is a place to test carefully for SSRF.