Use this when securing web sessions: ID generation, rotation, timeouts and logout.
Session Security
Session security protects the link between a user and their login: random, long session IDs, regenerated at login, sent only in secure cookies, with idle and absolute timeouts and server-side logout.
1. Session security: random IDs, regenerate on login, timeouts, server-side invalidation.
2. Secure cookies.
3. Bind sessions to context carefully.
4. Protect tokens in browsers.
5. Detect hijacking.
login → new session ID → cookie → expiry/logout
Context & applicabilityCommon mistakes · platform/version boundaries
Operational reference
Fast context before you go deeper.
Verification & Troubleshooting
Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.
Use the operational verification above to establish the expected state.
Capture the concrete output, symptom, packet, log or counter before changing anything.
Step 1 Session checklist Narrow the fault
- Session IDs: 128+ bits of randomness from a CSPRNG; never in URLs.
- New session ID after login and privilege change (prevents fixation).
- Cookies: Secure, HttpOnly, SameSite=Lax/Strict.
- Idle timeout (15–30 min for sensitive apps) and absolute timeout.
- Server-side invalidation on logout and password change; "log out all sessions" option.
- Detect hijacking signals (IP/device change) for high-risk actions and require re-authentication.
Step 2 Common mistakes Narrow the fault
- Session IDs in URLs.
Evidence · 1 on this Topic
Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.
- Use long random session IDs, regenerated at login.
- Use idle and absolute timeouts.
- Invalidate sessions server-side on logout.
- Session ID entropy and rotation on login — fixation protection
- Idle and absolute timeouts — expiry
- Logout invalidates server-side session — termination
ReferenceHow it works1 section · depth on demand
Decision and enforcement journey
Session Security is verified as a decision/enforcement journey: authenticated identity → session/token issuance → client storage/transport → server validation/authorization → protected request → expiry/revocation.
ReferenceImportant terms & boundaries1 section · depth on demand
In depth
Session security protects the token that keeps a user logged in after authentication. Whoever holds a valid session token is the user, so tokens must be unpredictable, protected in transit and storage, and limited in lifetime.
| Control | Purpose |
|---|---|
| Random, long session IDs from the framework | Prevent guessing |
| New session ID at login and privilege change | Prevent session fixation |
| Secure, HttpOnly, SameSite cookie flags | Limit theft and cross-site use |
| Idle and absolute timeouts | Limit window of misuse |
| Server-side invalidation on logout | Token cannot be reused |
| Re-authentication for sensitive actions | Protect high-impact operations |
Never put session IDs in URLs, where they leak into logs, browser history and Referer headers.
Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Verification history & basis
When and against what this Topic was checked. Later text edits do not count as a new check.
Authoritative/upstream documentation reviewed for bounded claims in Web Security → Session Security. Documentation verification only; this is not observed lab or production Evidence.
Basis: https://owasp.org/www-project-application-security-verification-standard/ · confidence 94%