5 lessons

Sessions & Tokens

How the server keeps remembering you: session IDs, cookie attributes, hijacking, rotation, revocation, and what JWTs actually buy and cost.

AssetThreatAttack SurfaceTrust BoundaryVulnerabilityExploit PathImpactMitigationDefense in DepthResidual Risk

Every lesson below identifies the asset, attacker capability and boundary before naming the vulnerability. Controls are split into prevention, detection and recovery; residual risk is explicit.

Sessions
▶ lab

Authentication happens once; the session is what makes the next thousand requests work — a random opaque identifier that maps to server-side state you can inspect, expire and revoke.

Boundary · The boundary between an anonymous request and an identified one, re-crossed on every single request for the life of the session.
Cookies and Their Attributes
▶ lab

Six attributes decide whether a cookie is a reasonable place to keep a session or a liability: `Secure`, `HttpOnly`, `SameSite`, `Domain`, `Path` and lifetime — and each one maps to a specific attack.

Boundary · The browser's origin and site model, which is the only thing deciding who can read the cookie and which requests carry it.
Session Hijacking
▶ lab

The attacker does not need the password: possession of the session token is possession of the account, and every defense is either about preventing the token from escaping or about limiting what it is worth once it has.

Boundary · The boundary between the user's browser and everywhere else — a boundary that leaks through logs, referrers, third-party scripts and shared screens.
JWT — What It Is and What It Costs
▶ lab

A signed, self-contained token that lets a service verify a claim without a lookup — which buys statelessness and pays for it with revocation you have to engineer separately.

Boundary · The verification boundary: everything after it treats the claims as true, so the correctness of the check is the whole of the security.
JWT Failure Modes
▶ lab

The specific ways token validation goes wrong — trusting the header's algorithm, skipping issuer and audience, over-long expiry, treating signed as confidential — and the verification routine that closes all of them.

Boundary · The verification function — a boundary that is a handful of lines and is trusted absolutely by everything behind it.