# 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 ([[raw/portswigger.net/dom-based-vulnerabilities-web-security-academy-5051|PortSwigger]]).
Textbook example — a "starts with https:" check that still allows a full external URL:
```js
goto = location.hash.slice(1)
if (goto.startsWith('https:')) { location = goto; }
// https://innocent.com/example#https://attacker.com
```
([[raw/portswigger.net/dom-based-vulnerabilities-web-security-academy-5051|PortSwigger]]). The YesWeHack snippet series flags the same pattern (`location.hash` to navigation) as a standalone open-redirect bug ([[raw/github.com/yeswehack-vulnerable-code-snippets-twitter-vulnerable-snippets-1498|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"* ([[raw/infosecwriteups.com/the-waf-blocked-my-xss-so-i-rotated-what-it-was-reading-11713|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:`) ([[raw/infosecwriteups.com/chaining-a-dom-xss-sink-waf-bypass-cross-origin-smuggling-and-sdk-abus-10213|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 ([[raw/blog.orange.tw/the-last-proof-of-human-craft-forging-a-microsoft-edge-full-chain-with-12423|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 ([[raw/infosecwriteups.com/chaining-a-dom-xss-sink-waf-bypass-cross-origin-smuggling-and-sdk-abus-10213|IW]]).
- `<meta http-equiv="refresh" content="0;URL=...">` built from HTML injection, usable even where `<script>` is blocked ([[raw/medium.com/hunting-good-bugs-with-only-html-1003|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 ([[raw/medium.com/hunting-good-bugs-with-only-html-1003|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 ([[raw/bishopfox.com/submit-and-execute-weaponizing-reflected-xss-in-siemens-teamcenter-s-l-12267|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 ([[raw/portswigger.net/portswigger-oauth-2-0-authentication-vulnerabilities-3899|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 ([[raw/infosecwriteups.com/the-waf-blocked-my-xss-so-i-rotated-what-it-was-reading-11713|Nitin Yadav]]).
## Related
- [[Open Redirect]] (main guide)
- [[DOM-Based XSS]] · [[Cross-Site Scripting]] · [[Redirect Validation Bypasses]] · [[Open Redirect to OAuth Token Theft]]
## Sources
- [[raw/portswigger.net/dom-based-vulnerabilities-web-security-academy-5051|DOM-based vulnerabilities | Web Security Academy]]
- [[raw/infosecwriteups.com/the-waf-blocked-my-xss-so-i-rotated-what-it-was-reading-11713|The WAF Blocked My XSS — So I Rotated What It Was Reading]]
- [[raw/infosecwriteups.com/chaining-a-dom-xss-sink-waf-bypass-cross-origin-smuggling-and-sdk-abus-10213|Chaining a DOM XSS Sink, WAF Bypass, Cross-Origin Smuggling, and SDK Abuse]]
- [[raw/medium.com/hunting-good-bugs-with-only-html-1003|Hunting good bugs with only HTML]]
- [[raw/bishopfox.com/submit-and-execute-weaponizing-reflected-xss-in-siemens-teamcenter-s-l-12267|Submit and Execute: Weaponizing Reflected XSS in Siemens Teamcenter's Login Redirect]]
- [[raw/blog.orange.tw/the-last-proof-of-human-craft-forging-a-microsoft-edge-full-chain-with-12423|The Last Proof of Human Craft: Forging a Microsoft Edge Full Chain]]
- [[raw/github.com/yeswehack-vulnerable-code-snippets-twitter-vulnerable-snippets-1498|YesWeHack vulnerable code snippets]]
- [[raw/portswigger.net/portswigger-oauth-2-0-authentication-vulnerabilities-3899|PortSwigger: OAuth 2.0 authentication vulnerabilities]]