Securitysession fixation attack

Session fixation

Definition

Session fixation exploits applications that keep the same session id across login: the attacker obtains or sets an id, gets the victim to authenticate with it, then uses the now-authenticated id.

In practice

The attacker might set the id through a URL parameter, a cookie written from a vulnerable subdomain, or a shared computer. If the server simply attaches the user to the existing session at login, the attacker's copy of the id becomes a logged-in session.

The fix is simple and mandatory: generate a fresh session id at login and whenever privileges change (for example after MFA or switching to admin), and invalidate the old one. Never accept session ids from URLs, and use the __Host- cookie prefix so other subdomains cannot overwrite the cookie.

Example

An attacker sends a link with ?sid=attacker123; the victim logs in and the app keeps attacker123, so the attacker's browser is now logged in as the victim. Regenerating the id at login stops it.