Security rules
NGB043: Insecure session cookie attributes
Reports session and authentication cookies issued by server code in the repository (Angular SSR server.ts, Express handlers, BFF endpoints) without HttpOnly (high), without Secure (medium), or with SameSite=None and no Secure (medium): Express res.cookie(name, value, options), Set-Cookie headers set with res.setHeader() / res.append() / headers.append(), and cookie.serialize()..
| Property | Value |
|---|---|
| Rule ID | NGB043 |
| Category | Angular SSR security |
| Default severity | high |
| CWE | CWE-1004, CWE-614, CWE-1275 |
| 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 session and authentication cookies issued by server code in the repository (Angular SSR server.ts, Express handlers, BFF endpoints) without HttpOnly (high), without Secure (medium), or with SameSite=None and no Secure (medium): Express res.cookie(name, value, options), Set-Cookie headers set with res.setHeader() / res.append() / headers.append(), and cookie.serialize().
Why it matters
The server is the only place that can protect a session cookie. Without HttpOnly, any XSS payload reads the session with document.cookie; without Secure, it is sent over plain HTTP and can be captured; SameSite=None without Secure is rejected by modern browsers, so the intended cross-site flow silently breaks or teams fall back to weaker settings.
Detection behavior and supported patterns
res.cookie('session', id, { … })on Express / Node response typesres.setHeader('Set-Cookie', 'sid=…; Path=/'),res.append('Set-Cookie', …),headers.append('Set-Cookie', …)with constant attribute text (template literals are split into constant parts)cookie.serialize(name, value, options)from thecookiepackage- Cookie names:
session,sid,connect.sid,auth,token,jwt,access_token,refresh_token,remember_meand names classified as credentials; CSRF/XSRF cookies are ignored (they must be readable by JavaScript) - Options set to non-constant values (
secure: process.env.NODE_ENV === "production") are not reported for that attribute
Example
res.cookie('session', sessionId, { sameSite: 'none' });Safer alternative
res.cookie('__Host-session', sessionId, { httpOnly: true, secure: true, sameSite: 'lax', path: '/' });Remediation
Issue session cookies as { httpOnly: true, secure: true, sameSite: 'lax' (or 'strict'), path: '/' }, preferably with the __Host- prefix, and set them only over HTTPS.
False-positive considerations
- A
tokencookie that intentionally must be readable by client code (not a session credential) can be reported; rename it or document an exception.
Known limitations
- Cookies set by frameworks or middleware (e.g.
express-sessionconfiguration) are not analyzed. - Cookie names that are not constant are not classified.
References
Run it
ngbastion explain NGB043