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
- 1Compute Max-Age and Expires from the same expiration timestamp so they always agree.
- 2Prefer setting only Max-Age in modern applications and drop Expires unless a legacy client requires it.
Code examples
Derive both from one timestamp
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.
More cookies checks
- LowCookie Domain Attribute Is Too Broad
- LowCookie Missing Secure Attribute
- InfoThird-Party Cookie Missing Partitioned Attribute
- High__Host- Prefix Cookie Missing Secure Attribute
- High__Host- Prefix Cookie with Non-Root Path
- High__Secure- Prefix Cookie Missing Secure Attribute
- LowCookie Expires/Max-Age Exceeds 1 Year
- InfoCookie Name Leaks Framework or Language
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.