---
name: sh-kb-open-redirect
description: "Knowledge base for finding open/unvalidated redirects - user-controlled redirect targets that send victims to attacker sites, enabling phishing, token leakage, and OAuth/SSO abuse. Use when hunting open redirects. CWE-601, OWASP A01:2021-Broken Access Control."
---
# Open Redirect - Hunter Knowledge Base
The app redirects to a URL taken from user input without restricting the destination. On its own it's a
phishing/trust-abuse issue; chained (OAuth `redirect_uri`, token in URL, SSO), it can leak credentials or
tokens.
## When to hunt this
Login/logout `?next=`/`?return_to=`/`?redirect=`/`?url=` params, post-action redirects, OAuth/OIDC
`redirect_uri`, SSO relay-state, "continue to" links, URL shorteners/proxies, `Location` set from input.
## Sinks (grep targets)
- **Python**: `redirect(request.args.get(...))`, Flask `redirect(url)`, Django `HttpResponseRedirect(user)`,
`return redirect(next)`.
- **JS/TS**: `res.redirect(userUrl)`, `window.location = user`, `location.href = user`, `location.assign`,
Next.js `redirect(user)`.
- **Java**: `response.sendRedirect(user)`, Spring `"redirect:" + user`, `RedirectView`.
- **PHP**: `header("Location: " . $user)`. **Go**: `http.Redirect(w, r, userURL, ...)`.
- **C#/ASP.NET**: `Redirect(returnUrl)` without `Url.IsLocalUrl`/`LocalRedirect`, `Response.Redirect(user)`.
**Rails**: `redirect_to params[:url]`, `redirect_back` with a `Referer`-derived target; Rails 7 can raise on
external hosts (`raise_on_open_redirects`, default with `load_defaults 7.0`) unless `allow_other_host: true`.
**Laravel**: `redirect($request->input('next'))`, `redirect()->away($user)`, `Redirect::to($user)`.
**FastAPI/Starlette**: `RedirectResponse(url=user)`. **Nest**: `@Redirect()` with a returned `{url: user}`.
- **Non-header redirects**: ``, `Refresh:` header, client-side
`router.push(user)`/`navigate(user)`, `window.open(user)`, `document.location`, `` on a "continue"
page, `target` fields in JSON that the front end follows, JS reading `URLSearchParams`/`location.hash` then
assigning to `location`.
- **Set headers by other means**: `Location` or `Refresh` headers built from `Host`/`X-Forwarded-Host`/`Referer`
(redirect-to-self that trusts the Host header), framework "append slash" or "force HTTPS" redirects that echo a
request-supplied host, reverse-proxy rewrite rules (`return 302 $arg_url`, `RewriteRule ... %{QUERY_STRING}`).
- Grep: `sendRedirect|res.redirect|HttpResponseRedirect|\bredirect\(|Location:\s|location.href|window.location`.
Add: `redirect_to|RedirectResponse|redirect\(\)->away|IsLocalUrl|http-equiv|router\.(push|replace)|returnUrl|
return_to|RelayState|continue=|callback=|dest(ination)?=|go=|goto=`.
## Detection recipe
1. `graft grep "redirect\(|sendRedirect|HttpResponseRedirect|Location:|location.(href|assign)" --json`.
2. Trace the redirect target to user input.
3. Also check the parameters' **sources**: query, form, JSON body, cookie (stored `next`), `Referer`, state/
RelayState/`state` blobs that carry a return URL, and values saved earlier (stored in the session or DB, then used
on a later redirect: second-order). A login `next` that survives a redirect round trip is a classic source.
4. Check for a validity check: is the target constrained to a relative path or an allowlisted host? Naive
checks (`startswith("/")`, `contains("mysite.com")`) are often bypassable.
5. Read the validator itself and look for these typical incomplete fixes: check done on the raw string and
the redirect on a decoded or normalized one (or vice versa); allow-list by `startswith`, `endswith`, `in`, or
regex with unescaped dots or no anchors (`mysite.com.evil.com`, `evilmysite.com`, `mysite.com@evil.com`); parsing
with one URL parser and redirecting with another (backslash, tab/newline, extra slashes, userinfo, port
confusion); blocking `http://` but not `//`, `/\`, `\\`, or `javascript:`/`data:`; validating only on the login
route and not on logout, register, OAuth callback, or error pages; only the host checked while the scheme is
left open; a relative-path check that still allows `/path/../..//evil.com` after the browser normalizes.
6. For OAuth/OIDC/SAML, look at the server side: `redirect_uri` compared by prefix, substring, wildcard, or
regex; allowed list includes a domain with an open redirect or user-controlled content; `RelayState` and
`post_logout_redirect_uri` unchecked; `state`/`next` echoed in an error redirect.
## Variant hunting
Once one redirect is found: grep every other call to the same helper (`safe_redirect`, `redirect_back`, `get_next`,
`return_to` utilities) and every other parameter name in the app that carries a URL; check sibling flows (login,
logout, signup, password reset, email confirm, SSO callback, language/theme switcher, link shorteners, click
trackers, payment return, error pages) and API-versus-web twins; check copy-pasted validators for the weaker
copy; check every `Location`-building proxy/CDN rule. Also check whether a found redirect is usable as an `ssrf`
bypass or OAuth `redirect_uri` hop, which raises its severity.
## Payloads / PoC
- `?next=https://evil.com`, `?url=//evil.com` (scheme-relative), `?url=https:evil.com`,
`?next=/\evil.com`, `?url=https://mysite.com.evil.com`, `?url=https://mysite.com@evil.com`,
backslash/whitespace/CRLF tricks, `?url=javascript:alert(1)` (if it reaches a DOM sink).
- Bypass of `startswith("/")`: `//evil.com`, `/\evil.com`, `/%2f%2fevil.com`.
- PoC: request the endpoint with the crafted target and observe a redirect to the attacker host.
## False-positive filters
- Target is forced relative (leading single `/` **and** not `//`/`/\`) after normalization, or resolved
against the app origin and re-checked.
- Destination validated against a strict host allowlist (exact host match, not substring/`endsWith`).
- Redirect target is server-chosen (not user input) or an opaque id mapped to a known URL.
- Framework guard in place and not bypassed: Django `url_has_allowed_host_and_scheme` (formerly
`is_safe_url`) with `allowed_hosts` set, Rails 7 default `raise_on_open_redirects`, ASP.NET `LocalRedirect` /
`Url.IsLocalUrl`, Spring `RedirectView` with `setHosts`/relative-only handling. Confirm it is called on the exact
value used, after any decoding.
- Redirect is only to a path on the same origin, fixed prefix, and the user value goes after the prefix as a
single path segment or a query parameter (not a host, not a path that can start with `/` or `\`).
- Real evidence of a finding: user-controlled input reaches a navigation or `Location` and you can show the
concrete string that the validator (if any) accepts and the browser follows to another origin. A same-site
redirect, or one that needs a post-auth session the attacker cannot arrange, is lower severity. Report
severity by what the redirect enables (token/code leak, phishing from a trusted host), not by its existence.
## Detection signals (for defenders)
- **Logs needed**: web/proxy/WAF access logs with full query string, response status, and `Location` response header
(or a gateway that records it); IdP/SSO logs for `redirect_uri` and `state` values and rejected-URI errors;
email gateway logs for links to the app with embedded external URLs; browser/proxy referrer logs.
- **Attempts and abuse**: 301/302/303/307/308 responses whose `Location` host is not in the organization's
domains, on routes that normally redirect internally; request parameters named `next`, `url`, `redirect`,
`return_to`, `continue`, `RelayState` containing an absolute URL, a leading `//`, `/\`, encoded slashes, or
`@`; one app URL appearing in many external messages (phishing campaign) with differing target values;
OAuth authorization requests with unregistered or unusual `redirect_uri` values and mismatch errors.
- **Success in the OAuth chain**: an authorization code or token issued to a `redirect_uri` on an
unexpected host, or a `Referer` of an external site carrying a code/token in the URL on its logs; the
same code redeemed from a different client address than the one it was issued to.
- **Behaviour detection ideas**: (1) redirect responses from the app whose `Location` host is outside an allowlist
of owned domains, grouped by route; (2) auth-code or token issuance followed by redemption from a different
source IP or user agent within a short window.
- **ATT&CK**: T1566.002 (Phishing: Spearphishing Link) for the common abuse as a trusted-link launderer, T1190
(Exploit Public-Facing Application) for abuse against the app, T1528 (Steal Application Access Token) when it
leaks OAuth codes or tokens.
## CWE / OWASP / severity
CWE-601. OWASP A01:2021. Usually **medium** standalone; **high** when it leaks OAuth codes/tokens or is a
step in account takeover.
## Chaining hints
Open redirect + OAuth `redirect_uri` -> steal authorization code -> account takeover; + token/Referer leak
-> session theft (`auth`); + `ssrf` allowlist bypass (redirect from allowed host to internal); boosts
phishing credibility. Frequently the first hop in takeover chains.
## Mitigation
Avoid user-controlled redirect targets; if needed, allowlist exact destination hosts or force
same-origin/relative paths (reject `//`, `/\`, absolute URLs, and non-http schemes) after canonicalization;
for OAuth, exact-match `redirect_uri` against pre-registered values; show an interstitial for external links.