-
Notifications
You must be signed in to change notification settings - Fork 160
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.flash() automatic set session when it's not required to do so. #33
Comments
Here's a slightly more elegant solution: module.exports = function flash(options) {
options = options || {};
var safe = (options.unsafe === undefined) ? true : !options.unsafe;
return function (req, res, next) {
if (req.flash && safe) { return next(); }
req.flash = _flash;
// BEGIN ADD
var _end = res.end;
res.end = function() {
if (Object.keys(req.session.flash || {}) == 0) {
delete req.session.flash;
}
_end.apply(this, arguments);
};
// END ADD
next();
}
} This proxies the end response and removes the |
We needed to patch connect-flash for similar reasons. Here's a quick one-line addition that should do the trick: function _flash(type, msg) {
if (this.session === undefined) throw Error('req.flash() requires sessions');
+ if (arguments.length < 2 && !this.session.flash) return [];
var msgs = this.session.flash = this.session.flash || {};
...
} |
Updates on this issue? |
Hi, A similar issue existed in Passport JS itself wherein it used to add an empty Passport object to the session for use after a user is authenticated, which was later fixed. I think that the session should not be touched until a value is stored in the flash area. |
This issue really could get more attention. It's causing all those bot requests to create empty sessions as well as sessions (+cookies) for every user, even before they consent to any. |
When in read-only scenario. Which flash is not yet existed. running
req.flash('name')
will setreq.session.flash
to{}
which will prevent caching.Solution:
req.session.flash
is set only whenreq.flash()
have 2 args.req.session.flash
does not existsThe text was updated successfully, but these errors were encountered: