An open redirect occurs when an application takes a redirect destination from controllable input without restricting it to an approved location. A link on the genuine corporate domain can thereby send visitors directly to an external site. Common parameter names include next, returnUrl, continue and redirect.
How does an open redirect work?
After login or logout, an application may return to the previous page. If the client supplies a full URL, an attacker can insert their domain and distribute the prepared link. The browser first visits the legitimate site and then follows an HTTP redirect or client-side navigation. Variants appear in JavaScript, meta refresh, routers, error pages and chains of multiple redirects.
Why is a redirect security-relevant?
| Abuse | Explanation |
|---|---|
| Phishing | The visible link domain creates trust before redirection to a copied login page. |
| Filter bypass | Mail, chat or advertising systems allow the known domain without following the final destination. |
| Malware and fraud | Campaigns change the external target while keeping the legitimate entry URL. |
| Attack chain | A redirect bypasses another feature's destination allowlist or supports OAuth, SSRF and token attacks. |
An ordinary redirect does not directly compromise the server. Risk depends on context, trust in the domain and potential chaining. An interstitial warning can inform users but does not correct unsafe destination selection.
What is different in OAuth and SSO?
OAuth and OpenID Connect use registered redirect URIs to which the authorization server returns after login. An overly broad, prefix-checked or itself open URI can expose authorization codes or tokens to an attacker path. Validation must follow the protocol and provider's exact requirements; a general open redirect inside a client may make the chain worse. Sensitive values should not appear unnecessarily in URLs, referrers or logs.
Why do simple URL checks fail?
A string can start with https://company.example but point to company.example.attacker.tld. Other edge cases include user information before @, protocol-relative URLs with //, backslashes, encoded separators, international domain names, ports, embedded URLs and repeated decoding. Proxy, framework and browser parsers may interpret the same value differently.
How are redirects implemented safely?
- Prefer fixed targets: Map a short identifier such as
dashboardto a known internal route server-side. - Constrain relative paths: Permit paths in the application only and reject protocol-relative and absolute values.
- Parse components: If external targets are needed, compare scheme, normalized host and port exactly with a small allowlist.
- Do not trust headers: Use host and proxy headers for URL generation only from trusted infrastructure.
- Register authentication targets: Specify OAuth and SSO redirect URIs as exactly as possible.
- Log redirects: Detect unusual external targets without recording tokens or personal data.
Code example: destination identifiers instead of arbitrary URLs
Vulnerable:
return redirect($request->query('next'));
Safer:
$destinations = [
'account' => route('account.index'),
'orders' => route('orders.index'),
];
$target = $destinations[$request->query('next')] ?? route('home');
return redirect()->to($target);
If external destinations are necessary, use a URL-parser-based allowlist covering scheme, exact host and, where relevant, port. Prefix and substring comparisons are not sufficient.
How are they tested?
Testers inventory redirects in login, logout, errors, invitations and email links. They exercise absolute, relative, protocol-relative, encoded and parser-sensitive destinations and redirect chains. The browser's actual final destination matters, not only the status code. OAuth and SSO flows are tested with test accounts and controlled callbacks without exposing real tokens.
Thank you for your feedback! We will review it and optimize this content.
Do you have feedback on Open Redirect? Tell us!
Additional Services
Comprehensive IT security solutions for complete protection
Red Teaming
Simulation of real attacks on your company including people, infrastructure and processes. A comprehensive approach to testing your entire security strategy.
Learn morePhishing Exercises
Practical phishing simulations to raise employee awareness. Increase awareness and reduce the risk of successful email-based attacks.
Learn more