An open redirect vulnerability lets an attacker use a trusted URL on your domain to send visitors somewhere else. This guide provides a reusable checklist for finding unsafe forwarding, validating destinations, testing encoded inputs, and preventing regressions in applications, short links, QR destinations, and redirect management workflows.
Overview
An open redirect occurs when an application accepts a destination from a user-controlled value and forwards the browser without adequately restricting where it can go. A common pattern looks like /redirect?url=https://example.com. If the same endpoint also accepts https://untrusted.example, an attacker can place your trusted URL in an email, message, advertisement, or social post while controlling the final destination.
The redirect may not directly expose data, but it can weaken trust in your domain and support phishing, misleading campaign links, or abuse of authentication flows. Treat every redirect destination as untrusted until it has passed validation. This applies to application routes, branded short links, affiliate link redirects, dynamic QR code destinations, domain forwarding rules, and administrator-configured routing tools.
First identify the redirect’s purpose. A fixed redirect to a known path is usually simpler to secure than a user-selectable destination. If users genuinely need to choose from several destinations, prefer an internal identifier such as /go/pricing or /r/abc123 and resolve that identifier server-side. Store the approved target in a controlled data record rather than accepting a complete URL from the request.
| Pattern | Risk | Safer approach |
|---|---|---|
Direct redirect from ?url= or ?next= | Any external destination may be accepted | Use an internal ID or strict allowlist |
| Hostname checked with a substring match | trusted.example.attacker.test may pass | Parse the hostname and compare an exact value or approved suffix boundary |
Protocol-relative URL such as //attacker.test | The browser can interpret it as an external URL | Require an approved scheme and reject protocol-relative destinations |
| Redirect value decoded only once | Encoded separators or nested URLs may bypass checks | Use a defined canonicalization process, then validate the final parsed value |
| Redirect after login using a raw return URL | Authentication flows can become phishing launch points | Use local paths, signed state, or a server-side destination record |
| Marketing or QR destination editable by many users | A legitimate link can be changed to an unsafe destination | Require permissions, validation, audit history, and a fallback destination |
Checklist by scenario
When auditing an existing redirect endpoint
- Inventory every parameter that can influence a redirect, including
url,next,return,continue, and less obvious JSON or form fields. - Trace the value from request input to the response’s
Locationheader. Check controllers, middleware, templates, database lookups, and client-side navigation. - Test whether the endpoint accepts absolute URLs, protocol-relative URLs, backslash variants, encoded characters, user-information syntax, fragments, or unexpected schemes.
- Confirm the response status is intentional. A status code does not make an unsafe destination safe; validation must happen before the response is generated.
- Check logs and analytics for unusual destinations, repeated probing, or changes to high-traffic links. Do not record sensitive query parameters unnecessarily.
When building a new application route
- Choose a fixed destination whenever possible. If the route always goes to one page, do not add a destination parameter.
- For local navigation, accept only an application-relative path beginning with a single slash. Reject values beginning with
//, containing a scheme, or resolving outside the application. - For approved external destinations, parse the URL with the framework’s URL parser. Permit only the schemes and hosts required by the feature.
- Prefer an exact host allowlist. If subdomains are allowed, enforce a real label boundary so an attacker-controlled hostname that merely contains the approved name cannot pass.
- Return a safe error page or a known fallback when validation fails. Avoid silently forwarding to a user-supplied value.
Framework-specific prevention steps
- Express or Node.js: Parse with the standard URL implementation using a known base for relative paths. Compare
protocolandhostnameagainst explicit allowlists; do not validate withincludes()or a loose regular expression. Set the redirect only after validation. - Django: Use the framework’s safe redirect checks for local URLs and its URL parsing utilities for external destinations. Keep allowed hosts separate from the application’s general host configuration; a host that can serve the application is not automatically a safe redirect target.
- Rails: Use the framework’s protection for external redirects where applicable and explicitly permit only expected hosts. Treat values from
redirect_to, session state, and query parameters as untrusted. - PHP: Parse and validate the destination before sending a
Locationheader. Avoid passing request parameters directly toheader(); also reject control characters and unexpected schemes. - Reverse proxies and redirect platforms: Review edge rules, origin rules, wildcard forwarding, and administrator APIs separately. A secure application route can still be undermined by a permissive proxy or link-management configuration.
When using branded short links, affiliate links, or QR codes
- Require authenticated, role-based access to create or change destinations.
- Validate destinations at creation time and again at update time; do not rely only on the interface to restrict values.
- Keep an audit record of who changed a destination, when it changed, and what the previous value was.
- Define a disabled-link behavior and a safe fallback. For printed QR codes, confirm that disabling or changing a destination does not create an unexpected loop.
- Review destination changes as part of campaign link management, affiliate governance, and product launch routing. A legitimate short link can become unsafe after an otherwise ordinary configuration change.
For related operational controls, see the guides to branded short-link ownership, affiliate link governance, and dynamic QR code destination management.
What to double-check
URL parsing differences are a frequent source of false confidence. Test the value as the application receives it, after any framework decoding, and after any normalization performed by a proxy or helper library. Your validation policy should state which representation is authoritative.
Use this regression-test template for every redirect input:
Input: https://approved.example/path
Expected: redirect allowed
Input: https://unapproved.example/path
Expected: rejected or sent to safe fallback
Input: //unapproved.example/path
Expected: rejected
Input: https:%2F%2Funapproved.example%2Fpath
Expected: rejected after defined decoding and parsing
Input: https://approved.example.attacker.test/path
Expected: rejected
Input: https://[email protected]/path
Expected: rejected
Input: /account/settings
Expected: allowed if local paths are supported
Input: //approved.example/path
Expected: rejected unless explicitly supported and safely normalized
Input: javascript:alert(1)
Expected: rejected
Input: approved destination with query parameters and fragment
Expected: allowed only if parameter and fragment policy permits them
Also test casing, trailing dots in hostnames, alternate ports, backslashes, whitespace, null bytes, double encoding, and nested redirect parameters. The exact cases depend on your framework and URL parser, so document the intended result rather than assuming every library behaves identically.
For a production review, confirm that approved destinations still resolve, HTTPS is used where required, query parameters are preserved only when needed, and no redirect chain or loop was introduced. A redirect-chain review is useful when several systems control the final route.
Common mistakes
- Checking for a trusted word: A substring match is not hostname validation. Parse the URL and compare structured components.
- Allowing every HTTPS URL: Encryption protects the connection; it does not establish that the destination is trustworthy.
- Validating only in the browser: Attackers can call the endpoint directly. Enforce the policy on the server or redirect platform.
- Trusting a hidden form field: Hidden fields, cookies, and session values can be modified or influenced. Validate them like query parameters.
- Using a wildcard without boundaries: An approval for
example.commust not accidentally approve a different hostname that contains that text. - Testing only ordinary URLs: Encoded, malformed, and parser-edge inputs are exactly where inconsistencies appear.
- Removing a vulnerable route without checking dependencies: Login, email, campaign, and QR workflows may depend on it. Replace it with a validated route and monitor the transition.
When to revisit
Review redirect security before each deployment that changes authentication, URL routing, middleware, proxy rules, link-management permissions, or campaign workflows. Re-run the regression template after framework upgrades, URL-parser changes, major browser behavior changes, or security advisories affecting your stack.
Add the checklist to recurring security reviews and vulnerability scans. Recheck high-value branded links, affiliate destinations, QR codes, and launch routes before seasonal planning cycles or major campaigns. If your redirect platform, DNS setup, or domain ownership changes, verify both the configuration and the fallback behavior.
The practical next step is to assign an owner, record the approved destination policy, and test one representative route from each redirect system you operate. Keep the test cases with your deployment checks so that a future change proves not only that the redirect works, but that it still works safely.