# Session

A bounded continuity context that associates a sequence of interactions with authenticated state and other server-recognized information.

- Type: term
- Domain: Engineering & architecture
- Level: Foundational
- Last reviewed: 2026-09-23
- Original: [Soroush’s Product Wiki](<https://wiki.soroush.uk/topic/session/>)

## What it means

A session maintains continuity across otherwise independent requests. After authentication, a service commonly issues an unpredictable session identifier and stores the associated identity, assurance, timestamps, and state server-side; other designs carry protected state in a token. A cookie is one transport mechanism for a session identifier, not the session itself.

## Why it matters

Sessions let products remember authentication and workflow state without asking users to prove identity on every request. Their creation, rotation, expiry, revocation, and protection determine how long stolen access remains useful.

## When to use it

Use a session when several interactions need shared authenticated or workflow context. Keep truly stateless public requests independent, and require reauthentication rather than trusting an old session for sufficiently sensitive actions.

## How it works

1. Authenticate the actor and create a high-entropy session identifier.
2. Store minimal session state with identity, assurance, creation, activity, and expiry data.
3. Send the identifier through a protected channel, commonly a secure HTTP-only cookie.
4. Validate the session and authorize each protected request.
5. Rotate identifiers after authentication or privilege change and expire them by inactivity and maximum lifetime.
6. Revoke sessions on logout, compromise, account changes, or administrative action.

## A practical example

After login, a banking site stores an opaque session identifier in a Secure, HttpOnly cookie. It rotates the identifier after authentication, expires idle sessions, and requires fresh authentication before adding a payee.

## Where it breaks

A valid stolen session can bypass the original login factors. Distributed storage and revocation add operational cost, while long lifetimes increase exposure and short lifetimes disrupt users.

## Common mistakes

- Putting predictable identity data directly in a session identifier.
- Failing to rotate the identifier after login and enabling session fixation.
- Treating logout as a client-side deletion without server-side invalidation.
- Using one lifetime for inactivity, absolute expiry, and sensitive reauthentication.

## Visualization

[View the visualization on the website](<https://wiki.soroush.uk/topic/session/#visualization-session>)

## Sources

1. [Digital Identity Guidelines: Session Management](<https://pages.nist.gov/800-63-4/sp800-63b.html#sec5>) — NIST · Government standard
2. [Session Management Cheat Sheet](<https://cheatsheetseries.owasp.org/cheatsheets/Session_Management_Cheat_Sheet.html>) — OWASP Foundation · Security practice guidance

## Related topics

- [Authentication](<https://wiki.soroush.uk/topic/authentication/>)
- [Cookie](<https://wiki.soroush.uk/topic/cookie/>)
- [Cross-Site Request Forgery \(CSRF\)](<https://wiki.soroush.uk/topic/cross-site-request-forgery/>)
