res.cookie does not allow setting Max-Age only, without Expires (One should be able to set maxAge alone, with expires: 0)
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- javascript, nodejs
- Domain
- backend
Research direction
Start in lib/response.js around lines 871-878, where res.cookie derives Expires from maxAge. Compare the current options handling with the issue's expires: 0 example, then verify that the resulting Set-Cookie header contains Max-Age and Path without Expires.
Written by the indexing model from the issue text.
Description
I want to set a cookie with Max-Age only, without having Expires. But the following lines 875-876 keep adding the unwanted Expires:
Setting expires: 0 does no good to override that behavior.
I think one should be allowed to only set Max-Age without automatically having Expires also set.
res.cookie('MyCookie', 'TheValue', {
expires: 0, // I don't want any Expires in the resulting Set-Cookie statement
maxAge: 60000,
});
Actual result:
MyCookie=TheValue; Max-Age=60; Path=/; Expires=Sun, 26 Mar 2023 06:00:31 GMT
Desired result:
MyCookie=TheValue; Max-Age=60; Path=/;
Workaround
The workaround for this is our having to manually write the Set-Cookie statement, possibly mimicking the same logic in the express code.
Possible solution
if (opts.expires !== 0) {
opts.expires = new Date(Date.now() + maxAge)
}
- Dominant language
- JavaScript
- Stars
- 69.7k
- Forks
- 25.6k
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 4
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from expressjs/express
-
Outdated res.send() syntax in lib/response.js documentation exampleMay be free again A pull request for this issue was closed without being merged. Opendocs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
expressjs/express#7588 · 1 comment ·
Maintainers usually reply within 1 day
-
4.x deps module:body-parser
Difficulty 1/5 Under an hour Newbie friendliness 75/100
expressjs/express#7564 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
-
Update to mocha 12.xPossibly taken @ganeshghutukade-04 claimed this 26 days ago. Opendeps
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
expressjs/express#7547 · 6 comments ·
Maintainers usually reply within 1 day
-
req.subdomains splits an IPv6 host that contains dotsPossibly taken @johnnyhuirilef claimed this 30 days ago. Open4.x 5.x bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
expressjs/express#7532 · 2 comments ·
Maintainers usually reply within 1 day
-
Readme: project name 'express.js' is not capitalizedMay be free again A pull request for this issue was closed without being merged. Open
Difficulty 1/5 Under an hour Newbie friendliness 95/100
Maintainers usually reply within 1 day
All issues in expressjs/express
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
anothaDev/luci-theme-vantage#143 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kingcharleslzy-ai/dsh-purge#282 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
a-corriger bug
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
christian-raj/S-Aloha#340 ·
-
area:image documentation good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day