Campaign links, QR code destinations, and analytics endpoints often rely on URL forwarding. This guide provides a reusable checklist for detecting open redirect vulnerabilities, validating destinations, protecting OAuth callback flows, and preserving trustworthy link management without sending visitors to unexpected sites.
Overview
An open redirect vulnerability occurs when a website accepts a destination from a request and forwards the visitor without adequately checking where that destination leads. A typical pattern might look like https://example.com/go?url=https%3A%2F%2Fdestination.example. If the endpoint accepts any external URL, an attacker may be able to create a link that begins with a trusted domain but ultimately opens an unrelated phishing page.
This risk matters to marketing and analytics teams because redirect endpoints are commonly used for campaign tracking, short links, QR code destinations, partner links, and attribution workflows. A redirect that works correctly for a legitimate campaign can still be unsafe if its destination parameter is freely controllable. The issue is not that every external redirect is automatically malicious; the issue is that the application has not established which destinations are permitted and under what conditions.
The safest design is usually to avoid accepting arbitrary absolute URLs. Prefer a server-side identifier mapped to a known destination, or accept only a relative path on your own site. If a campaign genuinely requires external forwarding, use a narrowly maintained allowlist and validate the destination before issuing the redirect.
For implementation context, distinguish redirect behavior from security validation. A 301, 302, or 307 redirect determines how the browser and crawlers interpret the response; it does not make an unsafe destination safe. Similarly, a redirect audit should examine both the response status and the destination-control logic.
Checklist by scenario
Campaign tracking and short links
- Inventory every endpoint that accepts a destination, including branded short links, partner tracking URLs, QR code redirects, and email campaign links.
- Decide whether each link needs an external destination at all. If not, store a campaign ID and resolve it on the server.
- Prefer a relative path such as
/offers/springwhen the destination is on the same site. - For external destinations, compare the parsed hostname against an explicit allowlist. Do not approve a destination merely because its text contains your domain name.
- Record the campaign identifier, destination ID, validation result, and redirect outcome in logs without storing unnecessary personal data.
- Give an invalid or missing destination a safe fallback, such as a campaign landing page or an explanatory error page.
Keep tracking parameters separate from destination selection. UTM parameters can help attribute visits, but they should not be treated as evidence that a URL is trusted. Review the handling of query strings before launch with the guidance in How to Handle Query Strings in URL Redirects Without Losing Tracking Data.
QR codes and printed campaigns
- Point the QR code to a stable URL on a domain you control rather than embedding an unchangeable third-party URL.
- Require an approved destination record before a QR redirect can be activated.
- Test the link on mobile browsers, where the final destination and warning behavior may be less obvious to the visitor.
- Keep an audit trail when a destination changes, including who approved the change and when it takes effect.
- Retire unused campaign IDs instead of allowing them to accept arbitrary destinations later.
OAuth and login callback endpoints
OAuth redirect or callback URLs require stricter controls than ordinary campaign links. A callback should normally be registered in advance with the identity provider and matched exactly, or according to the provider’s documented narrowly scoped rules. Do not use a general-purpose ?next= parameter as an unrestricted substitute for a registered callback.
- Maintain a fixed set of approved callback URLs for each client and environment.
- Validate the callback before starting the authorization flow, not only after the user returns.
- Do not place access tokens or authorization codes in a destination URL that can be redirected to an untrusted host.
- Keep state and, where applicable, nonce protections enabled and bound to the initiating session.
- Review callback changes as application security changes, not as routine campaign edits.
Relative paths versus absolute URLs
A relative path is generally easier to constrain because it does not specify a separate scheme and host. Still, normalize and validate it: reject values that begin with a protocol, contain a scheme-relative form, or resolve outside the intended application after parsing. Absolute URLs need scheme, hostname, port, path, and encoding checks. A simple string prefix test is not sufficient.
Platform-neutral validation pattern
function safeDestination(input, requestOrigin):
if input is missing:
return approvedFallback
decoded = decode only as required by the framework
parsed = parseUrl(decoded, requestOrigin)
if parsing fails:
return approvedFallback
if parsed is relative:
if path escapes the approved application area:
return approvedFallback
return normalizedRelativePath(parsed)
if parsed.scheme is not "https":
return approvedFallback
if parsed.hostname is not in approvedHostAllowlist:
return approvedFallback
if parsed.port is not an approved port:
return approvedFallback
return normalizedAbsoluteUrl(parsed)
The exact parser and URL normalization rules depend on the framework. Use the platform’s URL parser rather than manually splitting strings. Apply validation after the framework has handled the relevant encoding layers, and test how it treats encoded delimiters, Unicode hostnames, credentials, ports, fragments, and repeated parameters.
What to double-check
Use the following test-case table during a redirect audit. These are categories to test in a controlled environment, not links to distribute.
| Input category | Example shape | Expected result |
|---|---|---|
| Approved internal path | /campaign/offer | Redirect to the normalized internal path. |
| Approved external host | https://partner.example/landing | Redirect only if the host is explicitly allowlisted. |
| Unapproved external host | https://unapproved.example/page | Use the safe fallback or reject the request. |
| Scheme-relative URL | //unapproved.example/page | Reject; do not let the browser choose the scheme. |
| Non-HTTPS scheme | javascript:... or another non-web scheme | Reject before issuing a redirect. |
| Encoded destination | Destination whose delimiters are percent-encoded | Parse and validate the effective URL, not only the raw text. |
| Look-alike hostname | A hostname that merely contains the approved domain as text | Reject unless its parsed hostname exactly matches an approved entry. |
| Credentials or unusual port | A URL containing user information or a nonstandard port | Reject unless explicitly required and approved. |
| Missing or malformed value | Empty, repeated, or unparseable parameter | Use a deterministic safe fallback. |
Also check for redirect chains and loops. A safe first hop can still lead through an unsafe or unmonitored second hop. Review the complete destination path with a redirect monitoring report and inspect server or edge logs for unexpected hosts, repeated failures, and sudden changes in campaign destinations.
Do not confuse a canonical tag with redirect security. Canonicalization helps search engines interpret duplicate URLs; it does not prevent a browser from following an unsafe forwarding instruction. Likewise, changing a 302 to a 301 does not remediate an open redirect. Status-code selection should follow the intended permanence of the campaign or website change, as explained in the guide to 301, 302, and 307 redirects.
Common mistakes
- Using a prefix check: Checking whether a string starts with
https://yourdomain.examplecan be bypassed by a different hostname that includes the same text. Parse the hostname and compare it to an exact allowlist entry. - Validating before decoding only once: Encoded characters can change how a URL is interpreted. Follow the framework’s parsing model and validate the effective destination consistently.
- Allowing any subdomain: A broad wildcard can include forgotten, user-controlled, or less-protected subdomains. Approve only the hosts and paths that the campaign actually needs.
- Returning the submitted value on error: Error pages and fallback links should not echo an untrusted destination into HTML, JavaScript, or headers without context-appropriate output encoding.
- Putting authorization flows on a marketing redirect: OAuth callbacks should have their own registered and tightly controlled configuration.
- Ignoring operational access: A technically safe endpoint can become unsafe if many users can change its destination without approval, logging, or rollback.
- Testing only the happy path: Include malformed, encoded, repeated, and unexpected inputs in automated tests, then repeat them after framework, proxy, CDN, or routing changes.
If an open redirect is found, first disable or constrain the affected endpoint where practical. Next, replace arbitrary destinations with IDs or approved paths, rotate or retire exposed campaign links when necessary, inspect logs for suspicious use, and add regression tests. Document the change in the redirect inventory so future campaign managers do not recreate the unsafe pattern.
When to revisit
Review this checklist before seasonal planning cycles, whenever a new tracking-link workflow is introduced, and whenever a QR code or short-link destination can be edited. Revisit it after a site migration, CDN or proxy change, framework upgrade, OAuth configuration change, penetration test, or incident involving phishing or unexpected forwarding.
Make the review practical:
- Export the current redirect and campaign-link inventory.
- Mark every endpoint that accepts a destination or callback parameter.
- Confirm the allowlist, fallback, access controls, and logging for each endpoint.
- Run the suspicious-input tests in a non-production environment, then verify representative production URLs.
- Check the final destination, redirect chain, status code, tracking parameters, and analytics attribution.
- Record owners, approval dates, test results, and the next review trigger.
For larger migrations or campaigns, combine this security review with a documented redirect mapping and audit checklist. Treat destination validation as part of link governance, not as a one-time developer task. A campaign link should be measurable and convenient, but it should also make the final destination predictable for the visitor and controllable for the site owner.