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

Don't automatically add Expires in res.cookie if expires option is explicitly set to 0 #5151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,9 @@ res.cookie = function (name, value, options) {
var maxAge = opts.maxAge - 0

if (!isNaN(maxAge)) {
opts.expires = new Date(Date.now() + maxAge)
if (opts.expires !== 0) {
opts.expires = new Date(Date.now() + maxAge)
}
Comment on lines -875 to +877
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Allowing opts.expires to be of type number breaks the consistency, that in all other cases expires is of type Date. This is also enfored by the TS' type defintion @types/express as defined here.

Based on my comment on #5150 (comment), I would propose to remove opts.expires = new Date(Date.now() + maxAge) entirely. Developers can still set this value as part of the function call. The maintainers will need to decide if this would be a breaking-change.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tjarbo thank you your feedback. I put zero because the docs said:

expires | Date | Expiry date of the cookie in GMT. If not specified or set to 0, creates a session cookie.

Ref https://github.com/expressjs/expressjs.com/blob/867a10d748c4f5c83dfdbc634e210621aa1a34a9/_includes/api/en/4x/res-cookie.md

opts.maxAge = Math.floor(maxAge / 1000)
}
}
Expand Down