Safeguard
Security Guides•

What is session fixation and how do you test for it?

Session fixation happens when a session ID stays the same across login. How the attack works, a four step test, and the fix that scanners look for.

Safeguard Security Team
4 min read

Session fixation is a flaw where an application keeps the same session ID before and after login, so an attacker who planted a known ID in a victim's browser can use it once the victim signs in. Test it by comparing cookies before and after login. The fix is to issue a new ID at login.

How the attack works

The OWASP Web Security Testing Guide explains that this is enabled by preserving the same value of the session cookies before and after authentication. It often happens when the app uses a session before login, for example to hold a shopping cart.

  1. The attacker gets a session cookie from the site without logging in.
  2. The attacker forces that cookie into the victim's browser by some means.
  3. The victim logs in. If the cookie is not refreshed, the session is now authenticated.
  4. The attacker, who knows the cookie value, acts as the victim.

The attacker never needed the password. They only needed the application to promote an existing session to a logged-in one.

How to test for it

You need two browser profiles or a proxy, and a test account.

  1. Open the site without logging in and record the session cookie name and value.
  2. Log in with the test account in the same browser.
  3. Record the session cookie again.
  4. Compare. If the value is the same, the application is vulnerable to fixation. If it changed, the app regenerates the ID correctly.

Also repeat the check for other privilege changes. OWASP's cheat sheet says the ID must be renewed after any privilege level change, with login as the most common case, and it lists password changes, permission changes and switching from a regular role to an administrator role as others.

Some sites use more than one cookie. Check each, since one cookie may be refreshed while another that actually identifies the session is not.

What scanners can and cannot do

An authenticated scanner can run the same before and after comparison automatically, which makes this one of the checks that automation does well. Things it can miss:

  • Login flows with extra steps such as multi-factor prompts, where the ID may be rotated at the wrong step.
  • Apps that put the session in a header or local storage rather than a cookie.
  • Cookies set by a different subdomain than the one being scanned.
  • Privilege changes beyond login, which a scan has no reason to trigger unless configured.

The fixes

FixWhat it does
Regenerate the session ID on loginMakes any pre-login ID useless
Regenerate on privilege changeCovers password change and role switches
Use prefixed cookie namesThe testing guide suggests the __Host- or __Secure- prefix to protect cookie integrity against network attackers
Enable full HSTSThe same guide recommends full HSTS, covering subdomains, for the same reason

Most frameworks offer a one line call to rotate the session ID. Our post on resetting the session after login in Rails shows one example. Match the fix to your framework and test again afterward.

Quick check

Does HTTPS prevent session fixation?

No. HTTPS protects traffic in transit but does not change whether the server reuses a session ID across login. You still need to regenerate the ID.

Is this the same as session hijacking?

They are related. Hijacking steals an ID the victim already has. Fixation makes the victim adopt an ID the attacker already knows.

Try it yourself

Click through it at your own pace, or open it full screen. See how a scan records the cookies it sees while it crawls.

Safeguard offers a free scan of your dependencies at gold.safeguard.sh/scan, useful for checking the session libraries you rely on.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.