Security rules
NGB084: Session not regenerated after login
Reports server-side session stores (express-session style req.session) that are marked as authenticated — req.session.user = …, req.session.userId = …, req.session.authenticated = true — in a request handler that never calls req.session.regenerate().
| Property | Value |
|---|---|
| Rule ID | NGB084 |
| Category | Angular SSR security |
| Default severity | medium |
| CWE | CWE-384 |
| Built-in presets | recommended: warn, strict: error |
Confidence is reported per finding (high, medium, low) and is independent of severity. See Reading findings.
What it checks
Reports server-side session stores (express-session style req.session) that are marked as authenticated — req.session.user = …, req.session.userId = …, req.session.authenticated = true — in a request handler that never calls req.session.regenerate(). Heuristic: the property names identify a login.
Why it matters
Session fixation: if the session ID stays the same across login, an attacker who planted or learned the pre-login session ID (shared computer, a subdomain that can set cookies, a session ID in a URL) is logged in as the victim as soon as the victim authenticates. Issuing a new session ID at the privilege change closes that. express-session does not do this automatically.
Detection behavior and supported patterns
req.session.<user | userId | uid | account | authenticated | loggedIn | principal | role | isAdmin …> = valueon an Express / Node request (typed, or untypedreqnext tores)- Safe: a
regenerate()call anywhere in the same handler, including the assignment inside thereq.session.regenerate(cb)callback - Assignments of
null,undefined,false(logout) are ignored
Example
app.post('/login', async (req, res) => { const user = await auth(req.body); req.session.userId = user.id; res.redirect('/');});Safer alternative
app.post('/login', async (req, res, next) => { const user = await auth(req.body); req.session.regenerate((err) => { if (err) return next(err); req.session.userId = user.id; res.redirect('/'); });});Remediation
Regenerate the session when the user logs in (and when privileges change): req.session.regenerate(err => { if (err) return next(err); req.session.user = user.id; req.session.save(() => res.redirect('/')); });.
False-positive considerations
- Updating profile data on an already authenticated session (
req.session.user = updatedUser) is reported; such handlers are not logins — suppress them inline.
Known limitations
- Regeneration performed in a helper or middleware outside the handler is not seen.
- Session libraries with other APIs (Fastify
request.session.set(),cookie-session, JWTs) are not analyzed;cookie-sessionstores data client-side and is not subject to fixation in the same way. - Passport ≥ 0.6 regenerates sessions in
req.login(); code that only callsreq.login()is not reported.
References
Run it
ngbastion explain NGB084