01 //Introduction to Open Redirects
An open redirect (also called an unvalidated redirect) occurs when a web application takes a user-supplied URL or path and redirects the user to it without proper validation. Attackers exploit this to redirect victims from a trusted domain to a malicious site — enabling phishing, credential theft, and OAuth token hijacking.
In this guide, you'll learn how to spot open redirect patterns during code review, why simple validation like "starts with /" can be bypassed, which framework-specific patterns are dangerous, how attackers chain open redirects with OAuth and SSO, and what prevention strategies actually work.
?next=/dashboard
?redirect_uri=...
?returnTo=...
/r?u=...
?success_url=...
?url=verify&goto=...
A developer says open redirects aren't a real vulnerability because 'we're just redirecting, not executing code.' Why is this wrong?
02 //Vulnerable Code Patterns
Open redirects appear whenever user input flows into a redirect target without validation. The most common patterns involve query parameters, form fields, headers, and path segments that control where the server sends the user.
1// VULNERABLE: Direct query parameter redirect
2app.get('/login', (req, res) => {
3 // After successful authentication...
4 const redirectUrl = req.query.next || '/dashboard';
5 res.redirect(redirectUrl);
6 // Attacker: /login?next=https://evil.com
7});
8
9// VULNERABLE: Header-based redirect
10app.get('/redirect', (req, res) => {
11 const target = req.headers['x-redirect-url'];
12 res.redirect(target);
13});
14
15// VULNERABLE: Path parameter redirect
16app.get('/goto/:url', (req, res) => {
17 res.redirect(decodeURIComponent(req.params.url));
18 // Attacker: /goto/https%3A%2F%2Fevil.com
19});
20
21// VULNERABLE: POST body redirect
22app.post('/login', (req, res) => {
23 const { username, password, returnTo } = req.body;
24 if (authenticate(username, password)) {
25 res.redirect(returnTo); // User-controlled redirect
26 }
27});
28
29// VULNERABLE: Building URL with user input
30app.get('/redirect', (req, res) => {
31 const path = req.query.path;
32 res.redirect(`https://${req.query.host}/${path}`);
33 // Attacker: ?host=evil.com&path=phish
34});1# VULNERABLE: Django — redirect to user-supplied URL
2from django.shortcuts import redirect
3
4def login_view(request):
5 # After authentication...
6 next_url = request.GET.get('next', '/dashboard')
7 return redirect(next_url)
8 # Attacker: /login?next=https://evil.com
9
10# VULNERABLE: Flask — unvalidated redirect
11from flask import Flask, redirect, request
12
13@app.route('/auth/callback')
14def auth_callback():
15 return_url = request.args.get('return_to', '/')
16 return redirect(return_url)
17
18# VULNERABLE: Using urllib without validation
19import urllib.parse
20
21def safe_redirect(request):
22 url = request.GET.get('url')
23 parsed = urllib.parse.urlparse(url)
24 # Developer THINKS this is safe because they "parsed" the URL
25 # but they never actually check the parsed result
26 return redirect(url)1// VULNERABLE: Spring MVC — redirect: prefix with user input
2@GetMapping("/login")
3public String login(@RequestParam(defaultValue = "/home") String next) {
4 // After authentication...
5 return "redirect:" + next;
6 // Attacker: /login?next=https://evil.com
7}
8
9// VULNERABLE: HttpServletResponse.sendRedirect
10@GetMapping("/goto")
11public void goTo(HttpServletRequest req, HttpServletResponse res)
12 throws IOException {
13 String target = req.getParameter("url");
14 res.sendRedirect(target);
15}
16
17// VULNERABLE: Spring redirect with URI building
18@GetMapping("/redirect")
19public RedirectView redirect(@RequestParam String target) {
20 return new RedirectView(target);
21}Common Redirect Parameter Names to Search For
| Parameter | Context | Example |
|---|---|---|
| next, next_url | Post-login redirect | /login?next=/dashboard |
| redirect, redirect_url | Generic redirect | /auth?redirect=... |
| redirect_uri | OAuth flows | /authorize?redirect_uri=... |
| return, returnTo, return_url | Return after action | /sso?returnTo=... |
| goto, go, url, link | Link shorteners, trackers | /goto?url=... |
| target, dest, destination | Navigation handlers | /nav?target=... |
| continue, forward, rurl | Multi-step flows | /step2?continue=... |
| success_url, cancel_url | Payment flows | /pay?success_url=... |
A developer writes: `const next = req.query.next; if (next) res.redirect(next); else res.redirect('/');` — They say it's safe because the redirect only happens if 'next' is provided. Is this correct?
03 //Common Bypass Techniques
Developers often attempt to fix open redirects with naive validation — checking if the URL starts with /, contains the expected domain, or uses a blocklist. Attackers have well-known techniques to bypass each of these approaches.
1// BYPASS 1: "starts with /" check
2// Developer's validation:
3if (url.startsWith('/')) { res.redirect(url); }
4
5// Attacker bypasses with protocol-relative URL:
6// /login?next=//evil.com
7// Browsers interpret "//evil.com" as "https://evil.com"
8
9// Also bypassed with:
10// /login?next=/\evil.com (backslash treated as slash)
11// /login?next=/%2Fevil.com (double-encoded slash)
12
13
14// BYPASS 2: Domain substring check
15// Developer's validation:
16if (url.includes('trusted.com')) { res.redirect(url); }
17
18// Attacker bypasses with:
19// ?next=https://trusted.com.evil.com (subdomain of evil.com)
20// ?next=https://evil.com/trusted.com (path contains domain)
21// ?next=https://evil.com?q=trusted.com (query contains domain)
22// ?next=https://trusted.com@evil.com (userinfo — redirects to evil.com!)
23
24
25// BYPASS 3: Regex-based domain check
26// Developer's validation:
27if (/^https:\/\/trusted\.com/.test(url)) { res.redirect(url); }
28
29// Attacker bypasses with:
30// ?next=https://trusted.com.evil.com/phish (regex matches prefix)
31
32
33// BYPASS 4: Blocking "http://" and "https://"
34// Developer's validation:
35if (!url.startsWith('http://') && !url.startsWith('https://')) {
36 res.redirect(url);
37}
38
39// Attacker bypasses with:
40// ?next=//evil.com (protocol-relative)
41// ?next=HTTPS://evil.com (case variation)
42// ?next=\\evil.com (backslash)
43// ?next=data:text/html,... (data URI — in some contexts)Bypass Technique Summary
| Validation | Bypass | Why It Works |
|---|---|---|
| startsWith("/") | //evil.com | Protocol-relative URLs start with / but redirect off-domain |
| startsWith("/") | /\evil.com | Backslash is treated as forward slash by browsers |
| includes("trusted.com") | trusted.com.evil.com | Substring match catches subdomains of attacker domain |
| includes("trusted.com") | evil.com?q=trusted.com | Domain string appears in query/path, not hostname |
| includes("trusted.com") | trusted.com@evil.com | userinfo@host syntax — browser navigates to evil.com |
| !startsWith("http") | //evil.com or HTTPS://evil.com | Protocol-relative or case variation bypasses prefix check |
| endsWith("trusted.com") | nottrusted.com | Suffix check allows any prefix before the domain |
userinfo component: https://user:pass@host/path. When an attacker crafts https://trusted.com@evil.com, the browser navigates to evil.com with "trusted.com" as the username. Any validation that checks if "trusted.com" appears in the URL without proper URL parsing will be bypassed. Always parse the URL and check the hostname property specifically.A developer validates redirect URLs with: `if (url.startsWith('/') && !url.startsWith('//'))`. Can this still be bypassed?
04 //Framework-Specific Patterns
Each web framework has its own redirect APIs and built-in protections (or lack thereof). Understanding framework-specific behavior is critical for code review, as some frameworks offer partial protection that developers may over-rely on.
1# Django's url_has_allowed_host_and_scheme (formerly is_safe_url)
2# provides built-in open redirect protection
3from django.utils.http import url_has_allowed_host_and_scheme
4
5def login_view(request):
6 next_url = request.GET.get('next', '')
7
8 # SECURE: Uses Django's built-in validation
9 if url_has_allowed_host_and_scheme(
10 url=next_url,
11 allowed_hosts={request.get_host()},
12 require_https=request.is_secure(),
13 ):
14 return redirect(next_url)
15 return redirect('/dashboard')
16
17
18# VULNERABLE: Bypassing Django's LoginView protection
19# Django's LoginView uses url_has_allowed_host_and_scheme internally,
20# BUT only when using the default "next" parameter.
21# Custom login views often skip this:
22
23class CustomLoginView(View):
24 def post(self, request):
25 # Authenticates user...
26 return redirect(request.POST.get('redirect_to', '/'))
27 # Developer used "redirect_to" instead of "next"
28 # so Django's built-in protection doesn't apply
29
30
31# VULNERABLE: Empty allowed_hosts
32if url_has_allowed_host_and_scheme(url=next_url, allowed_hosts=set()):
33 return redirect(next_url)
34# With empty allowed_hosts, only path-relative URLs pass
35# BUT protocol-relative URLs like //evil.com are still blocked
36# This is actually SAFE — but confusing and fragile1// VULNERABLE: Next.js API route with unvalidated redirect
2// pages/api/login.ts
3export default function handler(req, res) {
4 const { callbackUrl } = req.query;
5 // After auth...
6 res.redirect(callbackUrl);
7}
8
9// VULNERABLE: Next.js middleware redirect
10import { NextResponse } from 'next/server';
11
12export function middleware(request) {
13 const returnUrl = request.nextUrl.searchParams.get('returnUrl');
14 // Redirecting without validation
15 return NextResponse.redirect(new URL(returnUrl, request.url));
16 // NOTE: new URL(returnUrl, request.url) resolves relative URLs
17 // against the current origin — but absolute URLs like
18 // https://evil.com override the base entirely!
19}
20
21// SECURE: Validating redirect in Next.js
22export function middleware(request) {
23 const returnUrl = request.nextUrl.searchParams.get('returnUrl');
24
25 // Parse and validate
26 try {
27 const target = new URL(returnUrl, request.url);
28 const allowedHosts = ['myapp.com', 'www.myapp.com'];
29
30 if (!allowedHosts.includes(target.hostname)) {
31 return NextResponse.redirect(new URL('/dashboard', request.url));
32 }
33 return NextResponse.redirect(target);
34 } catch {
35 return NextResponse.redirect(new URL('/dashboard', request.url));
36 }
37}
38
39// VULNERABLE: React client-side redirect
40// Attacker controls window.location via URL parameter
41function LoginCallback() {
42 const searchParams = new URLSearchParams(window.location.search);
43 const next = searchParams.get('next');
44
45 useEffect(() => {
46 window.location.href = next || '/dashboard';
47 // Client-side open redirect — same risk as server-side
48 }, [next]);
49}1// VULNERABLE: Spring redirect: prefix
2@GetMapping("/login")
3public String handleLogin(@RequestParam String next) {
4 return "redirect:" + next;
5}
6
7// VULNERABLE: Spring RedirectView
8@GetMapping("/redirect")
9public RedirectView redirect(@RequestParam String url) {
10 RedirectView rv = new RedirectView();
11 rv.setUrl(url);
12 return rv;
13}
14
15// SECURE: Allowlist-based validation in Spring
16@GetMapping("/login")
17public String handleLogin(@RequestParam(defaultValue = "/home") String next) {
18 if (isValidRedirect(next)) {
19 return "redirect:" + next;
20 }
21 return "redirect:/home";
22}
23
24private boolean isValidRedirect(String url) {
25 try {
26 URI uri = new URI(url);
27 // Only allow relative paths (no scheme = relative)
28 if (uri.getScheme() != null) {
29 return false;
30 }
31 // Block protocol-relative URLs
32 if (url.startsWith("//") || url.startsWith("/\\")) {
33 return false;
34 }
35 // Must start with /
36 return url.startsWith("/");
37 } catch (URISyntaxException e) {
38 return false;
39 }
40}url_has_allowed_host_and_scheme() is robust when used correctly. Rails raises ActionController::Redirecting::UnsafeRedirectError for external redirects since Rails 7 (configurable via allow_other_host). Spring Security's SavedRequestAwareAuthenticationSuccessHandler validates redirect targets. Express has no built-in protection — res.redirect() will redirect to any URL. Always verify your framework's behavior rather than assuming protection exists.A Next.js middleware uses: `new URL(returnUrl, request.url)` to resolve the redirect URL. The developer says this is safe because "it resolves relative to our origin." Is this correct?
05 //Detection During Code Review
Detecting open redirects during code review requires searching for redirect/navigation APIs that consume user input. The key is tracing data flow from user-controlled sources (query params, form fields, headers) to redirect sinks.
Redirect Sinks by Language/Framework
| Language | Redirect Sink | Notes |
|---|---|---|
| Node/Express | res.redirect(), res.writeHead(302, {Location: ...}) | No built-in validation |
| Next.js | NextResponse.redirect(), redirect() (server actions) | URL constructor can bypass validation |
| Django | redirect(), HttpResponseRedirect() | Use url_has_allowed_host_and_scheme() |
| Flask | redirect(), make_response() with Location header | No built-in validation |
| Spring | "redirect:" prefix, RedirectView, sendRedirect() | Spring Security has partial protection |
| Rails | redirect_to | Rails 7+ blocks external redirects by default |
| PHP | header("Location: ..."), wp_redirect() | No built-in validation |
| Client JS | window.location, window.location.href, location.assign() | Client-side open redirect |
1# Search for redirect sinks consuming variables
2rg "res\.redirect\(.*req\." --type js --type ts
3rg "redirect\(.*request\." --type py
4rg "sendRedirect\(.*req\." --type java
5rg "redirect_to.*params\[" --type ruby
6
7# Search for common redirect parameter names
8rg "(next|redirect|returnTo|goto|url|target|dest|forward|continue|callback)" \
9 --type js --type ts -g "*.tsx" | rg "(query|param|searchParam)"
10
11# Search for Location header manipulation
12rg "Location.*req\." --type js --type ts
13rg "HttpResponseRedirect|redirect\(" --type py
14rg "header\(.*Location" --type php
15
16# Search for client-side redirects
17rg "window\.location\s*=" --type js --type ts
18rg "location\.assign\(" --type js --type ts
19rg "location\.replace\(" --type js --type ts- Trace all redirect parameters back to their source — If a redirect target comes from
req.query,req.body,req.headers, orreq.params, it is user-controlled and must be validated. - Check for URL construction with user input — String concatenation like
`https://${req.query.host}/path`is just as dangerous as a direct redirect parameter. - Don't trust framework defaults — Verify whether your framework's redirect function validates URLs. Most (Express, Flask, PHP) do not.
- Look for client-side redirects too —
window.location.href = params.get("next")is an open redirect even though it happens in the browser. - Review OAuth redirect_uri handling — The
redirect_uriparameter in OAuth flows is the highest-impact open redirect vector because it can leak authorization codes and tokens. - Search for indirect redirects — Meta refresh tags (
<meta http-equiv="refresh" content="0;url=...">) and JavaScript navigation in server-rendered HTML are also redirect sinks.
During code review, you find `res.redirect(req.query.next || '/dashboard')`. The developer says the `|| '/dashboard'` fallback makes it safe. What do you flag?
06 //Prevention Strategies
Preventing open redirects requires a layered approach. The most reliable strategy is to avoid using user input in redirects entirely. When that is not possible, use strict validation with proper URL parsing.
1// STRATEGY 1: Indirect reference map (most secure)
2// Map user input to predefined destinations
3const REDIRECT_MAP = {
4 'dashboard': '/dashboard',
5 'profile': '/account/profile',
6 'settings': '/account/settings',
7 'billing': '/account/billing',
8};
9
10app.get('/login', (req, res) => {
11 const key = req.query.next;
12 const target = REDIRECT_MAP[key] || '/dashboard';
13 res.redirect(target);
14 // Attacker can only redirect to predefined paths
15});
16
17
18// STRATEGY 2: Strict URL parsing with hostname allowlist
19function validateRedirectUrl(url, allowedHosts) {
20 try {
21 // Reject protocol-relative URLs before parsing
22 if (url.startsWith('//') || url.startsWith('/\\')) {
23 return null;
24 }
25
26 // Parse relative URLs against a known base
27 const parsed = new URL(url, 'https://placeholder.invalid');
28
29 // If the URL was absolute, hostname won't be placeholder
30 if (parsed.hostname !== 'placeholder.invalid') {
31 // Absolute URL — check against allowlist
32 if (!allowedHosts.includes(parsed.hostname)) {
33 return null;
34 }
35 }
36
37 // Block non-HTTP schemes (javascript:, data:, etc.)
38 if (!['https:', 'http:'].includes(parsed.protocol)) {
39 // For relative URLs, protocol comes from the placeholder
40 if (parsed.hostname !== 'placeholder.invalid') {
41 return null;
42 }
43 }
44
45 return url;
46 } catch {
47 return null;
48 }
49}
50
51app.get('/login', (req, res) => {
52 const next = req.query.next;
53 const validated = validateRedirectUrl(next, ['myapp.com', 'www.myapp.com']);
54 res.redirect(validated || '/dashboard');
55});
56
57
58// STRATEGY 3: Relative-path-only with strict validation
59function isRelativePath(url) {
60 // Must start with exactly one forward slash
61 if (!url.startsWith('/') || url.startsWith('//')) {
62 return false;
63 }
64 // Reject backslash variations
65 if (url.includes('\\')) {
66 return false;
67 }
68 // Parse to verify no scheme or authority
69 try {
70 const parsed = new URL(url, 'https://placeholder.invalid');
71 return parsed.hostname === 'placeholder.invalid';
72 } catch {
73 return false;
74 }
75}1# SECURE: Using Django's built-in protection
2from django.utils.http import url_has_allowed_host_and_scheme
3
4def safe_redirect(request):
5 next_url = request.GET.get('next', '')
6
7 if url_has_allowed_host_and_scheme(
8 url=next_url,
9 allowed_hosts={request.get_host()},
10 require_https=True,
11 ):
12 return redirect(next_url)
13 return redirect('/dashboard')
14
15
16# SECURE: Custom validation with urllib.parse
17from urllib.parse import urlparse
18
19ALLOWED_HOSTS = {'myapp.com', 'www.myapp.com'}
20
21def validate_redirect(url: str) -> str | None:
22 if not url:
23 return None
24
25 # Block protocol-relative URLs
26 if url.startswith('//') or url.startswith('/\\'):
27 return None
28
29 parsed = urlparse(url)
30
31 # If scheme is present, it's an absolute URL — validate host
32 if parsed.scheme:
33 if parsed.scheme not in ('http', 'https'):
34 return None
35 if parsed.netloc not in ALLOWED_HOSTS:
36 return None
37 return url
38
39 # No scheme — check if netloc is present (protocol-relative)
40 if parsed.netloc:
41 return None
42
43 # Relative URL — must start with /
44 if url.startswith('/'):
45 return url
46
47 return NonePrevention Strategy Comparison
| Strategy | Security Level | Flexibility | Best For |
|---|---|---|---|
| Indirect reference map | Highest — no user URL in redirect | Low — predefined destinations | Login flows with known destinations |
| Hostname allowlist + URL parsing | High — proper parsing catches bypasses | Medium — allows any path on allowed hosts | Multi-domain apps, OAuth |
| Relative-path-only | High — blocks all external redirects | Medium — only same-origin paths | Single-domain apps |
| Blocklist (http://, //, etc.) | Low — easily bypassed | High — minimal restrictions | Not recommended |
| Substring check (includes domain) | Very Low — trivially bypassed | High | Not recommended |
form-action directive can restrict where forms submit to, limiting some redirect vectors. More importantly, if an open redirect is chained with XSS, a strong CSP limits the attacker's options. Consider CSP as one layer in your defense.Which prevention strategy is most secure for a post-login redirect where users can only land on /dashboard, /profile, or /settings?
07 //OAuth & Open Redirect
Open redirects in OAuth flows are the highest-impact variant of this vulnerability. In OAuth 2.0, the redirect_uri parameter tells the authorization server where to send the authorization code or access token after the user consents. If an attacker can manipulate this parameter, they can steal tokens and take over accounts.
1// OAuth Authorization Request (normal flow):
2// GET /authorize
3// ?response_type=code
4// &client_id=app123
5// &redirect_uri=https://app.com/callback
6// &scope=read
7// &state=random123
8
9// VULNERABLE: Server does prefix match on redirect_uri
10// Registered: https://app.com/callback
11// Attacker uses: https://app.com/callback/../redirect?url=https://evil.com
12// Path traversal in redirect_uri → token sent to callback,
13// which then redirects to evil.com WITH the token in the URL
14
15// VULNERABLE: Server allows subdirectory matching
16// Registered: https://app.com/
17// Attacker uses: https://app.com/page-with-open-redirect?next=https://evil.com
18// Auth code goes to legitimate page, which redirects to evil.com
19// Referer header leaks the code to the attacker
20
21// VULNERABLE: Server allows subdomain matching
22// Registered: *.app.com
23// Attacker finds XSS on blog.app.com
24// Uses: https://blog.app.com/xss-page as redirect_uri
25// Steals the authorization code via XSS
26
27
28// SECURE: Strict redirect_uri validation
29function validateRedirectUri(requestUri, registeredUris) {
30 // Exact string match — no pattern matching
31 return registeredUris.includes(requestUri);
32}
33
34// SECURE: Use state parameter + PKCE
35// state: prevents CSRF on the callback
36// PKCE: prevents authorization code interception
37// Together they make token theft much harder even with open redirectresponse_type=token (implicit flow), the access token is placed in the URL fragment (#access_token=...). An open redirect on the client application can leak this token via the Referer header or by redirecting to an attacker's server that reads the fragment. Even with authorization code flow, if the code is appended as a query parameter and the page has an open redirect, the code leaks via the Referer. This is why PKCE is essential — it binds the code to the original client, making stolen codes useless.- Always use exact redirect_uri matching — Never allow prefix, subdomain, or wildcard matching. The OAuth 2.0 spec recommends exact string comparison.
- Require PKCE for all flows — PKCE (Proof Key for Code Exchange) prevents authorization code interception even if an attacker manages to redirect the code.
- Use response_type=code, never token — The implicit flow puts tokens in URL fragments, making them vulnerable to leaking via redirects and Referer headers.
- Validate state parameter on callback — The state parameter prevents CSRF against the OAuth callback and should be a cryptographically random value.
- Audit all pages on your OAuth redirect domain — Any open redirect, XSS, or content injection on a page that can be used as redirect_uri enables token theft.
An OAuth provider matches redirect_uri using prefix matching: registered URI is 'https://app.com/callback'. Why is this dangerous?
08 //Chaining Open Redirects with Other Vulnerabilities
Open redirects become far more dangerous when chained with other vulnerabilities. A 'low severity' open redirect can escalate to critical impact when combined with SSRF, XSS, OAuth, or CSRF.
Open Redirect Attack Chains
| Chain | Mechanism | Impact | Severity |
|---|---|---|---|
| Open Redirect + OAuth | Redirect authorization code/token to attacker | Account takeover | Critical |
| Open Redirect + SSRF | Bypass SSRF URL allowlist via trusted domain redirect | Internal network access | Critical |
| Open Redirect + Phishing | Legitimate URL in phishing email redirects to fake login | Credential theft at scale | High |
| Open Redirect + XSS | Redirect to javascript: URI or page with reflected XSS | Code execution in victim context | High |
| Open Redirect + CSRF | Force redirect to CSRF payload after state-changing action | Chained state changes | Medium-High |
| Open Redirect + Header Injection | Inject CRLF in redirect URL to set arbitrary headers | Session fixation, cache poisoning | High |
1# Scenario: App fetches URLs but blocks internal IPs
2# The SSRF filter allows requests to "trusted-api.com"
3
4# Normal request (allowed):
5GET /fetch?url=https://trusted-api.com/data
6
7# Attacker finds an open redirect on trusted-api.com:
8# https://trusted-api.com/redirect?goto=http://169.254.169.254/
9
10# Attack chain:
11GET /fetch?url=https://trusted-api.com/redirect?goto=http://169.254.169.254/latest/meta-data/iam/security-credentials/
12
13# 1. SSRF filter sees trusted-api.com → ALLOWED
14# 2. Server requests trusted-api.com
15# 3. trusted-api.com responds with 302 → http://169.254.169.254/
16# 4. HTTP client follows redirect to metadata service
17# 5. Attacker gets IAM credentials
18
19# This is why SSRF protection MUST not follow redirects,
20# or must re-validate the URL after each redirect hop.09 //Real-World Case Studies
/callback/../other-page), enabling token theft. Google awarded a bounty and fixed the issue. This demonstrates that even the most security-conscious organizations struggle with redirect_uri validation — exact string matching is the only safe approach./\uff0f\uff0fevil.com passed the "starts with /" check but normalized to //evil.com in the browser. This highlights why string-based validation is inherently fragile — always use proper URL parsing.10 //Conclusion & Checklist
Open redirects are deceptively simple vulnerabilities with outsized impact. During code review, a systematic search for redirect sinks consuming user input will catch most cases. Use this checklist to ensure thorough coverage.
Open Redirect Code Review Checklist
| Category | Check | Priority |
|---|---|---|
| Redirect Parameters | Are query parameters (next, redirect, returnTo, url, etc.) used in redirects? | Critical |
| Redirect Parameters | Are POST body fields or headers used as redirect targets? | Critical |
| Validation | Is the redirect URL validated using proper URL parsing (not string checks)? | Critical |
| Validation | Does validation check the hostname property, not substring matching? | Critical |
| Validation | Are protocol-relative URLs (//) and backslash variants (/\) blocked? | High |
| Validation | Is there an allowlist of permitted redirect destinations or hosts? | High |
| OAuth | Does the OAuth implementation use exact redirect_uri matching? | Critical |
| OAuth | Is PKCE implemented for all OAuth authorization code flows? | Critical |
| OAuth | Are all pages on the redirect domain free of open redirects and XSS? | High |
| Client-Side | Does any JavaScript set window.location from URL parameters? | High |
| Client-Side | Are client-side navigation hooks validated before redirecting? | High |
| Framework | Are you relying on framework built-in protection? Is it correctly configured? | High |
| SSRF Defense | Does your SSRF protection re-validate URLs after following redirects? | High |
Prefer indirect reference maps: When destinations are finite, map keys to paths instead of accepting URLs.
Check hostname, not substring: String matching is trivially bypassed by userinfo, subdomain, and encoding tricks.
Treat redirect_uri as critical: Use exact string matching and pair with PKCE in every OAuth flow.