1 How Session Fixation Works
In a session fixation attack, the attacker tricks a victim into using a session ID that the attacker already knows — then after the victim logs in, the attacker uses that same ID to take over the authenticated session.
Attack steps:
- Attacker obtains a valid (unauthenticated) session ID from the server
- Attacker sends victim a link:
https://example.com/login?sessionid=KNOWN_SESSION_ID - Victim logs in — server authenticates but reuses the same session ID
- Attacker uses
KNOWN_SESSION_IDand is now authenticated as the victim
Vulnerable code (PHP):
session_start();
// User logs in successfully
$_SESSION["user_id"] = $user["id"];
// BUG: session ID not regenerated after login!
// Attacker who set sessionid= before login now owns the sessionThis vulnerability is particularly dangerous when session IDs can be set via URL parameters or cookie injection.