Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

req.session.regenerate is not a function since upgrade to 0.6.0 #907

Open
nickyblissAviva opened this issue May 27, 2022 · 27 comments
Open
Labels
duplicate This issue or pull request already exists

Comments

@nickyblissAviva
Copy link

We have been using passport for some time within our application and have had no issues but once upgraded from 0.5.2 to 0.6.0 we are suddenly seeing an error when submitting authentication.

C:\stash\NTTSites\sites\fw-standards\node_modules\passport\lib\sessionmanager.js:28
  req.session.regenerate(function(err) {
              ^

TypeError: req.session.regenerate is not a function
    at SessionManager.logIn (C:\stash\NTTSites\sites\fw-standards\node_modules\passport\lib\sessionmanager.js:28:15)
    at IncomingMessage.req.login.req.logIn (C:\stash\NTTSites\sites\fw-standards\node_modules\passport\lib\http\request.js:39:26)
    at Strategy.strategy.success (C:\stash\NTTSites\sites\fw-standards\node_modules\passport\lib\middleware\authenticate.js:256:13)
    at verified (C:\stash\NTTSites\sites\fw-standards\node_modules\passport-local\lib\strategy.js:83:10)
    at Strategy.runAuth [as _verify] (C:\stash\NTTSites\sites\fw-standards\utils\passport-authentication.js:60:10)

Our passport-authentication.js just initialises passport within expressJS and sets some local strategies.

I have rolled back to 0.5.3 and our application works fine again.

Environment

  • Operating System: Windows 10
  • Node version: 16.13.2
  • passport version: 0.6.0
@jaredhanson
Copy link
Owner

What are you using for session middleware?

@nickyblissAviva
Copy link
Author

cookie-session 2.0.0

@jaredhanson
Copy link
Owner

Thanks for the report. This is a duplicate of #904. I'd recommend pinning to 0.5.x, until I've had a chance to release an update with the new features described on the initial issue.

@jaredhanson jaredhanson added the duplicate This issue or pull request already exists label May 27, 2022
MINJE-98 added a commit to MINJE-98/login-template that referenced this issue Aug 31, 2022
Andrei-Stepanov added a commit to fedora-ci/ciboard-server that referenced this issue Dec 1, 2022
Upstream link: jaredhanson/passport#907

Signed-off-by: Andrei Stepanov <astepano@redhat.com>
Andrei-Stepanov added a commit to fedora-ci/ciboard-server that referenced this issue Dec 1, 2022
Upstream link: jaredhanson/passport#907

Signed-off-by: Andrei Stepanov <astepano@redhat.com>
@spraju92
Copy link

Passport 0.5.0 has a significant vulnerability, and when we update to 0.6.0, we see the error "TypeError: req.session.regenerate is not a function." Does that mean that anything relating to the session create issue needs to be manually edited?

@raphaelpreston
Copy link

Any update for March 2023? I see that @VottonDev has a fix in their separate repo..

@VottonDev
Copy link

Any update for March 2023? I see that @VottonDev has a fix in their separate repo..

Yeah, I'm using: https://github.com/joeyguerra/passport#missing-regenerate-on-req temporarily till passport fixes it upstream and that works for me so far when using the cookie-session module.

@hier01
Copy link

hier01 commented Mar 10, 2023

@VottonDev, what's the best way to apply the fix in joeyguerra's fork?

@VottonDev
Copy link

@VottonDev, what's the best way to apply the fix in joeyguerra's fork?

Well I've changed my package.json passport to
"passport": "github:joeyguerra/passport#missing-regenerate-on-req",

The PR for the fix is here, which is how I found it:
#947

@japthind
Copy link

I am getting the below error when I logout from my application. I am using express-session module to manage the sessions. According to the above discussion is there a permanent fix for this or do I need to downgrade from Passport 0.6.0

/node_modules/passport/lib/sessionmanager.js:83
req.session.regenerate(function(err) {
^
TypeError: Cannot read properties of undefined (reading 'regenerate')
at Immediate. (/node_modules/passport/lib/sessionmanager.js:83:17)
at process.processImmediate (node:internal/timers:471:21)

@japthind
Copy link

Hi All,

Can anyone please confirm the status of this issue as this is currently blocking one of our production deployments? Is there a permanent fix for this or do we need to downgrade to 0.5.x version?

@faizur11786
Copy link

I encountered a similar problem with version 0.6 of Passport. To resolve it, I downgraded to version 0.5.0

@imartinezmorales-loom
Copy link

I ended up resolving this issue for our upgrade to passport 0.6.0 by stubbing the regenerate and save methods. I patched the dependency in our repository in the lib/sessionmanager.js file as such:

  options = options || {};

+  this._delegate = options.delegate || {
+        regenerate: function(req, cb) {
+            cb();
+        },
+        save: function(req, cb) {
+            cb();
+        }
+    };

And then propagating those changes to the various calls to save and regenerate in the file.

@recursiveway
Copy link

@imartinezmorales-loom do we simply have to add these lines or have to change/remove something as well

@imartinezmorales-loom
Copy link

@recursiveway - I actually ended up writing a middleware function that I pull into our express server. The middleware function is just a stub similar to the one above:

export const passportMiddleware = (request, response, next) => {
  if (request.session && !request.session.regenerate) {
    request.session.regenerate = cb => {
      cb();
    };
  }

  if (request.session && !request.session.save) {
    request.session.save = cb => {
      cb();
    };
  }

  next();
};

malikimran34 added a commit to DFE-Digital/login.dfe.services that referenced this issue Oct 20, 2023
… details...

  /*
    Addressing issue with latest version of passport dependency packge
    TypeError: req.session.regenerate is not a function
    Reference: jaredhanson/passport#907 (comment)
  */
@tonmoydeb404
Copy link

instead of using cookie-session I've used express-session as a session middleware with the latest passport package and this solves the problem.

@radoslavirha
Copy link

@tonmoydeb404 but they serve different purposes, it's not a solution.

@tanosaur
Copy link

tanosaur commented Nov 7, 2023

Can't believe this still isn't fixed?

@AlvesJorge
Copy link

+1 Above

@raulrene
Copy link

instead of using cookie-session I've used express-session as a session middleware with the latest passport package and this solves the problem.

Yes but it should also work with cookie-session, it did until 0.5.0. It's not so easy for everyone to switch the session manager, especially on large projects. Hopefully this gets fixed sometime soon

@daneedev
Copy link

daneedev commented Dec 2, 2023

So should I change session manager from cookie-session to express-session, or stay on passport 0.5?

@lalitkishork73
Copy link

@drebel, it shows me, Error: req#logout requires a callback function

@yevon
Copy link

yevon commented Apr 11, 2024

Any news for this one? I'm getting same error under passport 0.7.0 and cookie-session 2.1.0

@daneedev
Copy link

@yevon

Any news for this one? I'm getting same error under passport 0.7.0 and cookie-session 2.1.0

Hey, the cookie-session isn't officialy supported by passport. So I don't think they will ever make support for it. I used to use cookie-session, but I switched to express-session and it works very well. I suggest you to switch too.

Have a nice day,
Daniel Kroufek

@yevon
Copy link

yevon commented Apr 12, 2024

@yevon

Any news for this one? I'm getting same error under passport 0.7.0 and cookie-session 2.1.0

Hey, the cookie-session isn't officialy supported by passport. So I don't think they will ever make support for it. I used to use cookie-session, but I switched to express-session and it works very well. I suggest you to switch too.

Have a nice day, Daniel Kroufek

Thanks for that! I will try to replace it

@asaxena1415
Copy link

@yevon

Any news for this one? I'm getting same error under passport 0.7.0 and cookie-session 2.1.0

Hey, the cookie-session isn't officialy supported by passport. So I don't think they will ever make support for it. I used to use cookie-session, but I switched to express-session and it works very well. I suggest you to switch too.
Have a nice day, Daniel Kroufek

Thanks for that! I will try to replace it

express-session does not store cookies on the client side, the session gets destroyed every time the serve restarts, this is not a solution.

@yevon
Copy link

yevon commented May 2, 2024

With express jwt you can store the coockie as http only, I have it working now.

@zerone0x
Copy link

express-session

Thanks for your suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests