What is an open redirect — and why a link on your domain lands on someone else's site

Here's a link: https://your-site.com/go?url=https://evil-site.com. It starts with your domain. The spam filter will let it through, your user will click it because the domain looks familiar. And a stranger's page opens, asking for a password.
That's an open redirect. The nastiest part: nobody "hacks" it in — you add it yourself while writing a convenient login form.
What an open redirect is
A redirect on its own is harmless: the server says "go there" and the browser goes. It becomes open when the destination comes from the user's request and is never checked.
The classic, in two lines:
// the server dutifully sends people wherever they asked
const target = req.query.url;
res.redirect(target);
Your server is a forwarding service here. For an attacker that's a gift: the link looks like yours, the domain reputation is yours, and the landing page is theirs. OWASP puts it plainly — because the server name in the link matches the real site, the phishing attempt looks far more trustworthy.
Where it appears on its own
Almost always at the login. The logic is familiar: someone clicked a private page, you sent them to sign in and remembered where to send them back.
/login?next=/dashboard
Convenient. Then someone swaps in ?next=https://evil.com/login — and after a successful sign-in the person lands on a copy of your login page saying "session expired, please enter your password again." They just typed it on the real site, so they'll type it again.
The same parameter goes by url, redirect, returnUrl, continue, back. The second common source is email: a "confirm your address" link with a forwarding URL inside. The third is "external link" fields in comments and profiles.
There's a separate flavour — forwarding inside the app (?fwd=admin.jsp). The problem there isn't phishing: by swapping the path you can slip past an access check, because one page was authorized and another was served. If you have logins and roles, take a look at how to add login properly too.
Why "check that it starts with my domain" doesn't save you
The first instinct is to write a check. Almost any naive check can be walked around:
startsWith('https://mysite.com')is beaten byhttps://mysite.com.evil.com— the string does start correctly;includes('mysite.com')is beaten byhttps://evil.com/?a=mysite.com;- "must start with a slash" is beaten by
//evil.com— the browser reads it as a protocol-relative address and leaves for another host; - a blocklist of bad domains never works: there are infinitely many domains.
Separately: even a correct server-side check is worthless if the client later does location = params.get('next'). The hole just moves into the browser.
How to fix it: three levels
Level 1, the most reliable — don't accept an address at all. Let the client pass a short identifier and let the server know where it leads: ?next=dashboard → /dashboard. There's nothing to substitute: a foreign address simply isn't in the dictionary. This is exactly what OWASP recommends.
Level 2 — an allowlist. If you really need an address, parse it with a real URL parser and compare the whole host against a list of allowed ones, not a chunk of string:
const dest = new URL(req.query.url, "https://mysite.com");
const allowed = new Set(["mysite.com", "docs.mysite.com"]);
if (!allowed.has(dest.hostname)) return res.redirect("/");
A list of allowed hosts, not blocked ones. That distinction is the whole point.
Level 3 — an interstitial page. For links meant to go outside (social profiles), show a middle screen: "you are leaving the site, destination is X." The person sees the real domain before they land on it.
Why this is worse than it looks: the OAuth combo
One more reason not to postpone. When you add sign-in with Google or GitHub, the provider doesn't send users just anywhere: you list the allowed return addresses up front, and the authorization code only goes to those. The allowlist works.
Now imagine one of those allowed addresses is a page on your site with an open redirect. The provider sees a familiar domain, the check passes, the code is delivered — and your page dutifully forwards the browser onward, to a foreign address, parameters and all. The provider's allowlist was bypassed by your own hands.
So combined with sign-in through a third party, an open redirect stops being "an ugly link": it becomes a step towards someone else's session. Audit your return pages first.
How to check your site in a minute
- Find redirects where the address comes from the request: search for
redirect(,location =,location.href =nearquery,params,searchParams. - List the parameters that feed them:
next,url,returnUrl,redirect,continue. - Put a foreign address into each one —
?next=https://example.com— and open the link. - Landed on example.com? You have an open redirect. Landed on your home page or got an error? You're fine.
And one more reason to hurry: links aren't only followed by people now. Mail filters, messenger previews and AI agents follow them automatically and judge trust by the domain — yours. Your domain becomes a tool in someone else's hand.
Is it really a vulnerability if nothing was "hacked"?
Yes. Your server's data is intact, but your users and your domain reputation are not: mail providers lower trust for domains that keep forwarding people into phishing.
What if I genuinely need redirects to partner sites?
Keep them in a server-side allowlist and update it when a partner is added. Twenty entries is a fair price for your domain not sending people to random places.
How is an open redirect different from a normal 301?
Technically it isn't — same mechanism. The difference is where the address comes from: a normal one is written in your code or config, an open one arrives in the request. If you want to tighten things up, start with security headers.
The AI Architect 2027 course: step by step from computer basics to your own app and first customers. 543 short lessons on your phone.





