Skip to main content

How to fix: Cookie Max-Age=0 Deletion Pattern

Max-Age=0 instructs the browser to delete the named cookie immediately. This is the canonical cookie deletion pattern used on logout. Repeated occurrences outside logout endpoints may indicate a double-delete bug.

Why it matters

If Max-Age=0 is emitted on non-logout routes, it may unexpectedly delete user sessions or other cookies, causing functionality failures. If the same cookie is set and deleted in the same response, the deletion takes precedence in some browsers.

Max-Age=0 is the correct and portable way to delete a cookie. However, emitting it outside dedicated logout or session-reset endpoints indicates either a bug or a race condition where a cookie is being both set and deleted in the same response.

How to fix it

  1. 1Restrict Max-Age=0 Set-Cookie emission to logout and session-reset endpoints only.
  2. 2Verify no response sets and deletes the same cookie in the same response.

Code examples

Logout endpoint cookie deletion

TypeScript
// Only on the logout endpoint
res.setHeader('Set-Cookie', '__Host-session=; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=0');
res.redirect('/');

References

Detected automatically by VulnRadar. The check id is cookie-max-age-zero, stable across every scan so you can filter or diff on it.

See every cookies check

Questions

How severe is Cookie Max-Age=0 Deletion Pattern?
VulnRadar rates this info severity in the cookies category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id cookie-max-age-zero, which stays the same between runs so you can filter, diff, or gate CI on it.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for cookie max-age=0 deletion pattern

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

How to fix: Cookie Max-Age=0 Deletion Pattern | VulnRadar