Fix it in your stack

Tested fixes for CWE-384 in Express, Flask, Spring Boot, ASP.NET Core, Rails and Laravel: the vulnerable code, the fix, a plausible fix that still fails, and the regression tests.

Definition

MITRE’s description of CWE-384: 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.

Common consequences MITRE lists

  • Access Control: Gain Privileges or Assume Identity

Why it matters

Fixation turns a pre-login cookie, which can be easier to set or observe, into full account access without stealing a password.

How to prevent it

  • Issue a new session identifier at sign-in and at every privilege change, and invalidate the old one.
  • Accept session identifiers only from cookies, never from URLs.
  • Use the __Host- cookie prefix, which requires Secure and Path=/ and forbids Domain, so sibling subdomains cannot plant the cookie.

Guides on this site

References

  1. CWE-384 in the MITRE CWE list (version 4.20)
  2. OWASP Session Management Cheat Sheet

List data from MITRE; the name, definition and consequences are from MITRE’s CWE 4.20 catalogue. A guide is listed as the main subject when the weakness is what the guide is about, and as covering it when a dedicated section or worked example addresses it.

CWE content: Copyright © 2006–2026, The MITRE Corporation. CWE, CWSS, CWRAF, and the CWE logo are trademarks of The MITRE Corporation. CWE™ is free to use by any organization or individual for any research, development, and/or commercial purposes, per these CWE Terms of Use. Accordingly, The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. Any copy you make for such purposes is authorized on the condition that you reproduce MITRE’s copyright designation and this license in any such copy. CWE is a trademark of The MITRE Corporation. CWE Terms of Use.