touch does not update session.cookie.expires
See original GitHub issueWhen resave: false
and rolling: true
then the store will update the top-level expires
in the session database on each request. express-session will also update the cookie and send it with every response.
The problem is that the stored document at the path session.cookie.expires
does not get updated, so it is out-of-sync with both the top level expires as well as the expires in the cookie.
Since the touch()
implementation already sends a call to the database to update the top-level expires
should it not also update session.cookie.expires
?
This is the configuration of express-session:
const store = new MongoStore({
mongooseConnection: db,
stringify: false,
});
session({
secret: 'some_secret',
resave: false,
rolling: true,
saveUninitialized: false,
cookie: {
maxAge: 60000,
secure: true,
httpOnly: true,
},
store,
})
The actual document saved to the store looks something like this:
{
"_id": "f2yQHE_BPi6UKV4pMuM7xluGPwQIhxIU",
"expires": {
"$date": "2020-02-03T15:23:54.646Z"
},
"session": {
"cookie": {
"originalMaxAge": 3599997,
"expires": {
"$date": "2020-02-03T15:04:06.890Z"
},
"secure": false,
"httpOnly": true,
"domain": null,
"path": "/",
"sameSite": null
},
"passport": {
"user": "someUser"
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:33 (8 by maintainers)
Top Results From Across the Web
ExpressJS session cookie is not updated - node.js
I expected that session.touch() would do it, but it only seems to reset session expiration date on server and doesn't push new cookie...
Read more >Cookie Policy
Cookies may be either 'persistent' cookies or 'session' cookies. A persistent cookie is stored by a web browser and will remain valid until...
Read more >Everything You Need to Know About Session Cookies
A session cookie is a simple snippet of code that a website installs on its visitor's device for temporary use. It helps track...
Read more >COOKIE POLICY | Morgan Lewis
There are two broad categories of cookies: session cookies and persistent cookies. A session cookie expires and disappears when you close ...
Read more >Sessions API
A session cookie has an expiration configurable by an administrator for the organization and is valid until the cookie expires or the user...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Current Behavior
Expected Behavior (my opinion)
I performed a quick search on
expires
. It seems like to me that it (the top levelexpires
) is used to perform faster queries and should reflect the value in the cookie.resave
forces the session to be saved back to the session store. No mention ofexpires
Reference: https://expressjs.com/en/resources/middleware/session.html
Happy to have a look at code if everyone agrees.
@YC I have just reverted it in
develop
branch. https://github.com/jdesboeufs/connect-mongo/commit/82e1831b80fc5982b31a14b8db7dd0490d42d3a9 I will group the bug fixes and cut a release later.