Security

Session expiry and rotation

A session is server-maintained login state, usually reached through an opaque identifier in a cookie. A token can instead carry claims or reference authorization state. Both require expiration and validation; neither automatically solves logout, stolen credentials or changes to permissions. Do not put credentials into URLs or logs. Do not equate base64 decoding with verification. Do not store a real session identifier in an exercise or use the following Map as a production session store. Evidence: local teaching fixture, not a production security guarantee. Source: https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html

Formal Syntax & Structure

nodejs syntaxnodejs
lookup(id, now) → user or null (lesson-defined model)

Working Example

Example Snippetnodejs
const sessions = new Map([['fixture-1',{user:'reader-a',expires:1000}]]);function lookup(id, now) {  const session = sessions.get(id);  return session && now < session.expires ? session.user : null;}console.log(lookup('fixture-1',999));console.log(lookup('fixture-1',1000));console.log(lookup('missing',0));
Node.js Reference