Session Fixation
debt(d7/e3/b3/t7)
Closest to 'only careful code review or runtime testing' (d7). The detection_hints indicate automated detection is 'no' and the tool listed is semgrep — a specialist SAST tool — but the pattern (missing session_regenerate_id(true) after credential verification) requires semantic understanding of auth flow that even semgrep struggles with reliably. The absence is silent in normal operation; the vulnerability only manifests when an attacker actively exploits it, so d7 is the right anchor rather than d5.
Closest to 'simple parameterised fix' (e3). The quick_fix is 'call session_regenerate_id(true) immediately after any privilege change.' While conceptually a one-liner, the common_mistakes reveal there are typically 2–3 related fixes needed (regenerate with deletion, stop accepting URL-based session IDs, set Secure/HttpOnly flags), making it a small but multi-step fix within the auth component rather than a single-line swap.
Closest to 'localised tax' (b3). The applies_to scope is web contexts only and the fix is confined to login/auth handlers. It doesn't radiate across the whole codebase — only the authentication layer needs the pattern applied. Future maintainers only need awareness in the specific auth flow context, not system-wide.
Closest to 'serious trap — contradicts how a similar concept works elsewhere' (t7). The misconception field directly states that developers believe HTTPS prevents session fixation, which is wrong — the attack is about pre-supplying a known session ID before login, not about transport interception. This contradicts the general intuition that 'HTTPS = secure sessions.' Additionally, regenerating the ID without deleting the old session (a common mistake) leaves a false sense of security, making the obvious partial fix actually still vulnerable.
Also Known As
TL;DR
Explanation
Session fixation occurs when an application accepts a session ID supplied by the attacker (via URL parameter or cookie) and reuses it after the user logs in. The attacker sets a known session ID, waits for the victim to authenticate, then uses the same ID to access the authenticated session. Prevention: always call session_regenerate_id(true) immediately after a successful login to generate a fresh session ID and invalidate the old one.
Diagram
sequenceDiagram
participant A as Attacker
participant V as Victim
participant S as Server
A->>S: GET /login
S-->>A: Set session ID: abc123
A->>V: Send link with ?PHPSESSID=abc123
V->>S: Login with credentials + session abc123
S-->>S: Authenticates user to session abc123
Note over A,S: Attacker already has session abc123!
A->>S: Request with session abc123
S-->>A: Returns victim's authenticated session
Note over S: Fix: session_regenerate_id(true) after login
Common Misconception
Why It Matters
Common Mistakes
- Not calling session_regenerate_id(true) immediately after a successful login.
- Regenerating the ID but not deleting the old session — the old ID remains valid.
- Accepting session IDs from URL parameters (?PHPSESSID=) — only accept them from cookies.
- Setting session cookie without Secure and HttpOnly flags — the cookie can be read over HTTP or via JavaScript.
Code Examples
// Session ID never regenerated after login — attacker can pre-set it
session_start();
$_SESSION['user_id'] = $user->id; // same session ID before and after auth
session_start();
// After successful authentication — always regenerate
session_regenerate_id(true); // true = delete old session file
$_SESSION['user_id'] = $user->id;
// Also regenerate on privilege escalation (sudo/admin mode)