Session fixation: the identifier the attacker chose
Session fixation is an attack on how a site hands out session identifiers. The attacker does not steal a session; they arrange for the victim to sign in under an identifier the attacker already knows. If the application keeps that identifier after login, the attacker's copy of it now belongs to a signed-in user. The remedy is short to state and easy to forget: change the identifier when the user authenticates.
Quick facts
- Weakness
- CWE-384, session fixation: authenticating a user without invalidating any existing session identifier
- OWASP category
- A07:2025 Authentication Failures
- Who sets the identifier
- The attacker, before the victim signs in
- What the attacker needs
- A way to make the victim's browser send the chosen identifier, and an application that keeps it after login
- Defined in
- OWASP community page on session fixation; cookie behaviour in RFC 6265
- Main fix
- Issue a new session identifier at login and on any privilege change; invalidate the old one
Claims on this page follow the OWASP Session Management Cheat Sheet, CWE-384 and RFC 6265. Where a source says nothing, the page says nothing either.
How session fixation works
A web application recognises a returning browser by a session identifier, usually kept in a cookie. Many applications create one as soon as a visitor arrives, before any login, to remember a basket or a language choice. That pre-login session is anonymous, but it is real, and the identifier is already in the browser.
Fixation uses that gap. As the OWASP community page on session fixation describes it, the sequence has three steps.
- The attacker obtains a valid identifier. Often they simply visit the site and receive one.
- The victim is made to use it. The victim's browser ends up presenting that same identifier to the site.
- The victim signs in, and the identifier stays the same. The server upgrades the existing session to an authenticated one. The attacker presents the identifier they already hold and is treated as the victim.
No password is guessed and no traffic is read. The attacker waits for the victim to do the work. That is why CWE-384 is described as a failure to invalidate the existing identifier when a new session is established: the flaw is in what the server does at the moment of login, not in how the identifier was made.
How an attacker gets an identifier into the victim's browser
The attacker does not need the victim's cooperation beyond one visit, but they do need the identifier to arrive in the browser. Three routes are documented at the level of principle.
An identifier carried in the URL
If the application accepts a session identifier from a URL parameter, a crafted link is enough. The OWASP Session Management Cheat Sheet advises using cookies for session identifier exchange and not accepting an identifier submitted through another channel, because that closes this route. The same page warns that identifiers in URLs also leak into logs, browser history and the Referer header.
A cookie set from a sibling host
Cookies were not designed to protect their integrity across related hosts. RFC 6265, section 8.6, says that cookies give no integrity guarantee for sibling domains and their subdomains: a page on one subdomain can set a cookie that is later sent to another subdomain of the same parent domain. An attacker who controls any host under your domain, for instance after a subdomain takeover, can try to plant an identifier this way. Section 8.4 of the same RFC names session fixation as something servers should take care to avoid.
A flaw elsewhere that writes a cookie
A script injected through cross-site scripting can write a cookie, and unfiltered line breaks in a response header can let an attacker add a Set-Cookie header; see CRLF injection. In both cases the real defect is somewhere else, and fixation is what the attacker does with it. Fixing the login step removes the payoff even if another weakness survives for a while.
Fixation, hijacking and CSRF
Three attacks touch the session, and they are easy to confuse because all of them end with someone acting as a user they are not.
Session fixation sets the identifier before login. The OWASP community page on session fixation draws the contrast directly: hijacking steals an established session after login, fixation sets the session before it. If the identifier was stolen from a signed-in user, the case belongs on the session hijacking page, where the defences are about keeping the token private.
Cross-site request forgery never learns the identifier at all. It makes the victim's own browser send a request with their own cookie attached. Defences differ: CSRF is stopped by anti-forgery tokens and SameSite cookies, not by changing the identifier.
WebSocket hijacking is a close relative of CSRF for long-lived connections that authenticate with the cookie; see cross-site WebSocket hijacking.
The practical consequence: a site can be immune to one and open to another. A login that renews the identifier is safe from fixation and still needs CSRF protection.
The fix: a new identifier at login
CWE-384 lists the main mitigation as invalidating any existing session identifiers before authorizing a new user session. The OWASP Session Management Cheat Sheet is firmer still: the identifier must be renewed or regenerated after any privilege level change, and the page calls regeneration mandatory to prevent fixation. Authentication is the most common trigger, but the same section names password changes, permission changes and role elevation too.
- Regenerate on login. When credentials are accepted, create a fresh identifier, move across only the session data you intend to keep, and discard the old identifier on the server. Most frameworks have a call for this; check that your login code actually uses it.
- Regenerate on privilege change. A user who steps up to an administrator role, or who changes their password, gets another new identifier.
- Accept only identifiers the server issued. The cheat sheet separates permissive session management, which accepts any identifier presented and creates a session for it, from strict management, which does not. It states that an application should never accept an identifier it has never generated. It also notes that PHP defaults to the permissive behaviour.
- Take identifiers from cookies only. Ignore session parameters in the URL and in request bodies.
- Expire sessions. The cheat sheet makes idle and absolute timeouts mandatory. They shorten the time during which a planted identifier is useful, though they do not replace regeneration.
- End sessions properly on logout. Invalidate the identifier on the server, not only in the browser.
Test the fix by reading, not guessing: sign in and compare the session cookie before and after. If the value is the same, the application is exposed. Do this on a staging copy or an account you own. The wider design of sign-in flows is covered in API authentication.
Cookie settings that support the fix
Cookie attributes narrow what a browser will do with the identifier. They do not replace regeneration, but they remove several easy routes. The OWASP Session Management Cheat Sheet asks for all three below.
- Secure
- The browser sends the cookie only over HTTPS (RFC 6265, section 4.1.2.5). The RFC adds that Secure protects confidentiality, not integrity: it does not stop a cookie from being overwritten from an insecure channel.
- HttpOnly
- The cookie is withheld from scripts (RFC 6265, section 4.1.2.6). It limits theft through cross-site scripting; it does nothing about an identifier that was fixed before login.
- SameSite
- Not part of RFC 6265. The cheat sheet asks for an explicit SameSite=Strict (preferred) or Lax, and describes it as defence in depth against CSRF. See MDN on Set-Cookie for what each value sends.
One more option addresses the sibling-host route above. A cookie whose name begins with __Host- is accepted by supporting browsers only if it is set with Secure from an HTTPS page, carries no Domain attribute and has Path set to /. Without a Domain attribute the cookie is bound to the host that set it, so a sibling subdomain cannot supply a value for it. MDN cautions that browsers without prefix support accept such cookies without checking, so treat the prefix as a layer and not a guarantee.
Where a WAF helps and where it does not
The repair for session fixation lives in the login code. A WAF sits in front of the application and filters requests; it cannot make the application issue a new identifier, and it cannot see whether one was issued. CWE-384 lists an application firewall as an operational mitigation that may detect attacks against the weakness, which makes it a supporting control and not a substitute for the design fix.
What a filter can offer is visibility. Requests that carry a session identifier in the URL are visible as requests. Unusual cookie values, or the encoded line breaks that show up in CRLF injection probes, are visible too. Neither tells the filter whether your application will keep the identifier after login, and this page does not describe a dedicated fixation rule.
The three modes apply as usual. In off, nothing is inspected. In monitor, matches are recorded in the activity log and every request is still served, so you can see which paths receive identifiers in the URL before anything is refused. In block, matching requests are refused and still recorded. Start with monitor mode, read the log, and only then consider block.
Throttling logins also helps in a different way: rate limits slow repeated sign-in attempts but have no bearing on which identifier is used. The same split between filter and application appears with account takeover, where the filter limits the volume and the application owns the session.
Questions
What is session fixation?
Session fixation is an attack in which the attacker makes the victim use a session identifier the attacker already knows. If the application keeps that identifier after the victim signs in, the attacker holds a valid authenticated session.
How is session fixation different from session hijacking?
In fixation the attacker sets the identifier before the victim signs in. In hijacking the attacker steals an identifier that already belongs to a signed-in session. The first is fixed by issuing a new identifier at login; the second needs the identifier kept out of reach.
How do you prevent session fixation?
Issue a new session identifier whenever a user signs in or gains privilege, and invalidate the old one. Accept identifiers only from a cookie, reject identifiers the server never issued, and set the Secure, HttpOnly and SameSite attributes.
Do cookie attributes stop session fixation?
Not by themselves. Secure, HttpOnly and SameSite limit how a cookie is sent and read, but none of them changes the identifier at login. The regeneration step is what removes the weakness.
Can a WAF stop session fixation?
Not by itself. A WAF filters requests, but the fix is the application issuing a new identifier at login. A filter can record requests that carry identifiers in the URL, which helps you find where the application still accepts them.