Skip to main content
MediumHeadersOWASP A05:2021CWE-942

How to fix: CORS Allows 'null' Origin

Access-Control-Allow-Origin is set to the literal string 'null'. The 'null' origin is sent by sandboxed iframes, data: URIs, and some file:// contexts, so trusting it lets attacker-controlled sandboxed content bypass the intended origin restriction.

Why it matters

An attacker can host a sandboxed iframe (sandbox without allow-same-origin) that sends the Origin: null header, which this configuration trusts, granting the attacker's page cross-origin access it should never have.

Never explicitly allow 'null' as an origin. Validate the incoming Origin header against an allowlist and never return 'null' or reflect an origin that wasn't matched.

How to fix it

  1. 1Remove 'null' from any CORS origin allowlist.
  2. 2Validate the Origin header against an explicit allowlist of trusted origins.
  3. 3Never return 'null' for unmatched or missing Origin headers.

Code examples

Never allow the null CORS origin

TypeScript
// BAD: Access-Control-Allow-Origin: null
// The "null" origin is sent by sandboxed iframes and file://, allowing it
// gives untrusted sandboxed content access to your API

export function corsHeaders(req: Request) {
  const origin = req.headers.get("Origin") ?? "";
  const ALLOWED = new Set(["https://yoursite.com", "https://app.yoursite.com"]);
  return ALLOWED.has(origin) ? origin : ""; // never return "null"
}

References

Detected automatically by VulnRadar. The check id is cors-null-origin-allowed, stable across every scan so you can filter or diff on it.

See every headers check

Questions

How severe is CORS Allows 'null' Origin?
VulnRadar rates this medium severity in the headers 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 cors-null-origin-allowed, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does CORS Allows 'null' Origin map to?
It maps to CWE-942. In the OWASP Top 10 it falls under A05: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 cors allows 'null' origin

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

How to fix: CORS Allows 'null' Origin | VulnRadar