express icon indicating copy to clipboard operation
express copied to clipboard

`res.clearCookie()` does not ignore `maxAge`

Open tjarbo opened this issue 2 years ago • 8 comments

Hi everyone! I just ran into a bug, where res.clearCookie() does not work properly.

What happen?

According to the typescript definitions, res.clearCookie() accepts CookieOptions as a second parameter (see here) which includes the maxAge attribute. But if the maxAge is set, the cookie won't be deleted.

What do I expect?

.clearCookie()should ignore (or delete) the maxAge attribute, because it is used to calculate the expire attribute afterwards in .cookie();

Research

I already located the bug and would like to provide a pr to fix this.

tjarbo avatar Mar 08 '22 15:03 tjarbo

I had the same problem a few days ago, thanks for the pr i want to try when it merged

yagmurmutluer9 avatar Mar 13 '22 13:03 yagmurmutluer9

Thank you for your work on this @tjarbo !

dougwilson avatar Mar 13 '22 18:03 dougwilson

Please see #4252 for related discussion. This was original designed this way on purpose (ugh), and I see it being used in the wild this way. We can land such a change in the 5.0 branch, so I'm setting it to 5.0.

dougwilson avatar Mar 24 '22 03:03 dougwilson

Added a review for tgarbo's PR

Segmentational avatar Jun 28 '22 19:06 Segmentational

Thank you @Segmentational !

tjarbo avatar Jul 04 '22 09:07 tjarbo

Since #4252 is closed, I'll continue the discussion here:

As all the other options (domain, sameSite, etc) needs to be the same when clearing the cookie as when setting it, the natural thing to do is use the same const OPTIONS when clearing the current cookie as when setting it. Anything that depends on the current behaviour is obviously broken. If a new major is needed to fix this, then a new major is needed asap.

Big thanks to @tjarbo for identifying the problem and provding a PR!

kaj avatar May 10 '23 10:05 kaj