CWE-384: Session fixation | Causes and Fixes Skip to content

Security weakness

CWE-384 Session fixation

An attacker plants a session ID on a visitor, waits for the login, then takes over the account.

  • Senior security engineers
  • 540+ projects delivered
  • Reply within one business day

Quick answer

What is CWE-384?

Session Fixation: 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.

Business impact

What CWE-384 could cost your business

MITRE documents what this weakness can do. Here is what that means for a website, store or app.

Access Control

Accounts and admin areas exposed

Logins and permission checks can be bypassed, putting admin and customer accounts at risk.

  • Gain Privileges or Assume Identity

In plain English

What Session fixation means for your business

  • 540+projects delivered
  • 9+years in business
  • 23+certified experts
Get a free security check

A senior engineer replies within one business day.

When someone visits your site, the server hands their browser a session ID, a random token that says who they are on each request. Session fixation happens when your site keeps that same ID after the person logs in. An attacker who knew or chose the ID beforehand now holds a valid key to the logged-in account, without ever seeing the password.

For a business, the result is account takeover. The attacker can read order history and saved addresses, change account details or act as an admin if the victim was one. Strong passwords and two-factor login do not help, because the attacker rides in on a session the real user authenticated. The good news is that the fix is small and well understood: issue a fresh session ID at every login.

Where it shows up

  • Custom login systems in PHP, Node.js or other frameworks where the developer starts a session on the first page view and never regenerates it after the password check.
  • Sites that accept a session ID from the URL, such as a link carrying the ID in its query string, which lets someone hand a visitor a chosen session.
  • Stores where a guest cart session carries straight over into the logged-in customer account at checkout without a new session ID being issued.
  • Apps on shared parent domains, where a weaker subdomain can set a cookie that the main site then trusts as the visitor’s session.

Free security check

Is CWE-384 hiding in your site?

A senior engineer checks your site, store or app for this weakness and the rest of the CWE Top 25, then sends a prioritized fix plan within one business day. No obligation.

Official definition

How MITRE defines CWE-384

Session Fixation

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.

Such a scenario is commonly observed when:

A web application authenticates a user without first invalidating the existing session, thereby continuing to use the session already associated with the user.

An attacker is able to force a known session identifier on a user so that, once the user authenticates, the attacker has access to the authenticated session.

The application or container uses predictable session identifiers.

In the generic exploit of session fixation vulnerabilities, an attacker creates a new session on a web application and records the associated session identifier. The attacker then causes the victim to associate, and possibly authenticate, against the server using that session identifier, giving the attacker access to the user’s account through the active session.

Weakness ID
CWE-384
Type
Compound
Status
Incomplete
Applies to
Web Based, Web Server
Introduced during
Architecture and Design, Implementation

Fix it

How to fix Session fixation

Practical steps in priority order. Share them with your developer or agency.

  1. Regenerate the session ID at login

    Issue a brand-new session ID the moment authentication succeeds and invalidate the old one on the server. Most frameworks have a built-in call for this, such as session_regenerate_id(true) in PHP or req.session.regenerate in Express.

  2. Regenerate on every privilege change

    Also rotate the ID when a user switches roles, re-enters a password for a sensitive action or moves from guest to customer. Any step that raises trust should start a fresh session.

  3. Accept session IDs from cookies only

    Turn off session IDs in URLs and hidden form fields. In PHP, enable session.use_only_cookies and session.use_strict_mode so the server rejects any ID that it did not create itself.

  4. Harden the session cookie

    Set the HttpOnly, Secure and SameSite attributes on the session cookie, and use the __Host- cookie name prefix where you can so a sibling subdomain cannot overwrite it.

  5. Expire and destroy sessions properly

    Destroy the server-side session record at logout, set idle and absolute timeouts, and make sure IDs are long, random values from the framework’s generator rather than anything predictable.

Signs you may be affected

  • The session cookie value is identical before and after you log in.
  • Session IDs appear in page URLs, shared links or your browser history.
  • Logging out does not end the session on the server, so the old ID still works.

Questions to ask your developer

  • Do we issue a new session ID every time someone logs in?
  • Can our site ever accept a session ID from a URL or form field?
  • What happens to the session on the server when a user logs out?

Prevention

What MITRE recommends, phase by phase

Every mitigation from the CWE entry, in the order a project runs: plan, build, test, operate.

  1. 01

    Architecture and Design

    • Invalidate any existing session identifiers prior to authorizing a new user session.
    • For platforms such as ASP that do not generate new values for sessionid cookies, utilize a secondary cookie. In this approach, set a secondary cookie on the user’s browser to a random value and set a session variable to the same value. If the session variable and the cookie value ever don’t match, invalidate the session, and force the user to log on again.
  2. 02

    Operation

    • Use an application firewall that can detect attacks against this weakness. It can be beneficial in cases in which the code cannot be fixed (because it is controlled by a third party), as an emergency prevention measure while more comprehensive software assurance measures are applied, or to provide defense in depth [REF-1481].

Detection and evidence

How CWE-384 is found, and where it has hit

The testing methods MITRE recommends, and real vulnerabilities this weakness has caused.

Real vulnerabilities it caused

  • CVE-2022-2820Website software for game servers does not properly terminate user sessions, allowing for possible session fixation

How we fix it

From finding to fixed: how Codefreex closes CWE-384

  1. Scan and confirm

    We test your site, store or app for this weakness and the rest of the CWE Top 25 with automated scanning and manual review, and confirm what is actually exploitable.

  2. Fix at the source

    We change the code, configuration or dependency that causes it, not just the symptom, and plan the changes to avoid downtime.

  3. Verify the fix

    We retest every finding, check that nothing else broke and hand you a short report you can share with your team, client or auditor.

  4. Keep it fixed

    Updates, monitoring and maintenance so the weakness does not return with the next plugin, theme, app or code change.

FAQ

CWE-384: FAQs

Short answers for owners and developers. Not sure whether your site is affected? Ask us to check.

How serious is session fixation for my business?

It is serious because it leads directly to account takeover. An attacker who fixes a session can do anything the victim can do, including viewing personal data, changing account details or using admin features. It does need the victim to log in with the planted session, which limits scale, but a single compromised admin account can be costly.

How do I prevent session fixation?

Generate a new session ID whenever a user logs in or gains privileges, and invalidate the old one. Accept session IDs only from cookies, never from URLs. Mark the cookie HttpOnly, Secure and SameSite. Most modern frameworks do this by default if you use their built-in authentication, so the risk is highest in custom or legacy login code.

Is session fixation the same as session hijacking?

Not quite. Session hijacking means stealing a session ID that already belongs to a logged-in user. Session fixation works the other way around: the attacker picks the ID first and gets the victim to log in with it. Both end with the attacker inside the account, and regenerating IDs at login plus protected cookies defends against both.

What is CWE-384?

CWE-384, “Session Fixation”, is a software weakness catalogued by MITRE in the Common Weakness Enumeration. 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.

How serious is CWE-384?

It can affect access control, with impacts such as gain privileges or assume identity. The real risk depends on where the weakness sits and what data or functions it exposes.

How do you prevent CWE-384?

Invalidate any existing session identifiers prior to authorizing a new user session. For platforms such as ASP that do not generate new values for sessionid cookies, utilize a secondary cookie. In this approach, set a secondary cookie on the user’s browser to a random value and set a.

Can Codefreex check my site for CWE-384?

Yes. A senior engineer reviews your site, store or app for CWE-384 and the rest of the CWE Top 25, confirms what is exploitable and sends a prioritized fix plan within one business day. Start with the free security check form on this page.

Free security check

Find out if CWE-384 affects your site

Send your URL. A senior engineer checks for this weakness and the rest of the CWE Top 25, and replies within one business day with what to fix first.

  • A senior strategist reviews your request, not a sales bot
  • Clear scope, timeline and estimate within one business day
  • Free 30-minute discovery call, no obligation
  • NDA available on request

Weakness data from the Common Weakness Enumeration (CWE®) version 5.0, Copyright © 2006–2026, The MITRE Corporation. CWE is free to use by any organization or individual for any research, development, and/or commercial purposes under the CWE Terms of Use. CWE is a registered trademark of The MITRE Corporation. The business impact, risk profile and plain-English guidance on this page are written by Codefreex and are general information, not a security assessment of your system.