Skip to content

Security · 5 of 6

The server tricked into fetching

Step 1 · The pattern

Paste a link, get a preview

A user posts a link; the preview service fetches the page and returns a title and image. It fetches whatever URL it is given. (All numbers are illustrative.)

  • a link
  • preview built

In short

The server tricked into fetching: how it works and how it breaks

Plenty of features fetch a URL the user supplies: link previews, webhooks, 'import from URL', PDF renderers. The request comes from your server, inside your network, so it can reach addresses the internet cannot: internal admin pages, databases, and the cloud's instance metadata service, which hands the server temporary credentials for its role. Server-side request forgery (SSRF) is asking your server to fetch one of those for you. On a cloud server, one forged request can return keys that read everything the role can read. The defences stack: resolve the hostname once and refuse private, loopback and link-local addresses (and re-check every redirect); send user-driven fetches through an egress proxy that can only reach the internet; require a session token for the metadata service, as AWS's IMDSv2 does, so a simple forged GET gets nothing; and give each server's role only the access it needs.

What this simulation simplifies

  • The attacker's request goes straight through; real attacks often chain redirects or alternative address spellings.
  • Blind SSRF, where the response is never shown, is not animated.

How this comes up in interviews

"Design a 'fetch this URL' feature (webhooks, previews) safely."

Then they ask

  1. What about redirects?
  2. How do you handle DNS rebinding?
  3. What if a credential leaks anyway?

A strong answer covers

  • Allow-list schemes and ports; resolve once, refuse private, loopback and link-local ranges.
  • Re-validate every redirect, or do not follow redirects.
  • Run fetches through an egress proxy with no route to internal networks.
  • Require IMDSv2 (session tokens) for the metadata service.
  • Least-privilege roles and alerts on unusual use of them.

Points to cover, not a script. Say them in your own words and tie them to a system you have worked on.

On one page: the track cheat sheet.

Last reviewed: Official documentation

Diagrams are our own simulations: the timings, rates and counts in them are illustrative, not measurements. Captions are original wording.