CVE-2022-25896 (published 2022-07-01T20:15Z)

This affects the package passport before 0.6.0. When a user logs in or logs out, the session is regenerated instead of being closed.

Severity: MEDIUM
CVSS v2 base score: 5.8 (AV:N/AC:M/Au:N/C:P/I:P/A:N)
CVSS v3 base score: 4.8, MEDIUM (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:L/I:L/A:N)

Weakness information:
cwe_id: CWE-384
cwe_name: Session Fixation
description: 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.
extended_description: 
            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.
         
         

Fix information:
repo_url: https://github.com/jaredhanson/passport
commit_details: repo_url: https://github.com/jaredhanson/passport
author: Jared Hanson
author_date: 2022-05-17 08:15:54-07:00
msg: Regenerate session on login.
repository: repo_url: https://github.com/jaredhanson/passport
repo_name: jaredhanson/passport
description: Simple, unobtrusive authentication for Node.js.
repo_language: JavaScript
owner: jaredhanson
file_changes: filename: sessionmanager.js
change_type: ModificationType.MODIFY
diff: @@ -10,24 +10,34 @@ function SessionManager(options, serializeUser) {
 }
 
 SessionManager.prototype.logIn = function(req, user, cb) {
+  console.log('SM: logIn');
+  
   var self = this;
-  this._serializeUser(user, req, function(err, obj) {
+  req.session.regenerate(function(err) {
     if (err) {
       return cb(err);
     }
-    // TODO: Error if session isn't available here.
-    if (!req.session) {
-      req.session = {};
-    }
-    if (!req.session[self._key]) {
-      req.session[self._key] = {};
-    }
-    req.session[self._key].user = obj;
-    cb();
+    
+    self._serializeUser(user, req, function(err, obj) {
+      if (err) {
+        return cb(err);
+      }
+      // TODO: Error if session isn't available here.
+      if (!req.session) {
+        req.session = {};
+      }
+      if (!req.session[self._key]) {
+        req.session[self._key] = {};
+      }
+      req.session[self._key].user = obj;
+      cb();
+    });
   });
 }
 
 SessionManager.prototype.logOut = function(req, cb) {
+  console.log('SM: logOut');
+  
   if (req.session && req.session[this._key]) {
     delete req.session[this._key].user;
   }

programming_language: JavaScript