Why AI tools produce this: AI coding tools produce this regularly, typically when prompted for a shortcut or a quick fix.
Why this matters
Sandboxed iframes, documents loaded from file://, and certain cross-origin redirects send Origin: null. Adding the string 'null' to your CORS policy therefore grants cross-origin access to ANY such context (including an attacker's sandboxed iframe), which defeats the same-origin policy. Combined with credentials this becomes a CSRF / data-exfiltration primitive.
The 'null' origin is not a safe sentinel and cannot be trusted: it is not bound to any host. Remove it from the allowlist entirely.
Use an explicit allowlist of real, trusted origins instead:
import cors from 'cors';declare const res: { setHeader: (k: string, v: string) => void };// ok: auth.cors.null-origin -- single explicit real originexport const singleOrigin = cors({ origin: 'https://app.example.com', credentials: true,});// ok: auth.cors.null-origin -- allowlist array with only real originsexport const allowlistOrigin = cors({ origin: ['https://app.example.com', 'https://admin.example.com'], credentials: true,});// ok: auth.cors.null-origin -- `null` keyword (not the string), out of scopeexport const keywordNullOrigin = cors({ origin: null, credentials: true,});// ok: auth.cors.null-origin -- static real origin in a manual header writeexport function manualRealOrigin() { res.setHeader('Access-Control-Allow-Origin', 'https://app.example.com');}
Suppressing this rule
If a finding is a genuine false positive, scope the suppression to the exact line and leave a reason, never disable the rule project-wide. Disable directives are line-scoped by design.