Skip to content

Open Redirect: How Your Trusted Link Sends Users to an Attacker

An open redirect lets an attacker borrow your domain's credibility to bounce victims to phishing pages and steal OAuth tokens. Here is how the unvalidated redirect parameter is abused and how to constrain it.

SelfSec Team 7 min read

Part 1 of 2From the Open Redirect series

At a glance

CWE-601
Interpreter
Browser redirect handling and URL parser
Required condition
A request value chooses the redirect destination without an allowlist check.
Potential impact
Phishing from a trusted domain, OAuth code or token theft, and a stepping stone for other attacks.
Primary defense
Redirect only to local paths or server-mapped destinations, and exact-match any external host.

Safe practice: use benign proof only, in a disposable local lab or on a system you are explicitly authorized to test.

An open redirect happens when an application takes a user-supplied URL and redirects the browser to it without checking that the destination is one it trusts. On its own it does not leak data or run code — which is exactly why it is so often dismissed. But it hands an attacker something valuable: the ability to launch an attack from your domain. The link starts on a site the victim trusts and quietly lands somewhere the attacker controls.

Those redirect, next and returnUrl parameters that pepper login flows and post-action pages are the usual culprits. The OWASP Top 10:2025 maps open redirect (CWE-601) to A01 Broken Access Control. This post shows how an unvalidated one becomes a phishing and token-theft tool, and how to lock the redirect down to destinations you actually own.

The mental model: the browser resolves the URL, not your validator

A redirect target is a string the application checks and then hands to the browser's URL parser. If the check and the parser disagree about where that string points, the parser wins. Most broken redirect filters are string tests that the browser reads differently:

Check the code performs Value that passes it Where the browser goes
Starts with / //evil.example https://evil.example/
Starts with / but not // /\evil.example https://evil.example/
Contains app.example https://app.example.evil.example A host the attacker registered
Starts with https://app.example https://[email protected] evil.example, with app.example as a username

Only a check that parses the URL the same way a browser does, or avoids user-supplied URLs altogether, closes this gap.

How it happens

The pattern shows up wherever an app needs to send you somewhere after an action — typically back to where you came from after logging in. The destination is read from the request and used verbatim:

public IActionResult Login(string returnUrl)
{
    // ... authenticate the user ...
    return Redirect(returnUrl);
}

The developer expects returnUrl to be something like /dashboard — a path on the same site. But the value is attacker-controlled, and Redirect() will happily send the browser to any URL it is handed, including an absolute one pointing at a completely different domain.

A concrete attack

The attacker crafts a link that begins on the trusted site but carries an off-site returnUrl:

https://app.example/login?returnUrl=https://app-example.evil.example/login

The victim sees app.example at the start of the URL, trusts it, and signs in. After authentication the app issues:

HTTP/1.1 302 Found
Location: https://app-example.evil.example/login

The browser follows it to a pixel-perfect clone of the login page on the attacker's domain, which harvests the credentials the user re-enters. Filters that only block obvious https:// prefixes are sidestepped with protocol-relative and malformed variants that browsers still treat as off-site:

returnUrl=//evil.example                           # protocol-relative, inherits https
returnUrl=/\evil.example                           # backslash that browsers normalize to //
returnUrl=http:evil.example                        # missing slashes; an https page resolves it to http://evil.example/
returnUrl=https://[email protected]   # userinfo trick; host is evil.example

The same primitive is even nastier in OAuth flows: if redirect_uri is not strictly validated, the authorization code or token meant for the real app is delivered straight to the attacker's domain. The OAuth redirect_uri deep-dive covers that variant.

The vulnerability is not that the app redirects. It is that the app lets the attacker decide the destination, while the victim sees only your trusted name at the start of the link.

What an attacker gains

A redirect the attacker controls is a credibility laundering machine:

  • Convincing phishing — the lure begins on your real domain, defeating "check the link" advice.
  • OAuth token and code theft — a loose redirect_uri hands authorization codes or access tokens to the attacker.
  • Malware delivery — bouncing users to drive-by download or exploit pages under cover of your brand.
  • Filter and reputation bypass — security tools that trust your domain wave the initial link through.

Where open redirects hide

Login return URLs are the classic case, but the same sink appears in logout and single sign-on flows, language and region switchers, link-tracking endpoints such as /out?url=, and error pages that offer a "go back" link. Not every redirect is a Location header, either: a Refresh header, a <meta http-equiv="refresh"> tag or client-side code such as location.href = params.get('next') does the same job.

Each of those sinks can lead somewhere worse than a phishing page. A client-side redirect that accepts javascript: URLs becomes cross-site scripting. A redirect target copied into a Location header without rejecting line breaks becomes CRLF injection. And a server-side fetcher that follows redirects can be bounced from an allowed URL to an internal one, which is how open redirects feed SSRF chains.

The fix: allowlist destinations, prefer relative paths

The reliable rule is to never redirect to a raw user-supplied URL. Constrain the destination to things you control. The simplest robust approach is to only allow same-site relative paths and reject anything absolute or protocol-relative:

public IActionResult Login(string returnUrl)
{
    // ... authenticate the user ...

    if (!Url.IsLocalUrl(returnUrl))
        returnUrl = "/dashboard";

    return Redirect(returnUrl);
}

Url.IsLocalUrl accepts /dashboard but rejects https://evil.example, //evil.example and the backslash and userinfo tricks above. ASP.NET Core's LocalRedirect applies the same rule and throws instead of redirecting when the URL is not local.

Better still, do not accept a URL at all. Map a short token to a destination the server owns, so there is no redirect target to tamper with. In Express:

const DESTINATIONS = new Map([
  ['dashboard', '/dashboard'],
  ['billing', '/account/billing'],
]);

app.get('/after-login', (req, res) => {
  res.redirect(DESTINATIONS.get(req.query.next) ?? '/dashboard');
});

When you genuinely must redirect off-site, parse the value with a standard URL parser and compare the parsed scheme, host and port against an explicit allowlist rather than pattern-matching the string:

const ALLOWED_HOSTS = new Set(['docs.example', 'status.example']);

function safeExternalUrl(value) {
  let url;
  try {
    url = new URL(value);
  } catch {
    return null;
  }
  if (url.protocol !== 'https:' || url.username || url.password) {
    return null;
  }
  return ALLOWED_HOSTS.has(url.host) ? url.href : null;
}

url.host includes any non-default port, so https://docs.example:8443 does not slip through, and redirecting to the normalized url.href rather than the raw input means the browser receives exactly the URL that was checked. For OAuth, require redirect_uri to exactly match a pre-registered value; RFC 9700 makes exact string matching a requirement for authorization servers.

Fixes that do not hold

  • Blocking http:// and https://: protocol-relative, backslash and missing-slash forms are still absolute destinations to a browser.
  • Prefix, suffix or substring checks: app.example.evil.example and [email protected] both contain your domain.
  • Validating before the last decode: if another layer decodes the value again, %2F%2Fevil.example becomes //evil.example after your check has passed.
  • Unanchored host regular expressions: /app\.example/ matches inside an attacker's hostname just as easily.
  • Fixing only server-side redirects: client-side location assignments and meta refresh tags read the same parameters.
  • Allowing every subdomain: a user-content or abandoned subdomain then becomes a trusted landing page for the attacker.

A developer review checklist

  1. Find every redirect sink: Redirect(), res.redirect, Location and Refresh headers, meta refresh tags and client-side location assignments.
  2. Prefer local paths validated by a framework helper such as IsLocalUrl or LocalRedirect.
  3. Map short identifiers to server-owned destinations instead of accepting URLs.
  4. For required external destinations, parse the URL and compare scheme, host and port exactly against an allowlist; reject userinfo.
  5. Register exact OAuth redirect URIs and compare them by exact string.
  6. Reject control characters such as CR and LF in any value that reaches a redirect.

References

Module: Open Redirect. How it probes: Absolute, protocol-relative, backslash, missing-slash, multi-slash, userinfo and encoded targets in query parameters named like redirects or already carrying a URL or path. How it confirms: A fresh random host is injected again in several shapes, and only a 3xx Location or Refresh header that resolves to that host, with a benign control that does not, confirms the finding. A finding moves from Possible to Confirmed only after this check. Reported as CWE-601 · ATT&CK T1189, T1190 · SARIF 2.1.0.
How SelfSec proves this one
Module
Open Redirect
How it probes
Absolute, protocol-relative, backslash, missing-slash, multi-slash, userinfo and encoded targets in query parameters named like redirects or already carrying a URL or path.
How it confirms
A fresh random host is injected again in several shapes, and only a 3xx Location or Refresh header that resolves to that host, with a benign control that does not, confirms the finding.
Reported as CWE-601 · ATT&CK T1189, T1190 · SARIF 2.1.0

A reflected response alone is not enough to promote a Open Redirect finding. The classical engine has to confirm the behavior before it reaches the report. See the detection engine

SelfSec scanner

Find Open Redirect in your own app

Reading about the class is one thing. SelfSec tests for it against an application you are authorized to assess, and only calls it real when independent evidence agrees.

Join the launch list