Skip to main content

How to fix: Cookie Max-Age and Expires Disagree

A cookie sets both Max-Age and Expires with lifetimes that differ by more than an hour.

Why it matters

Modern browsers use Max-Age and ignore Expires when both are present, but any legacy client, proxy, or custom HTTP client that only understands Expires will apply a different session lifetime than the one the application intended, which can extend a session's exposure window well beyond what was intended.

RFC 6265 says Max-Age takes precedence over Expires when both are set, but the two are usually generated from the same source value. A large mismatch typically means a bug (e.g. Expires computed from a stale timestamp, or a hardcoded date left over from testing) rather than an intentional dual-lifetime design.

How to fix it

  1. 1Compute Max-Age and Expires from the same expiration timestamp so they always agree.
  2. 2Prefer setting only Max-Age in modern applications and drop Expires unless a legacy client requires it.

Code examples

Derive both from one timestamp

TypeScript
const maxAgeSeconds = 3600;
const expires = new Date(Date.now() + maxAgeSeconds * 1000).toUTCString();
res.setHeader('Set-Cookie', `session=abc123; Max-Age=${maxAgeSeconds}; Expires=${expires}; Secure; HttpOnly`);

References

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

See every cookies check

Questions

How severe is Cookie Max-Age and Expires Disagree?
VulnRadar rates this low 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-maxage-expires-conflict, 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 and expires disagree

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 and Expires Disagree | VulnRadar