Skip to main content
HighAI codeOWASP A05:2021CWE-942

How to fix: CORS Wildcard Origin in API Handler

A CORS wildcard origin (Access-Control-Allow-Origin: *) was found combined with Access-Control-Allow-Credentials: true, or in code that explicitly sets Allow-Origin to *. AI-generated CORS configs frequently use wildcards to 'fix' preflight errors.

Why it matters

Wildcard CORS with credentials allows any website to make authenticated API calls on behalf of the user. This completely undermines same-origin policy and enables attackers to call your API from any domain using the victim's session.

AI tools commonly generate `res.setHeader('Access-Control-Allow-Origin', '*')` to fix CORS errors quickly. This is safe for truly public APIs but catastrophic when combined with cookies or when the endpoint has any authentication.

How to fix it

  1. 1Never use * with Access-Control-Allow-Credentials: true (browsers will refuse it anyway).
  2. 2Maintain an explicit allowlist of allowed origins.
  3. 3Validate the Origin header against the allowlist and reflect it only if it matches.
  4. 4For public read-only APIs: * is acceptable if there is no authentication.

Code examples

Safe CORS configuration

TypeScript
const ALLOWED_ORIGINS = new Set([
  'https://yourapp.com',
  'https://www.yourapp.com',
]);

function corsHeaders(origin: string | null) {
  const allowed = origin && ALLOWED_ORIGINS.has(origin) ? origin : '';
  return {
    'Access-Control-Allow-Origin': allowed,
    'Access-Control-Allow-Credentials': 'true',
    'Vary': 'Origin',
  };
}

References

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

See every ai code check

Questions

How severe is CORS Wildcard Origin in API Handler?
VulnRadar rates this high 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-cors-wildcard, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does CORS Wildcard Origin in API Handler 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 wildcard origin in api handler

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 Wildcard Origin in API Handler | VulnRadar