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,HttpOnlyandSameSitelimit 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=1parsing in Tomcat and Jetty (Cookie Chaos, cookie smuggling). Tokens kept inlocalStorageare 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
expwhatever 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,Domainscope,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
alghandling (see JSON Web Tokens). - Token storage on the client:
localStorageorsessionStoragevsHttpOnlycookie. Is a refresh token cookie cross-site usable (SameSite=Nonetogether 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/refreshlet 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-parserturnsj:-prefixed cookie values into JSON, soauthenticationToken=j:{}reached the token provider as{}.signInhad no params schema (its deprecated sibling typedtokenas string),{}is truthy, and the Redis-backedCollection#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_tokensthen 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
HttpOnlycookies 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).
Related
- Authentication Security · Account Takeover · MFA Bypass · Password Reset Vulnerabilities · Adversary-in-the-Middle Phishing
- SameSite Cookies · Login CSRF · Cross-Site Scripting · JSON Web Tokens · JWT Secret Cracking · Remote Code Execution · Security Talks
Sources
- OWASP Session Management Cheat Sheet · original
- OWASP WSTG: Testing for Session Fixation · original
- OWASP: Session fixation attack · original
- Session Management Vulnerabilities: What Developers Get Wrong · original
- Session Hijacking in 2025: Techniques, Attack Examples and Defenses · original
- Cookie Chaos: How to bypass __Host and __Secure cookie prefixes · original
- Cookie Bugs - Smuggling & Injection · original
- From Stored XSS to Forced Login via Cookie Tossing · original
- Introducing CookieMonster: a tool for breaking stateless authentication · original
- Vvveb 1.0.9.0 authentication bypass in generateCookie() · original
- Sign In Once, Get Hacked Everywhere: The Hidden Cost of JWTs in Local Storage · original
- CVE-2025-34291: Critical Account Takeover and RCE in Langflow · original
- CVE-2026-102489 Deep-Dive: Zammad Session Leak to RCE · original
- Why Your Logout Button Doesn’t Log Out a JWT · original
- Fast Logins You Can Still Revoke: Sessions, JWTs, and Refresh Tokens Explained · original
- The cookie is a lie: handing Canarytoken sessions to infostealers (CHCon 2026) · original
- Stealing Microsoft Teams access tokens in 2025 · original
- Xen Orchestra: Empty-object login token · original