Issue
A redirect tells a browser to request another URL. Web applications commonly use redirects after login, after form submissions, or to send users to another page. An open redirect occurs when an application uses user-controlled input as the redirect destination without adequately checking where it leads.
For example, an endpoint might accept a next parameter and return a redirect to that value. If an attacker can change it to an external site, the link still begins with the application’s trusted domain, but the browser ends up elsewhere. OWASP and MITRE classify this weakness as an unvalidated redirect, or CWE-601. OWASP Unvalidated Redirects and Forwards Cheat Sheet, MITRE CWE-601
Common causes include:
- Passing a query parameter such as next, url, return, or redirect directly to a redirect function.
- Checking destinations with loose string matching, such as accepting any URL that starts with a trusted domain’s name.
- Allowing broad redirect patterns when only a small set of destinations is needed.
- Failing to validate return destinations in login or authorization flows.
A server-side forward is related but different: it routes a request to another resource on the server without necessarily sending the browser to a new URL. It can create authorization problems if the application forwards a request to a resource without checking access. This article focuses on browser redirects.
Examples
Illustrative vulnerable behavior
Request:
GET /redirect?next=https%3A%2F%2Fattacker.example%2F HTTP/1.1Host: app.example.comResponse:
HTTP/1.1 302 FoundLocation: https://attacker.example/
If the application produces this response for an untrusted destination, the browser will follow it to attacker.example.
Illustrative safer behavior
For a login return destination, the application can accept only local paths and use a safe default when the value is invalid:
Requested path: /account
Result: redirect to /account
Requested path: https://attacker.example/
Result: reject or redirect to a fixed local page
For a small set of external partners, use a server-side mapping from an approved identifier to a destination:
partner=docs → https://docs.example.com/partner=help → https://help.example.com/
Unknown value → reject or use a fixed local page
Impact
An open redirect can make a phishing link appear to come from a trusted site. A user may trust the link’s initial domain and follow it to a harmful destination. The redirect alone does not prove that credentials were collected, that an account was compromised, or that data was exposed; those outcomes require additional behavior and evidence.
Open redirects can also matter in security-sensitive flows. For example, OAuth security guidance warns that an open redirector can be used in some circumstances to expose authorization codes or access tokens. That impact depends on the authorization flow, how the redirect is reached, and whether the application handles credentials in URLs. It should be reported as a confirmed token exposure only when the relevant flow and exposure are demonstrated. RFC 9700, sections 2.1 and 4.11
Testing
1. Check whether user input controls the redirect destination
Capture a redirect request and replace its destination with a reserved external example origin. Inspect Location and follow it in a browser.
Example: A changed Location header is a lead. Confirm the browser reaches the destination rather than assuming it does.
GET /login?next=https%3A%2F%2Foutside.example.test%2F HTTP/1.1
Host: app.example.test
2. Compare relative and alternate URL forms
Test the formats the application accepts, such as an absolute URL and a scheme-relative URL. Check the final destination after any intermediate redirects.
Example: A value beginning with // can identify another host. Compare how the server and browser interpret it.
GET /login?next=%2F%2Foutside.example.test%2F HTTP/1.1
Host: app.example.test
3. Check redirect use and boundaries
Review login, logout, referral, and return-to flows. Distinguish a deliberately allowed partner destination from an unexpected external redirect.
Example: An external redirect can support phishing. It does not by itself prove credentials were stolen.
Common false positives and limitations:
- A 3xx response may point only to a safe, local path or an approved destination.
- The application may normalize, reject, or replace the supplied value before redirecting. Inspect the actual Location header and browser destination.
- A string in the response body that resembles a URL is not proof that the browser was redirected.
- A redirect to an external site may be intentional. Confirm whether arbitrary destinations are accepted and whether the behavior is within the application’s intended design.
Mitigation
Primary fixes
- Prefer a fixed destination or a server-side mapping from an approved ID to a destination. This avoids accepting arbitrary URLs from the request.
- For return paths that must stay on the application, use the framework’s local-URL validation or redirect helper. Reject absolute URLs and other values the framework does not recognize as local.
- If external destinations are required, compare parsed URL components against an explicit allowlist. Check the scheme, canonical host, and effective port; constrain paths when appropriate. Avoid raw prefix or suffix checks, which can accept misleading hostnames or user-info tricks.
- In OAuth, require exact matching against registered redirect URIs, following the applicable protocol guidance. RFC 9700 says clients and authorization servers must not expose open redirectors that forward browsers to arbitrary query-parameter destinations. RFC 9700
Additional defenses
- Show the destination clearly and require the user to confirm before leaving the site when that fits the workflow. This can reduce deceptive use, but it does not replace destination validation.
- Log rejected redirect attempts in a way that supports investigation without recording sensitive tokens or credentials.
Retest by submitting both an approved destination and an external unapproved destination. Confirm that the approved case reaches the intended page, while the unapproved case is rejected or sent to a fixed safe destination. For OAuth, separately verify that unregistered redirect URIs are rejected and that the authorization server does not redirect to them.