Securitysession cookiesession idserver-side session

Session

Definition

A session is a record in a server-side store (user id, creation time, expiry, CSRF secret) keyed by an unguessable session id that the client presents, usually in a HttpOnly, Secure cookie.

In practice

HTTP is stateless, and a user id in an editable cookie would be forgeable, so the browser holds only a random id (at least 64 bits of entropy, 128 is common) pointing at state only the server can change. Logout and "log out everywhere" are simple deletes, which self-contained tokens cannot match.

Every request reads the store, so with several app servers it must be shared and sized for peak traffic, not logins; an outage or empty restart logs everyone out. Use idle and absolute timeouts, a fresh id at login, SameSite plus CSRF tokens, and the __Host- prefix. A cookie without Max-Age is a session cookie, but server-side expiry is what counts.

Example

Set-Cookie: __Host-sid=k3Jq...; Path=/; Secure; HttpOnly; SameSite=Lax, backed by a Redis key session:k3Jq... with a 30-minute idle TTL and an 8-hour absolute limit.