Home » Session Fixation: When to Rotate a Session ID

Session Fixation: When to Rotate a Session ID

An old session ticket is cut at a server, which issues a fresh ticket.

Rotate the session identifier when a user logs in or crosses a privilege boundary. Verify that the old identifier no longer authorizes the higher privilege. A secure-looking cookie cannot protect a user if an identifier that was known before login continues to act as the same authenticated session.

Understand the fixation attempt

Imagine a service accepts an anonymous session identifier from a cookie. An attacker obtains or otherwise knows the identifier before a victim signs in. If the application promotes that same session in place and gives it authenticated privileges, anyone able to reuse the identifier may be treated as the victim. The vulnerability comes from reusing an identifier across trust levels.

Session Management Cheat Sheet recommends regenerating a session ID after privilege changes. Cookie settings such as Secure, HttpOnly and SameSite help control exposure and cross-site use, but they solve different problems. Apply the application and framework's recommended session handling rather than relying on those attributes alone.

Trace what happens on login

In a synthetic test, first create an anonymous session and save its cookie as A. Complete login in the same browser and verify that the application issues a fresh ID B and access with B works. From a second isolated client, send A to an authenticated endpoint. The expected result is an unauthenticated or denied response. Also check that any carried state, such as a shopping cart, crosses only the intended boundary.

When using a framework's regeneration method, inspect the behavior of its old store entry. Replacing a browser cookie is insufficient if A still maps to an authenticated server session. Confirm the session store, cookie path and domain, and duplicate-cookie behavior across the hosts the application uses.

Test a transition beyond login

Repeat the check when a user performs step-up authentication for an administrative capability or other sensitive flow. Use independent clients so the old cookie cannot be silently replaced during the test. Test logout as a separate revocation case. A token-based application may use a different credential lifecycle. The same verification question applies, but do not treat rotating an opaque server session as a universal JWT recipe.

The passkey lifecycle guide discusses passkey-based login and account recovery. Strong authentication establishes identity; the application still has to manage what happens to its session identifiers after identity is established.

Handle concurrent activity deliberately

Two tabs can make requests across the moment the ID changes. Preserve only expected pre-login state and ensure earlier in-flight requests cannot inherit the new authorization by using the old ID. Decide which requests should recover by refreshing or signing in again. Record the expected states for old and new IDs and avoid saving actual cookie values in reports. The important outcome is the access each identifier grants, not the visual presence of a new cookie alone.

You may also like