Skip to content

Cookie's don't clear if maxAge is set #4252

@harryjamesuk

Description

@harryjamesuk

If a cookie with a maxAge is set, performing res.clearCookie() will not clear the cookie.

We update the expiry in clearCookie() so the expires property is overriden to a past date:

res.clearCookie = function clearCookie(name, options) {
  var opts = merge({ expires: new Date(1), path: '/' }, options);

  return this.cookie(name, '', opts);
};

But then when this.cookie() is called, it sees the cookie has a maxAge property, which will override the expiry date in this code:

  if ('maxAge' in opts) {
    opts.expires = new Date(Date.now() + opts.maxAge);
    opts.maxAge /= 1000;
  }

and the cookie therefore wouldn't be cleared (In fact, it would actually cause the cookie's expiry date to be further into the future).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions