← All tracks
Server-SideSSRF10 labsIntermediate7h practice

SSRF: The Server Has a Second Identity

Any server-side fetch is a request from the server's network position.

“The image preview fetched a URL. The server had a second identity: localhost.”

CWE-918OWASP Top 10 A10:2021OWASP ASVS 12.6.1
The mental model
You are not asking the server to show you a URL. You are asking the server to make a request from where it stands, with its network access and its trust.

The application accepts a URL and fetches it without restricting the destination. Loopback, link-local metadata, internal services and redirects are all reachable from the server even when your browser cannot reach them.

We think the URL is content. The server treats it as a destination. The attacker borrows the server's legs.

Threat model

What is actually at stake?

Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.

Assets

  • Cloud metadata credentials
  • Internal admin APIs
  • Service discovery and databases
  • Webhook and image-fetching workers

Actors

  • User who controls a URL, webhook or import source
  • Attacker with an SSRF-prone integration
  • Malicious document or profile image

Trust boundaries

  • Application network to internal network
  • Worker to metadata endpoint
  • URL allowlist to DNS resolution
  • Redirect target to original validation

Abuse cases

  • Fetch http://127.0.0.1:3000/internal
  • Read cloud metadata credentials
  • Use a public URL that redirects to an internal host
  • Use DNS rebinding to change the resolved IP
  • Reach an internal admin API with a POST
PrerequisitesHow server-side HTTP clients workPrivate IP ranges and loopbackDNS resolution and redirects
Request anatomy

Follow the decision, not the payload

Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.

  1. 01

    Accept URL

    A feature accepts a webhook, image, import, preview or callback URL.

  2. 02

    Validate

    The handler may check the string, scheme or hostname, but not the final destination.

  3. 03

    Resolve

    DNS returns an address, which may be loopback, private, link-local or a metadata service.

  4. 04

    Connect

    The server opens the connection from a trusted network position and may follow redirects.

  5. 05

    Return or act

    The response is shown, stored or used to make a second request, turning reachability into disclosure or action.

Case study

Capital One cloud metadata breach, 2019

Capital One, 2019, public reporting
Context

A misconfigured web application firewall in front of cloud storage allowed a request to reach the instance metadata service and obtain credentials.

Discovery

The attacker used the SSRF primitive to query the metadata endpoint, obtained a role credential, then used it to list and download storage objects.

Impact

Public reporting described data for about 100 million customers exposed, one of the defining cloud-era SSRF incidents.

Root cause

The application had excessive network reach, the metadata service was reachable without strong session controls, and the role permissions were broader than necessary.

Fix

Enforce IMDSv2, block metadata and private ranges at the network layer, use egress allowlists, scope instance roles tightly, and validate the final resolved destination.

Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.

Attacker lens

A repeatable testing sequence

  1. Find URL, image, webhook, PDF, RSS, preview and health-check features.
  2. Test external URLs, loopback, `127.0.0.1`, `localhost`, `[::1]`, decimal IPs and redirects.
  3. Look for a response difference: status, timing, body, error.
  4. Target an internal endpoint that returns a secret only to loopback.

Where smart people get fooled

  • Blocking the string `localhost` does not block `127.0.0.1` or alternate encodings.
  • Only allowing http does not prevent internal http.
  • Following redirects can turn an allowed URL into a forbidden destination.
Detection engineering

What would the logs show?

A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.

  • Server-side requests to loopback, private, link-local or metadata addresses
  • Webhook or image fetches that resolve to internal hostnames
  • URLs containing 169.254.169.254, localhost, 127.0.0.1 or internal ports
  • Redirect chains from public hosts to private destinations
  • A worker making requests to many hosts or unusual ports
Starter query
index=proxy sourcetype=egress | eval internal=if(match(dest_ip,"^(10\.|172\.(1[6-9]|2[0-9]|3[01])\.|192\.168\.|127\.|169\.254\.)"),1,0) | where internal=1 | stats count values(dest_ip) values(url) by src_host, user_id | where count > 0
The defender's move

Fix the decision, then prove it stays fixed

  • Allowlist destinations and resolve DNS before connecting; block link-local and metadata ranges.
  • Use a dedicated egress proxy with no access to internal networks.
  • Do not return raw internal responses to the user.
Vulnerable patterntypescript
const response = await fetch(req.body.webhookUrl);
return Response.json(await response.json());
Safer patterntypescript
const url = new URL(req.body.webhookUrl);
if (url.protocol !== "https:" || !allowedHosts.has(url.hostname)) throw new Error("blocked");
const addresses = await dns.resolve4(url.hostname);
if (addresses.some(isPrivateAddress)) throw new Error("blocked");
const response = await fetch(url, { redirect: "manual", signal: AbortSignal.timeout(3000) });
assertPublicResponse(await response.text());

Validate the hostname, resolve it yourself, reject private addresses, disable redirects, cap time and size, and enforce egress rules at the network layer as the final control.

Regression tests a reviewer would ask for

Loopback

GivenA feature fetches a user-supplied URL

WhenThe URL points to 127.0.0.1 or localhost

ThenThe request is blocked before connection

Metadata

GivenThe service runs in a cloud network

WhenThe URL targets the metadata address

ThenNetwork policy and application validation both deny it

Redirect

GivenAn allowed public URL returns a 302 to an internal host

WhenThe fetcher follows redirects

ThenThe redirect is not followed or the final host is revalidated

DNS rebinding

GivenA hostname resolves to a public address at validation and a private one at connection

WhenThe request is made

ThenThe connection is pinned to the validated address or rechecked at connect time

False positives

What this finding is not

Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.

  • A URL returns a connection error: try another port, scheme or redirect path; the failure may be a firewall, not a control.
  • The response is blank but the request took longer: use an out-of-band callback or timing to confirm reachability.
  • Only HTTPS is allowed: test redirects from an allowed HTTPS host to an internal target.
  • The hostname is public: DNS rebinding can change the address after validation.
Working vocabulary

Terms you should be able to use precisely

SSRF
Server-side request forgery: influencing a server to make a request to an unintended destination.
Metadata service
A cloud endpoint that exposes instance identity and temporary credentials.
DNS rebinding
Changing a hostname's resolved address between validation and connection.
Egress allowlist
A network policy that permits outbound traffic only to approved destinations.
IMDSv2
A session-token-based metadata service intended to resist simple SSRF.
Blind SSRF
SSRF where the response is not returned, confirmed through timing or callbacks.
Interview drill

Answer these without reciting a payload

Why is validating the URL string not enough?

DNS can resolve to a private address, redirects can change the destination, and alternate IP encodings can bypass string checks. Validate the resolved address and enforce network egress.

What is the strongest control against metadata theft?

Network-level denial of the metadata endpoint plus IMDSv2 and least-privilege instance roles. Application validation alone is not a reliable boundary.

How do you test blind SSRF?

Use a controlled callback endpoint and observe DNS or HTTP interaction. Then test redirects, alternate schemes and internal ports without causing harm.

Knowledge check

Can you separate the mechanism from the payload?

Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.

4 questions
01A webhook tester fetches http://169.254.169.254/latest/meta-data/. What is the primary risk?
02Which validation is strongest?
03Why can a redirect bypass a hostname allowlist?
04What is DNS rebinding?
الخلاصة الموسّعة
لماذا هذا مهم؟

SSRF تعني أن الخادم أصبح وكيلًا لك: أنت لا تطلب العنوان المستهدف، بل تجعل خادمًا يثق به يفعل ذلك من داخل الشبكة.

الخطر الأكبر في السحابة هو خدمة البيانات الوصفية، لكنه يمتد إلى أي API داخلي. لا تكتفِ بفحص النص؛ حلّل الاسم، ارفض العناوين الخاصة، لا تتبع التحويلات، وثبّت العنوان الذي تحققت منه. والأهم أن تمنع الخروج على مستوى الشبكة، لأن التطبيق وحده قد يُخدع.

What can the server reach that your browser cannot?