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
backURLread straight intowindow.location.assignwith 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 encodingjavascript:) (IW). - Browser schemes beyond
javascript:— Orange Tsai’s Edge full-chain treated a navigation primitive that could reachedge://,devtools://andjavascript: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.locationset cross-origin by a child document — SOP allows a child to set the parent’slocation, 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.searchinto an auto-submitting form, firing zero-interaction XSS (Bishop Fox). postMessagehandlers 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 (blocksjavascript:,data:, custom schemes); astartsWith('https:')-style check is not scheme validation. - Trusted Types and a strict CSP (
script-srcwithout inline, plus restrictingjavascript:navigation) reduce the sink-to-XSS jump. - Encode/validate at the sink, not just the WAF — WAF scheme filters fall to encoding (Nitin Yadav).
Related
- Open Redirect (main guide)
- DOM-Based XSS · Cross-Site Scripting · Redirect Validation Bypasses · Open Redirect to OAuth Token Theft
Sources
- DOM-based vulnerabilities | Web Security Academy · original
- The WAF Blocked My XSS — So I Rotated What It Was Reading · original
- Chaining a DOM XSS Sink, WAF Bypass, Cross-Origin Smuggling, and SDK Abuse · original
- Hunting good bugs with only HTML · original
- Submit and Execute: Weaponizing Reflected XSS in Siemens Teamcenter's Login Redirect · original
- The Last Proof of Human Craft: Forging a Microsoft Edge Full Chain · original
- YesWeHack vulnerable code snippets · original
- PortSwigger: OAuth 2.0 authentication vulnerabilities · original