Skip to content
Tutorials Center
My learning

Topics

Lesson 27 of 38 ยท Integrity, Logging and SSRF

Server-Side Request Forgery (SSRF)

OWASP A10: how server-side request forgery lets users make your server call internal addresses, why cloud metadata endpoints are a target, and what the flaw looks like.

Many features make your server fetch a URL that a user supplies: importing an image from a link, generating a link preview, checking a webhook address, converting a web page to PDF. Server-Side Request Forgery (SSRF, A10) happens when the application fetches that URL without checking where it points. The user is no longer limited to what their browser can reach; they borrow the server's network position.

That position is powerful. A server often sits inside a private network with access to internal admin pages, databases, internal APIs and, in the cloud, the instance metadata service (a special internal address such as 169.254.169.254 that can hand out credentials). A request that would be blocked from the internet may succeed from the server itself.

This lesson explains the weakness so you can recognize and fix it. Do not probe systems you do not own or have written permission to test. The code uses only reserved example addresses and never makes network requests.

How the flaw looks

A vulnerable endpoint takes a URL and fetches it:

TEXT
GET /preview?url=https://example.org/article

The developer expects a public web page. A malicious user supplies something else:

TEXT
GET /preview?url=http://localhost:8080/admin
GET /preview?url=http://10.0.0.12/internal-report
GET /preview?url=http://169.254.169.254/latest/meta-data/

If the server fetches and returns the answer, the attacker reads internal content. Even when the response is blind (nothing is returned), timing or error differences can map the internal network, and some requests change state.

The request path

User Sends a URL parameter.
Your server Fetches it for them.
Internal network Not reachable from outside.
Cloud metadata Can expose credentials.

The server is the confused deputy.

1 / 2

Why naive filters fail

A first reaction is "block the words localhost and 127.0.0.1". Attackers (and mistakes) get around string checks in many ways:

  • Alternative address forms: decimal 2130706433, hex 0x7f000001, octal and short forms all mean 127.0.0.1; IPv6 ::1 and IPv4-mapped IPv6 addresses too.
  • DNS tricks: a public-looking domain that resolves to a private address, or a name that changes its answer between your check and the fetch (DNS rebinding).
  • Redirects: a public URL that answers 302 and points at an internal address. If your client follows redirects, it ends up inside.
  • URL parsing differences: http://[email protected]/ has a user-info part; different libraries disagree about the real host.
  • Other schemes: file://, gopher://, ftp:// may be handled by the client library.

String blocklists lose this race. The robust approach, covered in Defending Against SSRF, validates the resolved IP address and limits what is allowed in the first place.

Seeing the problem: many spellings, one address

The Python standard library will tell you how different spellings are interpreted. This is local parsing only; nothing is fetched.

Python Different spellings of the same address

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

A string search for 127.0.0.1 would miss four of those entries. The code that finally decides must work on the parsed address.

The naive filter versus reality

Python A naive blocklist is easy to bypass

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Three of the five dangerous URLs pass the naive check. That is the lesson: SSRF protection built on string matching fails.

Impact

Depending on the environment, SSRF leads to:

  • Reading internal services and admin panels.
  • Credential theft from cloud metadata services (a major factor in several large breaches).
  • Port scanning of internal hosts through response differences.
  • Reaching internal APIs that trust "internal" callers, which turns SSRF into remote actions.
  • In some cases code execution, through vulnerable internal services.

Is your app at risk?

Ask these questions about every feature that makes outbound requests:

  • Does a user supply the URL, host or part of it (including inside XML, JSON, headers or file names)?
  • Does the server follow redirects?
  • Does the response (or its content, status or timing) come back to the user?
  • Could the server reach internal hosts, databases, admin interfaces or a metadata endpoint?
  • Does the server run with broad network access and cloud credentials?

If you answer yes to the first and a couple of the others, assume SSRF is possible until proven otherwise.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. In SSRF, whose network position does the attacker effectively borrow?

    The server makes the request, so it can reach internal hosts the attacker cannot reach directly.
  2. 2. Why is the cloud metadata address such a common SSRF target?

    Metadata services expose instance information and sometimes access tokens, usable from the host itself.
  3. 3. Why does blocking the strings localhost and 127.0.0.1 not fix SSRF?

    Decimal, hex, IPv6 forms, DNS names and redirects all bypass substring checks.
  4. 4. Which feature is most likely to need an SSRF review?

    Any server-side fetch of a user-influenced destination is an SSRF candidate.

Summary

  • SSRF makes the server fetch an attacker-chosen destination, exposing internal systems and cloud metadata.
  • Features like previews, imports, webhooks and renderers are typical sources.
  • String blocklists fail because of address spellings, DNS, redirects and URL parsing quirks.
  • Review every outbound fetch that a user can influence.

Next: Defending Against SSRF