Skip to main content
MediumClient-sideOWASP A01:2021CWE-601

How to fix: Client-Side Open Redirect via location Assignment

A window.location or document.location assignment was found using URL parameters or hash values without validation. Client-side open redirects are exploitable for phishing even without server-side participation.

Why it matters

Attackers craft URLs that appear to be from your trusted domain but redirect users to malicious sites: yoursite.com/login#next=http://evil.com. The redirect happens in the browser after visiting your legitimate URL.

Client-side redirects using location.href = someUrlFromTheCurrentPage are open redirect vulnerabilities. The target.com URL in the browser bar gives the victim confidence they are on a legitimate site before being redirected.

How to fix it

  1. 1Validate redirect targets are relative paths or match your domain.
  2. 2Reject any value starting with http://, https://, or //.
  3. 3For post-auth redirects: store the intended destination in sessionStorage or server-side session, not in the URL.
  4. 4Never redirect to a location.hash value without validation.

Code examples

Validate redirect URL

JavaScript
function safeRedirect(url) {
  // Only allow relative paths (no protocol)
  if (!/^\/[a-z0-9\-\/]/i.test(url)) {
    url = '/dashboard'; // fallback
  }
  window.location.href = url;
}

const next = new URLSearchParams(location.search).get('next');
safeRedirect(next ?? '/dashboard');

References

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

See every client-side check

Questions

How severe is Client-Side Open Redirect via location Assignment?
VulnRadar rates this medium severity in the client-side 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 open-redirect-client-js, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Client-Side Open Redirect via location Assignment 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 client-side open redirect via location assignment

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

Client-Side Open Redirect via location Assignment | VulnRadar