DEV Community

ClientN
ClientN

Posted on Originally published at clientn.com

Session Fixation: Why Every Login Needs a New Session ID

Most people picture a login as a password check. Once it passes, the server has a problem it rarely thinks about. HTTP forgets everything between requests, so the site has to remember who is asking. It does that with a session identifier, a long random string that the browser presents with every request. Whoever holds that string is treated as the signed-in person.

Session fixation exploits the moment that string is set. If a site keeps the same identifier when a visitor signs in, an attacker who learned that identifier beforehand can use it afterward. The victim types the correct password and the attacker does not see it, and the attacker still gets in. This article explains how the attack works, walks through a vulnerability published in September 2026, and ends with a short checklist for site owners.

What a session identifier does

HTTP treats each request as a separate event. To connect a page view to the one before it, the web relies on state kept somewhere else, and the usual place is a cookie. The server creates a record for the visitor, gives the browser an identifier that points to that record, and the browser returns the identifier with each request. The OWASP Session Management Cheat Sheet describes this arrangement and recommends cookies as the way the identifier is exchanged. It also advises against accepting an identifier from another route, such as a URL parameter, as a defense against session fixation.

The identifier works as a bearer credential. The server does not ask who is holding it. It checks that the string matches a live record, and if it does, the request is treated as coming from the account attached to that record. That design is fast and easy to scale, and it is also why the identifier needs careful handling at the moment its meaning changes. Before a login, the record belongs to an anonymous visitor. After a login, the same record may belong to a named account with more powers. The question session fixation asks is whether the server updates the label when that change happens.

The record behind an identifier holds whatever the site needs to remember: the account it belongs to, when it was created, when it was last used, and sometimes a shopping cart or a preferred language. Most sites add a timeout so an idle session expires. None of this is visible to the visitor, and none of it changes just because the visitor moves to another page. The record waits on the server until the next request names it, and that waiting is the whole reason an identifier is valuable to anyone who gets hold of it.

How the attack works, step by step

Session fixation has three steps. In the first, the attacker opens the target site and receives a session identifier the same way any visitor would. In the second, the attacker gets that identifier into the victim's browser. The routes vary. A crafted link can carry the identifier, a related subdomain can set a cookie the main site will read, and an attacker on the network path can write into the victim's traffic. In the third step, the victim signs in. If the site keeps the old identifier, the attacker's copy now points at an authenticated session.

Here is what step two can look like in an illustrative case, not a real incident. An attacker sends a link such as https://shop.example/login?session=VALUE_CHOSEN_BY_ATTACKER. A site that reads identifiers from the URL plants that value in the victim's browser, and the victim does not notice a change. The link looks like any other login page, which is why the attacker does not need to touch the victim's device.

The weakness lives in the server's habit, not in the victim's password. Nothing about the login form is broken. The site does not change the label on the session when the account gains its new rights. The Common Weakness Enumeration describes the pattern in one sentence:

Authenticating a user, or otherwise establishing a new user session, without invalidating any existing session identifier gives an attacker the opportunity to steal authenticated sessions.

Source: CWE-384: Session Fixation, MITRE.

The generic exploit in CWE follows the same three steps. An attacker creates a new session on the web application, records its identifier, and gets the victim to authenticate with that identifier. The attacker does not need the victim's password, and does not need to break the cryptography used to protect it. Everything depends on timing and on the identifier surviving the login. That is why the fix sits in one place, the moment of login.

Why the login moment is the one that counts

OWASP puts the rule in a single sentence: the session ID must be renewed or regenerated after any privilege level change within the associated user session. It then names the most common case. Authentication is when a visitor moves from anonymous to signed in, and the session has to be renewed at that point.

Many sites create a session before anyone signs in. A cart, a language choice, or a consent setting can all be stored against an anonymous session. That is normal and often useful. The risk appears when the login reuses that session without a change. The same record that held the cart now holds the account, and the identifier a stranger may have seen is still the one in use. OWASP lists other moments that deserve the same treatment, including password changes and permission changes.

Think of one session as a sequence of levels. Before sign-in, the record can browse pages and fill in a contact form. After sign-in, the same record can read the account's private data. The record is the same object in both states, and only its label changes. If the label does not change, an attacker's copy of the identifier inherits the higher level without any further step. Rotation is the rule for that change. It belongs in the session code, not in the login form, because every path that raises a session's level has to pass through it. A login form that sets the flag in one place and an admin tool that sets it in another are two paths, and both need the same call.

A 2026 case: the missing call in tirreno

On 9 September 2026, the National Vulnerability Database published CVE-2026-64857 for tirreno, a security framework. The record says that versions before 0.10.0 validate the user's credentials and then establish the authenticated session without calling session_regenerate_id(). The identifier therefore stays the same before and after sign-in. NVD scores the flaw 5.3, medium.

An attacker able to fix a known session identifier in a victim's browser (for example through a network man-in-the-middle position, or a separate cross-site scripting or subdomain cookie-injection issue) could then gain access to the victim's authenticated session.

The condition in that sentence matters. The attacker does not guess anything. They need a known identifier placed in the browser first, which is why the record lists three separate routes. When we checked the NVD record on 30 November 2026, its status read Deferred, so treat the score as provisional. NVD says the fix in v0.10.0 regenerates the identifier on successful authentication and destroys the previous session. The project's GitHub advisory is the linked reference for the issue. The defect was the absence of one function call.

If you run your own login code, this case is a short check. Find the function that marks a session as signed in, and confirm that a rotation call runs earlier in the same request, after the credentials pass. A login path that writes the user ID into the session without rotating the identifier has the same defect, whatever framework it uses. Code review catches this only when someone asks what happens to the session at the moment of login, so put that question on the review checklist.

The fix: give every login a new identifier

In most frameworks the fix is one call, placed in the right spot. OWASP lists the common ones: session_start() with session_regenerate_id(true) in PHP, request.getSession(true) with HttpSession.invalidate() in J2EE, and Session.Abandon() in ASP.NET. The call belongs after the credentials check succeeds and before the code marks the session as signed in. Setting the signed-in flag first and rotating afterward leaves a window in which the old identifier carries the new privilege.

A minimal PHP login path looks like this. It is illustrative, so adapt it to your framework and your own user lookup:

<?php
session_start();

if (password_verify($password, $user['password_hash'])) {
    // Issue a new identifier and delete the old session record.
    session_regenerate_id(true);
    $_SESSION['user_id'] = $user['id'];
}
?>
Enter fullscreen mode Exit fullscreen mode

Rotation has three parts. Generate a new random identifier. Move only the data the site needs into the new session, such as the return address or a cart. Then invalidate the old identifier, so a copy taken before login stops working. Skipping that last step is common, and it leaves the attacker's copy alive. A simple test catches most mistakes. Take an identifier while signed out, sign in, and check that the cookie value changed and that the old value now gets the visitor nothing.

Rotate again each time privilege changes within the same session. OWASP names password changes and permission changes as examples. A site that renews only at login, but keeps the same identifier through a password change, has left a smaller version of the same hole open. Put the rotation call next to each of those changes, and add a test for each one, so the next developer who adds a new privilege path inherits the habit.

Cookie flags help, but they do not replace rotation

The Secure attribute tells the browser to send the cookie only over an encrypted connection. OWASP notes that encryption protects the session against some fixation attacks, the ones in which an attacker intercepts and manipulates web traffic to inject or fix the identifier. The same guidance warns against switching a session between HTTP and HTTPS, because that exposes the identifier in the clear. When a site redirects to HTTPS, the cookie should be set or regenerated after the redirect has happened.

Flags do not cover everything. The tirreno record lists subdomain cookie injection as one route for fixing an identifier. A subdomain on HTTPS can still set cookies for the parent domain, so the Secure flag on the main site does not close that route. Rotation does, because the planted identifier stops mapping to the account once the server issues a new one at login. The defense works whichever route the attacker used to plant the value. That is why it belongs at the center of the checklist, and the flags belong around it.

Set HttpOnly as well, so page scripts cannot read the identifier. That protects against theft by script, which is a different problem from planting. An HttpOnly flag does not stop an attacker from writing a value into the browser, and only rotation at login makes a planted value useless. Treat the flags as the outer wall and rotation as the lock on the door. Review the cookie settings in the same release as the login change, so the two cannot drift apart.

Where anonymous sign-in fits

Sign-in without a shared email address or phone number still needs an answer to the same question: which browser holds the signed-in session? NIST's SP 800-63B-4 defines a session secret for this purpose and describes what it does:

A session secret SHALL be shared between the subscriber's software and the accessed service. This secret binds the two ends of the session and allows the subscriber to continue using the service over time.

Source: NIST SP 800-63B-4.

Once a session secret exists, the anonymous question becomes concrete. What if a site could sign you in without learning any identifier at all? It would still need a session, and the session would still need a rule for when its identifier changes. Anonymity does not remove the login boundary. It changes what a stolen identifier reveals. In a design with a different identifier per site, a leaked session tells an attacker less about the same person on other sites.

Anonymous sign-in changes what the site learns about a person. It does not change the fact that a session follows the login. The boundary still has to be renewed at the moment the person proves who they are to the site in front of them, and the session should be treated as a normal session with a normal rotation rule. A privacy design that skips this step weakens its own login, whatever it hides from the site. Read any privacy claim next to a plain statement of how long the session lasts and which routes can place a value in the browser.

A checklist for site owners

  1. Find every path that sets a signed-in state, including the password form. Social login callbacks, "remember me" tokens, and one-time link logins each need the same rotation.

  2. Rotate the identifier right after the credentials or proof check succeeds, and before the code grants any privilege. Use your framework's function, such as session_regenerate_id(true) in PHP.

  3. Invalidate the old identifier, so a copy taken before the login stops working.

  4. Rotate again on password changes and permission changes, and test each one.

  5. Do not accept session identifiers from URL parameters, set HttpOnly and Secure on the cookie, and keep HTTPS on every page that sets or reads it.

  6. Test it. Take an identifier while signed out, sign in, and confirm the cookie value changed and the old value returns nothing.

Keep this list in the release checklist for the login code, so the checks survive staff changes and framework upgrades.

Tools like ClientN explore sign-in that asks a site for no shared identifier at all. The session question stays in that design, and it still needs an answer. Ask any provider, including us, which browser holds the signed-in session and whether that identifier changes when the person signs in. A useful answer names the function, the moment, and the test. For the wider picture, read our public security page, the developer docs, or start at the homepage.

Internal further reading:


I'm building ClientN, so read the ClientN parts of this article as my view, not a neutral one. Each website that uses ClientN gets a random ID made only for that site, not your email address, and sign-in approvals are checked on your own device. The security page explains how: https://clientn.com/security/

Originally published at clientn.com/blog.

Top comments (0)