Session Management

Session management flaws let an attacker obtain, plant, forge or keep a valid session. Examples: an ID that’s guessable or never rotated, a cookie that’s readable or injectable, a stateless token signed with a weak key, or a session that survives logout and password change.

How it works

After login, the session identifier (or signed token) is the user. Whoever presents it is authenticated, and MFA has already been satisfied (OnSecurity). Security rests on five properties:

  • Unpredictable: IDs come from a CSPRNG with at least 64 bits of entropy, carry no meaningful content, and use a generic cookie name (OWASP).
  • Rotated at privilege change: if the pre-login ID survives authentication, an attacker who planted it beforehand (URL token, injected cookie, XSS, <meta> Set-Cookie) shares the victim’s authenticated session. This is session fixation, as opposed to hijacking, which steals an ID after login (OWASP, WSTG).
  • Confined: Secure, HttpOnly and SameSite limit theft over the network, through XSS and cross-site use (OnSecurity). The __Host- and __Secure- prefixes are meant to stop subdomains overwriting cookies (cookie tossing). Browser/server parsing differentials defeat them: Unicode whitespace that Django or ASP.NET strip from cookie names, and legacy $Version=1 parsing in Tomcat and Jetty (Cookie Chaos, cookie smuggling). Tokens kept in localStorage are readable by any XSS on any app that shares them (JWTs in localStorage).
  • Unforgeable: stateless sessions (JWTs, Flask, Django and Laravel signed cookies) move the risk to the signing key and the verification code. Weak or default secrets let attackers re-sign modified sessions (CookieMonster). Loose comparison of cookie hashes allows magic-hash forgery (Vvveb).
  • Revocable and expiring: idle and absolute timeouts, server-side invalidation on logout, and the ability to kill all sessions (OWASP). A self-contained JWT stays valid until exp whatever the user does. Revocation needs short access tokens plus revocable refresh tokens, versioning or a denylist (JWT logout, revocable fast logins).

Theft vectors now go beyond the web app itself. Infostealer malware harvests browser cookies at scale (CHCon talk). Desktop apps keep tokens on disk under DPAPI keys that the local user can recover (Teams tokens). AiTM proxies capture the post-MFA cookie (Adversary-in-the-Middle Phishing). Network sniffing, XSS, MITM and malware remain the core hijacking routes (Seraphic).

What to check

  • Compare the session ID before and after login, and after privilege changes (role switch, MFA completion). Does it rotate?
  • Will the app accept a session ID you supply (URL parameter, injected cookie) and authenticate it?
  • ID quality: length, randomness (sample many), embedded data, framework-revealing cookie name.
  • Cookie attributes: Secure, HttpOnly, SameSite, Domain scope, Path, prefixes. Can a sibling subdomain set a cookie that the app trusts?
  • Server cookie parsing: does it normalize names (whitespace, case, legacy $Version) differently from browsers?
  • Stateless tokens: identify the format, test for weak, known or default signing keys, and check alg handling (see JSON Web Tokens).
  • Token storage on the client: localStorage or sessionStorage vs HttpOnly cookie. Is a refresh token cookie cross-site usable (SameSite=None together with permissive CORS)?
  • Lifecycle: does logout invalidate server-side (replay the old cookie or token)? Is there an idle and absolute timeout? Is “log out everywhere” real? Are sessions revoked on password reset?
  • Do session IDs leak via URLs, logs, error messages, WebSocket or debug responses?

Notable cases

  • Zammad (CVE-2026-102489): a crafted WebSocket request leaked session cookies in error messages. An admin session was then used to overwrite the reset-email template, giving RCE through ERB. Used in the DIVD incident (Horizon3).
  • Langflow (CVE-2025-34291, CVSS 9.4): a refresh-token cookie with SameSite=None, permissive CORS and an unauthenticated /api/v1/refresh let attackers steal access tokens, leading to ATO and then RCE via code validation (Obsidian).
  • Cookie Chaos: __Host- and __Secure- bypasses through server-side name normalization (Django .strip(), ASP.NET) and legacy parsing (Tomcat, Jetty) (PortSwigger).
  • Cookie tossing for forced login: stored SVG XSS on an S3-backed subdomain was used to toss session cookies onto the main app (writeup).
  • Vvveb <1.0.9.0: generateCookie() compared MD5 cookie hashes loosely, so “0e” magic-hash cookies forged persistent logins (advisory).
  • Xen Orchestra (GHSA-2r3w-c2vx-fv5g): cookie-parser turns j:-prefixed cookie values into JSON, so authenticationToken=j:{} reached the token provider as {}. signIn had no params schema (its deprecated sibling typed token as string), {} is truthy, and the Redis-backed Collection#first({}) treated an empty object as an unfiltered lookup returning the first stored token; if unexpired, the request authenticated as its owner (bypassOtp: true), and /rest/v0/users/me/authentication_tokens then listed reusable token IDs. Admin impact reaches code execution on managed pools and root on XCP-ng hosts (advisory). Type-check session identifiers as strings before any lookup; never pass a parsed object to a query builder. See NoSQL Injection.
  • CookieMonster: a scanner that decodes and unsigns Django, Flask and Laravel sessions and JWTs built with weak secrets, then re-signs them (ian.sh).

Defenses

  • Use the framework’s session manager. Generate IDs with a CSPRNG (≥64 bits) and give the cookie a generic name (OWASP).
  • Regenerate the ID unconditionally at login and on every privilege change. Reject IDs the server didn’t issue (OnSecurity, WSTG).
  • Set Secure; HttpOnly; SameSite=Lax/Strict, use __Host- with host-only scope, and use HSTS. Make sure the server parses cookie names exactly (no trimming or normalization), and keep the server stack patched (PortSwigger).
  • Keep tokens in HttpOnly cookies rather than web storage (writeup).
  • Use strong, rotated signing keys and constant-time strict comparison (CookieMonster).
  • Apply idle and absolute timeouts, server-side invalidation on logout, and revoke-all on credential change. For JWTs, use short access tokens with revocable refresh tokens or a version or denylist check (writeup).
  • Consider binding sessions to client properties and detecting anomalies such as IP or User-Agent changes (OWASP).
  • Deploy session-cookie canaries to detect infostealer replay (CHCon).

Sources