Give error for incorrect maxAge and expires Type
See original GitHub issueOut of mere developer error, I inserted into the maxAge
field what should have been entered in expires
:
maxAge : new Date(Date.now() + 3600000)
Instead of
expires : new Date(Date.now() + 3600000)
However this causes a weird quirk in creating a session, for example, setting username and password within seconds of eachother will create two sessions, each with a negative maxAge
{
"_id" : "zY02IMuLO720J-SLFKVj"
"session" : {
"cookie" : {
"originalMaxAge" : -104023,
"expires" : ISODate("..."),
"secure" : null,
"httpOnly" : true,
"domain" : null,
"path" : "/"
},
"username" : "username"
},
}
"_id" : "fJ92IErLO730J-sLPMvQ"
"session" : {
"cookie" : {
"originalMaxAge" : -104035,
"expires" : ISODate("..."),
"secure" : null,
"httpOnly" : true,
"domain" : null,
"path" : "/"
},
"password" : "hashed_password"
},
}
So they are set as separate sessions, and this causes a session to expire, and new session to be created immediately, having some functionality to have express-session
throw an error if the wrong type is entered would be beneficial.
Issue Analytics
- State:
- Created 8 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Can't set cookie 'expires' or 'maxAge' in Node.js using Express ...
I was trying to use a short-lived cookie during development (120s), and got errors about 'Cookie “<cookieName>” has been rejected because it is...
Read more >Expires - HTTP - MDN Web Docs - Mozilla
The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 ...
Read more >HTTP/1.1: Header Field Definitions
If a response includes both an Expires header and a max-age directive, the max-age directive overrides the Expires header, even if the Expires...
Read more >What's the difference between Max-age and Expires?
Expires sets an expiry date for when a cookie gets deleted · Max-age sets the time in seconds for when a cookie will...
Read more >Express cookie-session middleware
maxAge : a number representing the milliseconds from Date.now() for expiry; expires : a Date object indicating the cookie's expiration date (expires at...
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
Ah @jackycute, good catch on the readme. That came from the cookie module and doesn’t fit well here. Let’s move the rest of this conversation to a new issue, please, so we don’t loose what the original issue was about.
Well, the thing is, JavaScript can change a
Date
object into a number without issue. Really, the weird behavior is JavaScript itself that you are describing 😃 You’re welcome to create a PR to increase the strictness of validating the input values, though!I’m not certain what happens if you are setting both
maxAge
andexpires
. I think they are supposed to be mutually exclusive. Does removingexpires
fix the issue? Perhaps we can open a new issue regarding that behavior as well.