Skip to main content
MediumAI codeOWASP A01:2021CWE-601

How to fix: Open Redirect via User-Controlled URL

A redirect was detected that may use a user-controlled URL parameter without validation. AI-generated authentication flows frequently implement 'redirect after login' with an unvalidated redirect_to or next parameter.

Why it matters

Open redirects enable phishing by forwarding users from your trusted domain to a malicious site. Attackers craft URLs like your-site.com/login?next=http://evil.com to steal credentials or session tokens.

AI tools generate login flows with `const redirectUrl = searchParams.get('next'); ... redirect(redirectUrl)` without validating that the URL stays on the same origin. This is a direct phishing enabler.

How to fix it

  1. 1Validate that redirect URLs are relative paths or match your domain explicitly.
  2. 2Reject any redirect URL that starts with http://, https://, //, or contains a @.
  3. 3Use a whitelist of allowed redirect destinations.
  4. 4For post-login redirects, store the intended URL in the session, not in the URL.

Code examples

Safe redirect validation

TypeScript
function isSafeRedirect(url: string): boolean {
  // Reject absolute URLs and protocol-relative URLs
  if (/^(https?:)?\/\//i.test(url)) return false;
  // Only allow paths starting with /
  if (!url.startsWith('/')) return false;
  // Reject paths with protocol-like patterns
  if (url.includes('://') || url.includes('@')) return false;
  return true;
}

const next = searchParams.get('next') ?? '/dashboard';
return redirect(isSafeRedirect(next) ? next : '/dashboard');

References

Detected automatically by VulnRadar. The check id is vibe-open-redirect, stable across every scan so you can filter or diff on it.

See every ai code check

Questions

How severe is Open Redirect via User-Controlled URL?
VulnRadar rates this medium severity in the ai code category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id vibe-open-redirect, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Open Redirect via User-Controlled URL map to?
It maps to CWE-601. In the OWASP Top 10 it falls under A01:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for open redirect via user-controlled url

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Open Redirect via User-Controlled URL fix | VulnRadar