Open redirect vulnerabilities occur when a web application accepts a user-controlled URL in a parameter (such as `?next=`, `?returnTo=`, or `?redirect_uri=`) and sends an HTTP `302` redirect or client-side `window.location` navigation to an arbitrary external domain. While sometimes dismissed as low-severity in isolation, open redirects frequently act as the critical pivot in OAuth account takeover and phishing chains.
How attackers chain open redirects with OAuth 2.0 and SSO
In an OAuth 2.0 or OpenID Connect login flow, the identity provider redirects the user's browser back to a registered `redirect_uri` with an authorization `code` or token in the URL. When an application's OAuth client configuration or post-login handler is combined with an open redirect, three escalation paths emerge:
- Referer leakage of authorization codes: if the OAuth callback page or a permissive path-matching `redirect_uri` bounces through an open redirect on the trusted domain, the browser can forward the sensitive `?code=...` URL in the HTTP `Referer` header to an external attacker host.
- Bypassing URL allowlists in SSRF: internal URL-fetching services that verify a link starts with `https://trusted.example.com` can be tricked into fetching internal metadata if the HTTP client follows an open redirect on `trusted.example.com`.
- High-trust phishing links: a link that begins with `https://login.yourcompany.com/auth?next=https://lookalike-login.example` displays your authentic domain and TLS certificate on initial inspection, lowering user suspicion before landing on a credential-harvesting page.
How to validate redirect targets safely
Whenever possible, avoid passing full URLs in redirect query parameters; use short symbolic route keys (such as `?next=billing`) mapped to known paths on the server. When dynamic relative paths are needed, verify that the destination starts with a single forward slash (`/`) followed by an alphanumeric character—explicitly rejecting protocol-relative URLs (`//attacker.com`), backslash tricks (` /\attacker.com`), and control characters—or parse the URL with `new URL(input, BASE_ORIGIN)` and verify that `parsed.origin === BASE_ORIGIN`.
Parse redirect targets against your canonical origin and verify that parsed.origin matches exactly before issuing a 302 redirect or client navigation.