Open redirect

On this page 7

An open redirect is a vulnerability in which a web application sends the browser to a destination taken from user-controlled input without checking that the destination is trusted. In application security and cybersecurity more broadly, it is classified as CWE-601, URL redirection to untrusted site, and it matters because the victim sees a legitimate, trusted domain in the link before being forwarded to an attacker’s page.

On its own, an open redirect rarely exposes data directly. Its real weight comes from chaining: it lends credibility to phishing, helps bypass URL allowlists, and in OAuth and single sign-on flows it can leak authorization codes or tokens to a hostile server.

How an open redirect works

An open redirect works by abusing a redirect parameter that the application trusts blindly. Many sites accept a value such as next, returnUrl, continue or redirect_uri so that, after login or logout, the user returns to the page they came from. When the server copies that value into a Location header or a client-side navigation call without validation, any URL becomes a valid destination.

A typical attack link looks like https://bank.example/login?next=https://evil.example/. The victim recognizes the bank domain, signs in, and is then silently forwarded to a cloned page that asks for the password again or for a one-time code. The trusted origin at the start of the link is what makes the technique effective.

The following table shows the main places where redirect logic is implemented and how each can become exploitable.

MechanismHow the redirect happensTypical exploitable input
HTTP 3xx responseServer returns 301, 302, 303, 307 or 308 with a Location headerQuery parameter copied into Location
Client-side JavaScriptScript assigns window.location or calls location.replaceValue read from the URL fragment or query
Meta refresh tagHTML instructs the browser to load another URL after a delayParameter echoed into the tag content
Framework helpersLibrary function such as a redirect-to-referrer utilityReferer header or stored return path
Where redirects are implemented

Variants and bypass techniques

Open redirect variants differ mainly in where the destination comes from and in how weak validation is evaded. Developers often add a partial check, such as requiring that the value starts with a slash or contains the company domain, and attackers respond with parser confusion tricks that satisfy the check while still leaving the site.

The table below lists common bypass patterns that defeat naive string checks.

Payload patternNaive check it defeatsWhy the browser leaves the site
//evil.exampleValue starts with a slashProtocol-relative URL keeps the current scheme but changes the host
/\evil.exampleValue starts with a single slashBrowsers normalize a backslash to a forward slash
https://trusted.example@evil.exampleValue contains the trusted domainText before @ is treated as user information, not the host
https://trusted.example.evil.exampleValue starts with the trusted domainThe real host is a subdomain of the attacker’s domain
javascript: schemeValue is not an external URLClient-side redirects may execute script, turning the flaw into XSS
Common validation bypass patterns

The last row is significant: when a client-side redirect accepts the javascript: scheme, the issue escalates from a redirection problem to DOM-based cross-site scripting, which carries a far higher severity.

An open redirect is often confused with neighboring vulnerabilities because all of them involve URLs and requests. The decisive difference is who follows the URL: in an open redirect, it is the victim’s browser, whereas in server-side request forgery it is the server itself.

VulnerabilityWho makes the requestPrimary impact
Open redirectVictim’s browserPhishing credibility, token leakage
SSRFApplication serverAccess to internal services and cloud metadata
XSSScript running in the victim’s pageSession theft and actions as the user
CSRFVictim’s browser, without intentUnwanted state-changing actions
ClickjackingVictim, through a hidden frameMisdirected clicks on real controls
How open redirect differs from neighboring vulnerabilities

An open redirect can, however, amplify SSRF. If a server-side fetcher only allows URLs on the application’s own domain but follows redirects, an internal open redirect lets the attacker steer the server to arbitrary hosts.

Preventing open redirects in practice

The most reliable prevention is to avoid accepting full URLs as redirect targets. Instead, the application stores a set of known destinations and receives only an identifier or a relative path that maps to one of them. When dynamic destinations are unavoidable, validation must operate on the parsed URL, not on the raw string.

The decision table below summarizes which defense fits each design situation.

SituationRecommended approachReason
Fixed set of return pagesMap tokens to stored URLsNo user-supplied URL ever reaches the Location header
Return to any internal pageAccept only validated relative pathsReject values starting with // or containing a backslash
Partner or tenant domainsExact host allowlist after URL parsingComparing parsed hosts defeats @ and subdomain tricks
OAuth redirect_uriExact string match with registered valuesPrefix or wildcard matching enables code interception
Legacy links that must stayShow an interstitial warning pageThe user sees the real destination before leaving
Choosing a defense for redirect logic
  • Parse the destination with the same URL library the browser semantics expect, then compare scheme and host.
  • Allow only the https scheme and reject `javascript:` and `data:` outright.
  • Prefer a server-side session value for the return path instead of a query parameter.
  • Add redirect parameters to automated scanning and code review checklists, since they recur across login, logout and payment flows.

Severity, risks and common mistakes

The severity of an open redirect is context dependent. Many bug bounty programs rate a standalone redirect as low risk, yet the same flaw becomes high or critical when it sits in an OAuth authorization endpoint, because an attacker can redirect the authorization code or access token to a server they control and take over accounts.

A frequent mistake is treating the flaw as harmless because it does not touch the database. Another is relying on blocklists of known bad domains, which attackers sidestep by registering new domains within minutes. Teams also forget that the Referer header and URL fragments can carry tokens to the destination site once the browser has been redirected.

Finally, an open redirect on a reputable domain weakens email and web filters, since many security products score links by their visible domain. That is why phishing campaigns actively search for redirectors on large, trusted websites.

In simple terms

Imagine a trusted hotel reception desk that will send you to any address written on a slip of paper, without reading it first. A stranger hands you a slip that starts with the hotel’s name, so you trust it, but the desk then sends you to a fake office down the street.

An open redirect is that careless reception desk on a website. The link looks safe because it begins with a real company’s address, yet it ends somewhere dangerous. The fix is simple in principle: the website should only send visitors to trusted places it already knows.

A practical example

A regional online retailer used a login page that accepted a returnUrl parameter so customers could go back to their shopping cart after signing in. During a routine penetration test, a security consultant found that the value was copied directly into a 302 response. A link such as the login page followed by returnUrl=//shop-account-check.example sent signed-in customers to an external look-alike site.

The consultant demonstrated a phishing email whose visible link pointed to the retailer’s real domain, which passed the company’s own email filter. The development team replaced the parameter with a short token mapped to five stored return paths and added a check that rejects any value beginning with two slashes. A retest confirmed that every external destination was refused, and the finding was closed within one sprint.