SSRF Lab: Beat the URL Allowlist With a Redirect

✨ AI Summary
PreviewBot only accepts URLs on an allowlist — example.com, wikipedia.org, a couple of others. That feels safe. But it checks the URL you submit, then follows whatever redirects that URL returns, without checking again. Point an allowed host at a redirect, and the fetcher walks straight to the internal network.
Lab at a glance: Advanced · 110 XP · about 20 minutes · runs in your browser, no signup or setup. Try it yourself first; the full solution is behind a spoiler below.

What this lab teaches

Server-Side Request Forgery tricks a server into making requests on the attacker's behalf, often to internal systems the attacker cannot reach directly. An allowlist is a common defence — but if the fetcher validates the first URL and then blindly follows redirects, the allowlist only guards the front door.

The lesson: validation and the actual request must apply to every hop, not just the URL the user typed.

How PreviewBot fetches a URL

PreviewBot checks that your submitted URL is on the allowlist, then fetches it following HTTP redirects. If an allowed (or attacker-controlled) URL responds with a redirect to an internal address, the fetcher follows it — and the internal metadata endpoint, normally unreachable, answers.

The attack approach

  • Confirm the allowlist blocks direct internal URLs but the fetcher follows redirects.
  • Set up (or use) a URL that passes the allowlist check yet responds with a redirect.
  • Point that redirect at the internal metadata endpoint the lab protects.
  • Submit the allowed URL; the fetcher follows the redirect and returns the internal content.

Full walkthrough (spoiler)

If the fetch stays on the allowed host, the redirect is not being followed the way you expect — open the steps.

Show the step-by-step solution
  1. Give PreviewBot a URL that satisfies the allowlist but is under your control or known to redirect.
  2. Have that URL issue an HTTP redirect to the internal metadata endpoint.
  3. PreviewBot validates the original (allowed) URL, then follows the redirect without re-validating the destination.
  4. The internal endpoint responds and its content comes back through the preview. The lab detects the internal fetch and marks you solved.

Why it works

The allowlist check runs once, against the URL you submit. The HTTP client then follows redirects as a convenience, and nothing re-checks each new location. So an allowed URL becomes a springboard: the first hop passes, and the redirect carries the request somewhere the allowlist would have blocked.

Core principleRe-validate every redirect hop against the allowlist, or disable redirect-following entirely for server-side fetches.

Where this happens in the real world

Redirect-based allowlist bypass is a standard SSRF escalation, and SSRF itself reached the OWASP Top 10 as its own category (A10, 2021). The 2019 Capital One breach was an SSRF against a cloud metadata endpoint that exposed data on roughly 100 million people — a reminder of what an internal fetch can reach.

How to defend against it

  • Re-validate the destination on every redirect, or turn off automatic redirect-following for server-side requests.
  • Resolve the hostname and block private, loopback and link-local ranges at request time, not just by string.
  • Require IMDSv2 and hardened metadata settings so a reachable metadata endpoint still resists abuse.
  • Egress-filter the fetcher so it can only reach the specific external hosts it truly needs.
Mr Elite tip: When testing a URL fetcher you are authorised to assess, point an allowed URL at a redirect you control and watch where the server actually ends up. Validating only the first URL is the classic gap.

Try it, then go further

Reading about it is the easy part. Open the lab, try your own approach before peeking at the spoiler, and see how many attempts it takes.

❓ Frequently asked questions

What is SSRF?
Server-Side Request Forgery — making a server fetch a URL of the attacker's choosing, often to reach internal systems or cloud metadata the attacker could not reach directly.
Why doesn't the allowlist stop it?
Because the allowlist checks only the URL you submit. If the fetcher then follows redirects without re-checking, an allowed URL can redirect to a blocked internal address.
How do I fix redirect-based SSRF?
Re-validate every redirect hop against the allowlist (or disable redirect-following), and block private/loopback/link-local ranges after resolving the host.
Is cloud metadata really a target?
Yes. The 2019 Capital One breach used SSRF to read a cloud metadata endpoint. Requiring IMDSv2 and restricting egress sharply reduces the risk.
⚡
Join free to earn XP for reading this article Track your progress, build streaks and compete on the leaderboard.
Join Free
Lokesh N. Singh aka Mr Elite
Lokesh N. Singh aka Mr Elite
Founder, Securityelites · AI Red Team Educator
Founder of Securityelites and creator of the SE-ARTCP credential. Working penetration tester focused on AI red team, prompt injection research, and LLM security education.
About Lokesh ->

Leave a Comment

Your email address will not be published. Required fields are marked *