Open Redirects Explained: Why They Are a Security Risk
By Urlzee Team · Published · 6 min read
An open redirect is a weakness where a website will forward visitors to any address placed in its URL, without checking where that address leads. Attackers exploit it to build links that begin on a trusted domain and finish on a phishing page. The fix is to redirect only to destinations the site has approved.
What is an open redirect?
It's a redirect whose destination is controlled by whoever writes the link. Many sites have a legitimate need to send people onward. After you sign in, for example, the site returns you to the page you were on. A common way to do that is to carry the return address in the URL:
https://example.com/login?next=/account/orders
After login, the server reads next and redirects there. The flaw appears when the server accepts any value at all:
https://example.com/login?next=https://evil.example/login
If the site redirects to that without question, it has an open redirect. The weakness is catalogued as CWE-601, "URL Redirection to Untrusted Site", and OWASP refers to the category as unvalidated redirects and forwards.
How does an open redirect attack work?
The attacker borrows the reputation of the vulnerable site. A typical sequence:
- The attacker finds a redirect parameter on a well-known site that accepts any destination.
- They craft a link starting with that site's real domain and ending with their own page in the parameter, often encoded so it's harder to read.
- They send the link in an email or message that claims to come from the well-known brand.
- The recipient checks the start of the link, sees the genuine domain, and clicks.
- The genuine site immediately redirects the browser to the attacker's page, which is a copy of the brand's login screen.
- The victim, believing they're still on the real site, enters their password.
The victim did what they'd been taught and checked the domain. The redirect made that check useless.
Why are open redirects a real risk?
They undermine the most common piece of safety advice, and they can help in more technical attacks too.
- Phishing with a trusted prefix. People read the beginning of a link. So do some email filters and allowlists, which may let through anything on a reputable domain.
- Reputation damage. The trusted site's name ends up in scam messages, and its domain may be flagged by security tools.
- Token theft in login flows. In sign-in systems such as OAuth, an open redirect on an approved domain can sometimes be chained to send authorisation codes or tokens to an attacker.
- Bypassing other checks. Where an application only fetches or links to "safe" domains, an open redirect on one of those domains can be a way around the rule. This is one route to the server-side attacks described in SSRF explained.
An open redirect on its own doesn't expose the vulnerable site's data, which is why it's sometimes rated as low severity. The harm falls on the people who trust that site's name.
What does an open redirect look like in a URL?
Look for a parameter that holds another web address. The parameter names vary, but a few appear again and again.
| Common parameter names | Example |
|---|---|
url, u, link | https://example.com/out?url=https://other.example/ |
next, continue, return, returnTo | https://example.com/login?next=https://other.example/ |
redirect, redirect_uri, redir, r | https://example.com/go?redirect=https://other.example/ |
dest, destination, target, goto | https://example.com/track?dest=https://other.example/ |
The destination is frequently percent-encoded, so https://other.example/ appears as https%3A%2F%2Fother.example%2F. That's normal encoding, but it also makes the true target harder to see at a glance.
Not every such parameter is a vulnerability. Many sites validate the value properly. It only becomes an open redirect when arbitrary external addresses are accepted.
How can you tell where a link really ends up?
As someone receiving a link, check the end of the journey as well as the start. Paste the link into the URL expander, which follows each redirect from Urlzee's server and lists every hop and the final address without loading the page in your browser.
If the final domain differs from the one the link began with, and the message is asking you to sign in or pay, treat it as phishing. More ways to check are covered in how to check where a short link goes.
How do developers fix an open redirect?
Never pass user input straight into a redirect. In order of preference:
- Avoid user-supplied destinations entirely. If there are only a few possible targets, send a short key (
?next=orders) and look up the real path on the server. - Allow only relative paths on your own site. Accept
/account/orders, reject anything that resolves to another host. - Use an allowlist for external destinations. If you must redirect off-site, compare the parsed hostname with an exact list of approved hosts.
- Parse, don't pattern-match. Use the platform's URL parser and compare the resulting origin or hostname. String checks like "starts with" or "contains" are easy to fool.
- Fall back to a safe default such as the homepage when validation fails.
- Show an interstitial for unknown external links ("You are leaving example.com for other.example") if blocking isn't practical.
Here's a minimal same-site check in JavaScript. It resolves the input against your own origin and only accepts the result if it stays there:
function safeRedirectPath(input, siteOrigin = "https://example.com") {
try {
const url = new URL(input, siteOrigin);
if (url.origin !== siteOrigin) return "/";
return url.pathname + url.search + url.hash;
} catch {
return "/";
}
}
safeRedirectPath("/account/orders"); // "/account/orders"
safeRedirectPath("https://evil.example/login"); // "/"
safeRedirectPath("//evil.example/login"); // "/"
safeRedirectPath("javascript:alert(1)"); // "/"
Returning only the path, query and fragment means the redirect can't leave your site even if something unexpected slips through.
Which validation mistakes let attackers through?
Most bypasses exploit naive string checks. Each of these defeats a common shortcut:
//evil.exampleis a protocol-relative URL. It begins with a slash, so a "must start with /" check passes, but browsers treat it as another host./\evil.exampleworks the same way in browsers, which treat a backslash like a forward slash in web URLs.https://example.com.evil.examplepasses a "starts with https://example.com" check but belongs toevil.example.https://example.com@evil.exampleputs your domain in the username position. The real host isevil.example.https://evil.example/?x=example.compasses a "contains example.com" check.
Comparing the origin from a real URL parser, as in the code above, handles all of these. The OWASP Unvalidated Redirects and Forwards Cheat Sheet has guidance for other languages.
Is a URL shortener an open redirect?
Not in the sense security testers mean, though the comparison is fair to ask about. Both send visitors from one domain to another. The difference lies in where the destination comes from.
With an open redirect, the destination is written into the link itself and the site forwards to it blindly at click time. Anyone can mint unlimited links to anywhere with no record. With a shortener, the destination is submitted once, stored against a short code, and can be checked, logged, reported and switched off.
That design gives a shortener places to apply controls, and a responsible one uses them. Urlzee validates each destination before creating a link, refuses destinations on private networks and links to other shorteners, screens against blocklists, and pauses links reported through its report abuse page. The broader set of defences is described in how URL shorteners prevent abuse.
A shortener's domain also isn't a brand people associate with their bank or email account, so it doesn't lend borrowed trust in the way a well-known site's redirect does. That's a reason to keep expanding short links from unknown senders, and a reason site owners should fix redirect parameters on their own domains: your domain's reputation is what an attacker is borrowing.
What should you remember about open redirects?
For readers: the start of a link shows where the journey begins, not where it ends. When it matters, check the final destination.
For developers: any parameter that accepts a URL should be treated as untrusted input. Redirect only to places you've approved, validate with a parser, and default to somewhere harmless.
Frequently asked questions
- What is an open redirect?
- An open redirect is a flaw where a website forwards visitors to whatever address is supplied in a URL parameter, without checking it. Attackers use it to create links that start on a trusted domain and end on a malicious one.
- Why is an open redirect dangerous?
- It lends a trusted site's name to a phishing link. People and some security filters judge a link by its domain, so a link that begins with a well-known site is more likely to be clicked and less likely to be blocked.
- How do you fix an open redirect vulnerability?
- Do not redirect to arbitrary user-supplied URLs. Allow only relative paths on your own site or destinations on a fixed allowlist, validate them with a proper URL parser, and fall back to a safe default page.
- Is a URL shortener an open redirect?
- Not in the usual sense. A shortener redirects to a destination that was stored and checked when the link was created, not to whatever address appears in the URL at click time. It is still a redirect service, so it needs abuse controls.