What this thread does
Do first: map the trusted HTTPS proxy before enabling cookie.secure: true.
Short answer
As of November 2026, this path uses Express 5.3.0, express-session 1.19.0 and connect-redis 11.0.0 (2026-11-16; checked 2026-11-23), which requires ESM imports and Node.js 22 or later. Store identity server-side in shared Redis, rotate the session ID after authentication, and require both idle and absolute expiry.
Choose / don't choose
- Shared server session: choose for immediate revocation across replicas; don't choose default MemoryStore for production (session API).
- Same-origin login: choose
sameSite: 'lax'; don't copy that assumption into a cross-site frontend.sameSite: 'none'requires Secure plus a separate CORS/CSRF design (cookie contract). - Redis adapter: choose a compatible client; It only supports redis (v5 and later) now rather than ioredis (releases).
Not for: choosing JWT versus database sessions; see jwt-or-database-session-cookie-for-my-app-and-how-logout-works.
Settings that matter
| Setting or flag | Value / default | Applies to | Source |
|---|---|---|---|
cookie.httpOnly | true (default) | express-session 1.19.0 | API |
cookie.secure | true on deployed HTTPS; default false | express-session 1.19.0 | API |
cookie.sameSite | 'lax' for this same-origin flow; default false means omit attribute | express-session 1.19.0 | API |
cookie.maxAge | Milliseconds; 60000 is the API's short demonstration, default null | express-session 1.19.0 | API |
store | new RedisStore({client: redisClient}); connect client before serving | connect-redis 11 | adapter |
resave, saveUninitialized | Both false for this touch-capable store | session 1.19.0 / RedisStore 11 | adapter |
rolling | true for sliding idle cookies | session 1.19.0 | rolling |
trust proxy | 1 only for a topology with exactly one trusted proxy hop; otherwise explicit trusted proxy addresses | Express 5.3 | proxy guide |
ttl, disableTouch, disableTTL | Cookie expiry supplies TTL; otherwise 86400 seconds; both disabling flags default false | connect-redis 11 | TTL |
Order of operations
1. Connect Redis before listening (client connection); install session middleware before protected routes. Replicas share the store and signing-secret configuration. Credential validation, authorization and CSRF protection remain prerequisites. 2. Validate credentials, call req.session.regenerate, wait for its callback, set authenticated identity and timestamps in the new session, then req.session.save and wait before redirecting. On any store error fail the login response (1.19 login example). 3. On logout, call req.session.destroy, wait for successful deletion, then res.clearCookie with the same cookie path/domain/options. Do not report successful revocation if store deletion fails (destroy, clearCookie). 4. Inspect the login response's Set-Cookie, browser rejection reason and next request's Cookie; repeat across replicas, then attempt an old ID after logout and at each expiry boundary. Expect denial after server-side invalidation.
Known failures and fixes
| Error (short quote) | Cause | Fix | Source |
|---|---|---|---|
Set-Cookie not added in response headers when secure=true | App may see proxy-to-Node HTTP as insecure | Preserve Secure; inspect req.secure, trusted hop configuration and proxy-overwritten forwarded protocol | domcolella, May 6, 2024, #983, proxy guide |
race conditions | Unnecessary resaves can overwrite concurrent session changes | Use resave: false with touch-capable RedisStore; serialize sensitive session mutations where needed | session API, adapter |
The #983 symptom report does not establish a safe reason to disable Secure. Cookie and Redis lifetimes differ in units: milliseconds versus seconds. Manual save() before response-end may use the previous cookie expiry; account for the adapter's documented timing when customizing TTL.
Missing
- No universal timeout meets every application's risk model; the stated policy is a bounded example. This card does not provide credential validation or a cross-site authentication design.
Checked
2026-11-12; Sources read: release notes, Express/session API, versioned README, Redis client/adapter, OWASP and domcolella’s report. No login or store operations were run.
Started from a post by @Express.js, packaged by the editor. Original post