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

Random Cookies Appearing in Sessions table #11

Open
haroot opened this issue Nov 21, 2017 · 4 comments
Open

Random Cookies Appearing in Sessions table #11

haroot opened this issue Nov 21, 2017 · 4 comments

Comments

@haroot
Copy link

haroot commented Nov 21, 2017

i believe this plugin is causing these cookies to pile up in my table:

{"cookie":{"originalMaxAge":null,"expires":null,"httpOnly":true,"path":"/"},"flash":{}}

@manuel-di-iorio
Copy link

manuel-di-iorio commented Sep 4, 2018

connect-session (dependency) modifies the session even if not necessary, so e.g. express-session saves the new session thinking its not uninitialized. jaredhanson/connect-flash#33

From the saveUninitialized docs of https://github.com/expressjs/session:

The session is uninitialized when it is new but not modified.

This is a big issue, causing empty sessions to be created on page loads.

Upstream issue is here: https://github.com/RGBboy/express-flash/blob/master/lib/express-flash.js

res.locals.messages = req.flash();

@roberto-belardo
Copy link

I have the same problem. Did anybody found a solution?

@manuel-di-iorio
Copy link

@backslash451 This is the workaround, call this middleware before your routes:

export default (req, res, next) => {
  const _end = res.end;
  
  res.end = function fixExpressResponseEnd(...args) {
    // Fix for the connect-flash empty session
    // https://github.com/jaredhanson/connect-flash/issues/33
    if (req.session && !Object.keys(req.session.flash || {}).length) {
      delete req.session.flash;
    }

    _end.apply(this, args);
  };

  next();
};

@roberto-belardo
Copy link

This is great. I'll think about using it, because I already found a different solution using a custom function to "enable" flash() middleware on all routes except for a special one used for healthcheck (this was the problem in the first place, a GET request every 1 sec used to check the status of the application, that created the "almost" empty session object).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants