How to fix: Vary: Cookie Missing on Cookie-Bearing Response
The response sets cookies but does not include a Vary: Cookie header, and the response is not marked Cache-Control: no-store/no-cache/private. A shared cache (CDN, reverse proxy) that stores this response may serve one user's cookie-gated content to a different user requesting the same URL. Static assets are not reported: their bytes are identical for every visitor, and Vary: Cookie on one is itself a defect (see vary-cookie-on-static-resource).
Why it matters
If a shared cache stores this response without varying by Cookie, a different user requesting the same URL can receive another user's session-specific or personalized content, including authentication state or PII.
Vary: Cookie tells caches that the response content differs based on the Cookie header value. When cookies are present (indicating per-user state) but Vary: Cookie is absent, a CDN or reverse proxy configured to cache this response may store and replay one user's response to another. This risk only applies when the response can actually be stored by a shared cache; Cache-Control: no-store, no-cache, or private already rule that out.
How to fix it
- 1Add Vary: Cookie to any response that sets cookies and can be stored by a shared cache.
- 2For responses that must never be shared between users, prefer Cache-Control: private or no-store instead of (or in addition to) Vary: Cookie.
- 3Audit CDN and reverse proxy configuration to confirm Vary: Cookie is honored per distinct value, not treated as a simple cache on/off toggle.
Code examples
Nginx: vary auth-gated responses by cookie
location /account/ {
add_header Vary "Cookie" always;
# Or avoid shared caching entirely for this path:
# add_header Cache-Control "private, no-store" always;
}Next.js headers config
// In next.config.mjs: mark cookie-gated API responses so shared caches don't mix users
export default {
async headers() {
return [{
source: '/api/account/:path*',
headers: [
{ key: 'Vary', value: 'Cookie' },
],
}];
},
};References
Detected automatically by VulnRadar. The check id is vary-header-cookie, stable across every scan so you can filter or diff on it.
More config checks
- MediumNo Rate-Limit Policy Detected
- LowSet-Cookie Header Exceeds 4 KB
- LowVary Header Missing on Compressed Responses
- InfoDownloadable Content Served as inline
- InfoX-XSS-Protection Header Is Deprecated
- LowServer-Timing Exposes Cache Timings
- LowVary: Cookie on Static Resource
- MediumCORS Endpoint Missing Vary: Origin
Questions
- How severe is Vary: Cookie Missing on Cookie-Bearing Response?
- VulnRadar rates this medium severity in the config 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 vary-header-cookie, 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.