Lesson 3 of 14 · 13m
Fixation, Rotation, Expiry
Rotating the session ID at every privilege transition kills fixation; idle and absolute TTLs bound what a stolen ticket is worth.
Fixation: the login that upgrades a planted ticket
Session fixation has a three-step shape:
- The attacker obtains a valid but anonymous session ID — some servers mint one on first visit; older PHP apps with
session.use_only_cookies=0would even adopt?PHPSESSID=abcstraight from the URL. - The victim is steered into using that ID — a link, a planted cookie, a subdomain setter.
- The victim logs in. The server keeps the same ID and flips its server-side state to authenticated. The attacker, who has held the ID the whole time, refreshes and rides the authenticated session.
Nobody stole anything. The server politely upgraded a ticket the attacker printed. The countermeasure is equally mechanical: rotate the session ID at every privilege transition. The anonymous session's ID dies; a fresh ID maps to the authenticated record. The planted value becomes a dead pointer.
Every framework ships the primitive:
// express-session
req.session.regenerate(err => { /* new SID, old record gone */ });session_regenerate_id(true); // delete_old_session=true is the part people forget# Rails
reset_sessionregenerate_id without the delete flag, or regenerate-without-destroy equivalents, leaves the old ID valid — half a fix. The transition points that demand rotation: login, MFA step-up (aal1 → aal2), privilege elevation, and — cheap insurance — after password reset. Frameworks that rotate on login by default earned that default the hard way; the fixation bugs that motivated it were endemic in mid-2000s PHP/Java apps where pre-auth session IDs persisted through authentication and even appeared in URLs.
Two details that distinguish a real implementation from a cargo-culted one: rotation must happen after credential verification succeeds (rotating on failed attempts is harmless but pointless churn), and the old ID's server-side record must be deleted or invalidated — a regenerated ID that leaves the old pointer valid just doubles the ticket count.
Expiry is two clocks, and both are yours
Sessions need two independent TTLs:
- Idle timeout: N minutes since last activity. Sliding — the lookup refreshes the clock. Admin panels deserve something like 15–30 minutes; a consumer app can run longer.
- Absolute timeout: a hard wall-clock cap — 8 to 24 hours is common — after which the session dies regardless of activity. This bounds the value of a stolen token and forces periodic re-proof.
"Remember me" is not a longer session; it's a second artifact — a long-lived, rotatable token that exists solely to mint fresh sessions. Blending the two means either everyone gets logged out constantly or stolen sessions live for weeks. Cross-tab logout is the related UX edge: BroadcastChannel or a localStorage event lets one tab's logout kill the others — minor, but "I logged out and the other tab still worked" reads as a bug to users, and under theft it is one.
The wrong mental model
"The session ends when the user clicks logout" — only if you delete the server record; a destroyed cookie with a live server record is still a valid ticket if anyone copied it. And "cookie Max-Age is the session lifetime" — Max-Age is enforced by the browser. The TTL in Redis or your sessions.expires_at column is the actual control.
What to actually do
Rotate IDs on every privilege change and destroy the old record. Enforce idle + absolute TTLs server-side; make logout delete the store entry, not just instruct the browser. Keep the remember-me token separate and rotatable, and treat a presented-but-destroyed session ID hitting an authenticated route as a security event worth logging — under fixation, that request is the attacker noticing their ticket died. Cheap to implement, expensive to skip.
Keep reading
Related articles from the SudoSecurity blog.
A 257-Byte Password Is the Key: Inside the OpenSSH musl Bypass
CVE-2026-123158 lets an attacker log into a locked account on musl-based systems like Alpine by sending a password nobody set. The trigger is one number, 257, and the reason is a C library returning a single asterisk. I reproduced the exact boundary against musl 1.2.4 and read the fix.
Zero-Trust Access for Homelabbers: Teleport vs. Tailscale vs. WireGuard vs. Cloudflare Tunnel
Four tools solve four different problems that all get pitched as the same problem. Here's what each one does, where each one breaks, and the combination that covers a real homelab without paying an SSO tax you didn't see coming.
The SSO Tax: Why Self-Hosted Projects Are Gating Login Behind a Paywall
A growing list of open-core self-hosted projects, from Grafana to Planka, gate single sign-on behind an Enterprise tier. Here's which protocol actually gets paywalled, and what to check before you deploy.
Zero Trust Everything: The Complete Guide to Self-Hosting Teleport for Secure Infrastructure Access
SudoSecurity runs Teleport internally for everything — admin panel access, secure database connections, Kubernetes, and zero-trust philosophy across our entire team. This is the complete technical guide to installing, configuring, and running your own self-hosted Teleport cluster from scratch.