Security rules
NGB081: Permissive CORS with credentials
Reports server code and hosting configuration that let any website make credentialed cross-origin requests and read the responses: Access-Control-Allow-Origin set from the request's Origin header without an allowlist check, cors({ origin: true, credentials: true }) (also enableCors / register(fastifyCors, …)) or an origin callback that always allows, combined with Access-Control-Allow-Credentials: true — and Access-Control-Allow-Origin: null with credentials..
| Property | Value |
|---|---|
| Rule ID | NGB081 |
| Category | Angular SSR security |
| Default severity | high |
| CWE | CWE-942, CWE-346 |
| Built-in presets | recommended: error, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports server code and hosting configuration that let any website make credentialed cross-origin requests and read the responses: Access-Control-Allow-Origin set from the request's Origin header without an allowlist check, cors({ origin: true, credentials: true }) (also enableCors / register(fastifyCors, …)) or an origin callback that always allows, combined with Access-Control-Allow-Credentials: true — and Access-Control-Allow-Origin: null with credentials.
Why it matters
With credentials allowed, the browser attaches the victim's cookies to the cross-origin request and lets the requesting page read the response. Reflecting the caller's Origin (or allowing null, which sandboxed iframes and data: pages send) therefore lets any malicious website read every authenticated API response of a logged-in user — profile data, CSRF tokens, payment details — and act on their behalf.
Detection behavior and supported patterns
res.setHeader('Access-Control-Allow-Origin', req.headers.origin)(alsores.set/header/append,req.get('origin'), a local variable holding it) together withAccess-Control-Allow-Credentials: truein the same function — not reported when a dominating condition checks the origin (ALLOWED.includes(origin),origin === …, regex test)cors({ origin: true, credentials: true }),{ origin: (origin, cb) => cb(null, true), credentials: true },app.enableCors({ … }),fastify.register(cors, { … })Access-Control-Allow-Origin: nullwithAccess-Control-Allow-Credentials: truein server code or hosting configs (firebase.json,vercel.json,staticwebapp.config.json,_headers)
Example
app.use(cors({ origin: true, credentials: true }));Safer alternative
app.use(cors({ origin: ['https://app.example.com'], credentials: true }));Remediation
Allow credentials only for an explicit list of trusted origins: cors({ origin: ['https://app.example.com'], credentials: true }), or check ALLOWED_ORIGINS.includes(origin) before echoing it (and add Vary: Origin). Never allow null.
False-positive considerations
- APIs that intentionally serve any origin with cookies but expose only public data are reported; drop
credentialsfor them.
Known limitations
Access-Control-Allow-Origin: *with credentials is not reported: browsers refuse that combination, so it fails closed.- Allowlist checks in other functions (CORS middleware factories, config objects) are not seen; reflection guarded only elsewhere is reported.
- Reflection without
Access-Control-Allow-Credentials: trueis not reported (it is equivalent to*).
References
Run it
ngbastion explain NGB081