← Glossary

What Is Session Management?

Session management is the set of server-side rules that create a session after authentication, recognise it on later requests, renew or expire it over time, and end it on logout or revocation. The cookie that carries the session identifier is only the visible edge of that lifecycle.

Updated:

Session management is how a web application keeps track of who is making a series of requests after it has verified their identity once. HTTP has no memory between requests, so applications commonly create a record of authenticated state, hand the browser a reference, and use it to associate subsequent requests with that session. Other designs carry signed claims in the token itself. The reference is usually a session identifier in a cookie, but the identifier is the least interesting part. The substance lies in the server's decisions: when to create a session, what to bind to it, how long it may live, when to replace its identifier, how many may exist at once, and what must happen when it ends. Those decisions form a session lifecycle, and getting them wrong is a classic source of account takeover.

Creating and Binding Session State

A session begins when the server decides a request deserves one, typically after a successful login, though anonymous sessions for shopping carts or preferences follow the same mechanics. The server generates an identifier, stores a record keyed by it, and sends the identifier to the client. The OWASP Session Management Cheat Sheet sets two requirements for the identifier: it specifies at least 64 bits of entropy to resist guessing, and its value must be meaningless so it reveals nothing about the user or the system.

The server-side record holds whatever the application needs to associate with the person: user identity, roles, authentication method, creation time and last activity. It may also record attributes of the client such as IP address and User-Agent for later comparison. OWASP cautions that these bindings are useful for detecting hijacking but cannot be trusted as a defence, because an attacker on the same network or through the same proxy can share the victim's address and can copy the User-Agent string. These comparisons can flag changes, but cannot prove that the same person is present.

Timeouts, Rotation and Concurrent Sessions

Session expiration is governed by several clocks running at once.

  • Idle timeout ends a session after a period without activity. OWASP cites common ranges of two to five minutes for high-value applications and fifteen to thirty minutes for low-risk ones.
  • Absolute timeout ends a session after a fixed period regardless of activity, forcing re-authentication; a working-day application might use four to eight hours.
  • Renewal timeout replaces the identifier periodically during a long session so that any copied identifier has a limited useful life.

Session token rotation is also required at specific moments. OWASP states that the identifier must be regenerated after any change in privilege level, with login being the most important case. The reason is session fixation: if an attacker can place a known identifier into a victim's browser before login, and the application keeps that identifier after authentication, the attacker now holds a valid authenticated session. Issuing a fresh identifier at login breaks the link. Rotation introduces a race, which OWASP acknowledges: during the brief overlap when an old identifier is still accepted, an attacker who already holds it might win the renewal, so grace periods should be short and all identifiers from the same logical session should be revoked together on logout.

Whether a user may hold several sessions at once is an application decision. Allowing concurrency suits people who use a phone and a laptop; forbidding it suits high-security systems that want a new login to terminate the old session or to ask the user which to keep. Either way, the application should be able to list and terminate a user's active sessions, because that capability is what makes revocation possible.

Logout, Revocation and Where State Lives

Ending a session means more than deleting a cookie. The browser can discard its copy of the identifier, but the server-side record remains valid until the server invalidates it, and a copied identifier would keep working. OWASP therefore requires logout revocation on the server at minimum, and recommends a visible logout control so that security-aware users can end sessions deliberately. Administrative revocation covers the other cases: a reported compromise may call for revoking all account sessions, while password changes and anomalies need an explicit policy for revocation and re-authentication. Deleting only the current browser cookie cannot implement an account-wide response.

Where session state is stored shapes what revocation can do. A server-side store, whether in memory, a database or a cache, holds the authoritative record and can be edited or deleted at will, with a validation lookup or coordinated cache access when checking the session. OWASP notes that storing random tokens verbatim is acceptable in a tightly controlled store and suggests storing a one-way hash if read-only disclosure of the store is a concern. Stateless designs put signed claims in the token itself so the server needs no lookup, but then the server cannot revoke a token before it expires without an additional mechanism such as a denylist, an account/session version check or key revocation. These choices reintroduce state or have broader effects than revoking one token. The client side also matters: OWASP advises against keeping session identifiers or tokens in localStorage or sessionStorage, where any cross-site scripting flaw can read them, and prefers HttpOnly cookies.

The Cookie's Role in the Lifecycle

The cookie is the carrier, and its attributes should match the lifecycle decisions. Secure limits it to encrypted transport, HttpOnly keeps it from scripts, and SameSite Strict or Lax reduces its exposure to cross-site requests, with OWASP treating SameSite as defence in depth rather than a replacement for CSRF tokens. A session cookie without an expiry attribute lasts until the browser decides the session is over, which some browsers extend across restarts through session restore, so the server's own timeouts must not rely on the browser deleting anything. Persistent remember-me cookies carrying a long-lived token are a distinct mechanism that should map to a separate, lower-trust server-side record.

Common Failures and Their Limits

Lifecycle failures can expose a session even when its cryptography is sound: an identifier not rotated at login, a logout that cleared the cookie but not the record, an idle timeout never enforced by the server, or tokens in a web storage area that a script could read. Correct session management does not prevent every compromise. A stolen device, a malicious browser extension or a real-time phishing intermediary that captures the live session can still act as the user. What a sound lifecycle provides is bounded damage: short windows, revocable records, and the ability to answer, for any request, which session it belongs to and whether that session should still exist.

Frequently asked questions

Is deleting a cookie enough to revoke a session?

No. Deleting the cookie removes the browser's copy of the identifier, but the server-side record stays valid until the server invalidates it. Any copied identifier would keep working. Logout and revocation must act on the server.

Why rotate a session ID after login?

To defeat session fixation. If an attacker can plant a known identifier before login and the application keeps it afterwards, the attacker holds an authenticated session. Issuing a new identifier at login, and at any privilege change, breaks that link.

How do idle and absolute timeouts differ?

An idle timeout ends a session after a period without requests and resets with activity. An absolute timeout ends it a fixed time after creation regardless of activity. Applications usually enforce both, with ranges chosen by the sensitivity of the data.

Should session tokens be stored in localStorage?

Avoid persistent session tokens in script-readable web storage when an HttpOnly cookie fits the architecture. XSS running in the same origin can read that storage. HttpOnly reduces direct token theft, but does not stop injected scripts making authenticated requests; CSRF controls also remain necessary.

Can a session be bound to an IP address?

It can be recorded and compared to detect hijacking, but it is not a reliable defence. Users behind the same NAT, hotspot or proxy share addresses, mobile users change addresses legitimately, and an attacker on the same network can match the victim's address.