DOM-Based Open Redirect

Client-side JavaScript reads an attacker-controllable source (URL query, location.hash, postMessage, stored JSON) and assigns it to a navigation sink without validating the scheme or host — the redirect decision never reaches the server.

How it works

A DOM source flows to a navigation sink. Common sinks: location, location.href, location.assign(), location.replace(), window.open(), and <meta http-equiv=refresh>. The most common source is the URL (location.search, location.hash). Because the redirect is built in the browser, it is invisible to server-side Location-header filters and to WAFs that only see the first request (PortSwigger).

Textbook example — a “starts with https:” check that still allows a full external URL:

goto = location.hash.slice(1)
if (goto.startsWith('https:')) { location = goto; }
// https://innocent.com/example#https://attacker.com

(PortSwigger). The YesWeHack snippet series flags the same pattern (location.hash to navigation) as a standalone open-redirect bug (YesWeHack).

Why it escalates: scheme control

Controlling the destination often means controlling the scheme, and javascript: is a valid URL scheme to a browser — so a redirect sink becomes XSS: “I control the URL → I might control the scheme → javascript: = XSS” (Nitin Yadav). This is why redirect params (backURL, next, returnUrl, redirect) are prime XSS hunting ground:

  • Error-page backURL read straight into window.location.assign with no validation; the auto-submit of a same-origin “Reload” button turned it into one-click XSS and session theft behind Akamai (WAF bypassed by encoding javascript:) (IW).
  • Browser schemes beyond javascript: — Orange Tsai’s Edge full-chain treated a navigation primitive that could reach edge://, devtools:// and javascript: as “a stronger open redirect” that became UXSS when the navigation was browser-process-initiated (Orange Tsai).

Where to find it

  • Query/hash params fed to a redirect helper in JS bundles — grep for location.assign, location.replace, location.href =, window.open( taking a URL param (IW).
  • <meta http-equiv="refresh" content="0;URL=..."> built from HTML injection, usable even where <script> is blocked (Hunting with HTML).
  • iframe/top.window.location set cross-origin by a child document — SOP allows a child to set the parent’s location, enabling top-navigation redirect from embedded content (Hunting with HTML).
  • SSO/login redirect pages that reflect the query and auto-submit a form — Siemens Teamcenter CVE-2026-58113 reflected window.location.search into an auto-submitting form, firing zero-interaction XSS (Bishop Fox).
  • postMessage handlers and stored JSON that resolve to a redirect; often part of a longer gadget chain to leak a token off-origin (PortSwigger OAuth).

Defenses

  • Allowlist the destination as a relative path, or resolve against a fixed origin and reject anything whose resulting origin differs; never assign a raw source to a navigation sink.
  • Reject non-http(s) schemes explicitly before navigating (blocks javascript:, data:, custom schemes); a startsWith('https:')-style check is not scheme validation.
  • Trusted Types and a strict CSP (script-src without inline, plus restricting javascript: navigation) reduce the sink-to-XSS jump.
  • Encode/validate at the sink, not just the WAF — WAF scheme filters fall to encoding (Nitin Yadav).

Sources