← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · ✎ updated 7d
← Back to glossary

Session Fixation

Security CWE-384 OWASP A7:2021 CVSS 8.0 PHP 5.0+ Intermediate
debt(d7/e3/b3/t7)
d7 Detectability Operational debt — how invisible misuse is to your safety net

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.

e3 Effort Remediation debt — work required to fix once spotted

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.

b3 Burden Structural debt — long-term weight of choosing wrong

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.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

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.

About DEBT scoring →

Also Known As

session fixation attack fixed session ID

TL;DR

An attacker forces a victim to use a known session ID, then hijacks their session after they authenticate.

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

✗ Session fixation is prevented by using HTTPS. The attack works by supplying the victim with a known session ID before login — the fix is calling session_regenerate_id(true) after authentication, regardless of transport security.

Why It Matters

Session fixation lets attackers pre-set a session ID they know — once the victim logs in, the attacker uses the same ID to access the authenticated session. Regenerating the session ID on every login is the single most important session security measure.

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

✗ Vulnerable
// 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
✓ Fixed
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)

Added 13 Mar 2026
Edited 22 Mar 2026
Views 225
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S
No pings yet today
No pings yesterday
Scrapy 15 Amazonbot 14 PetalBot 14 SEMrush 12 Ahrefs 11 Perplexity 9 Bing 8 Google 6 Unknown AI 5 ChatGPT 3 Brave Search 3 Twitter/X 2 Applebot 2 Claude 1 Meta AI 1 Majestic 1 Baidu 1
crawler 104 crawler_json 3 your_context 1
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
Session general A session is how a website remembers who you are as you click from page to page. The server stores your info under a unique ID, and your browser sends that ID back with every request.

Nearly every logged-in feature on the web depends on sessions, so understanding them is essential for building or securing anything with user accounts.

💡 Start the session first, store only an ID, and regenerate that ID whenever the user's privilege level changes.

Ask Codex about Session →
⚡ DEV INTEL Tools & Severity
🟠 High ⚙ Fix effort: Low
⚡ Quick Fix
Call session_regenerate_id(true) immediately after any privilege change (login, sudo, role change)
📦 Applies To
PHP 5.0+ web
🔗 Prerequisites
🔍 Detection Hints
login/auth handler missing session_regenerate_id(true) call after credential verification
Auto-detectable: ✗ No semgrep
⚠ Related Problems
🤖 AI Agent
Confidence: High False Positives: Low ✓ Auto-fixable Fix: Low Context: Function Tests: Update
CWE-384


✓ schema.org compliant