- Missing HTTP cookie flags or unsafe proxy caching, allowing XSS scripts, downgrade attacks or shared CDN caches to expose another user’s session cookie.
- Pre-consent marketing and analytics cookies, where a tag manager or CMS plugin drops
_ga,_fbp,_gcl_auorhubspotutkon a cold unauthenticated visit before an EU visitor clicks accept.
This handbook explains every Set-Cookie security flag under RFC 6265bis, why Cache-Control matters whenever Set-Cookie is present, and how to verify your live production site from outside without logging raw cookie values.
The five Set-Cookie security controls that matter
1. Secure (always on over HTTPS)
A cookie without Secure is sent automatically by browsers over plain http:// if a user clicks an unencrypted link or sits on an intercepted Wi-Fi network. Every authentication, checkout and preference cookie on an HTTPS site should include Secure alongside HTTP Strict Transport Security (Strict-Transport-Security).
2. HttpOnly (mandatory for session tokens)
HttpOnly blocks client-side JavaScript (document.cookie) from reading the cookie. If an XSS bug ever slips into a page, HttpOnly stops injected scripts from reading the session token directly. Reserve non-HttpOnly cookies strictly for intentional client-read tokens such as double-submit CSRF cookies (xsrf-token) or UI theme preferences.
3. SameSite=Lax or SameSite=Strict
SameSite controls whether browsers attach cookies to cross-site requests, closing the majority of Cross-Site Request Forgery (CSRF) attacks:
SameSite=Lax(recommended default for login sessions): sends the cookie on normal top-level link navigations while blocking cross-sitePOSTforms and background requests.SameSite=Strict: never sends the cookie on any cross-site navigation (ideal for sensitive admin panels or banking flows).SameSite=None: required only for intentional cross-site embedded widgets, and browsers rejectSameSite=NoneunlessSecureis also set.
4. The __Host- cookie prefix
Prefixing a session cookie name with __Host- (for example __Host-session=...; Secure; HttpOnly; SameSite=Lax; Path=/) instructs modern browsers to reject the cookie unless all three rules hold: Secure is present, Path=/ is set, and no Domain= attribute is specified. That locks the cookie strictly to the exact origin host so a compromised subdomain (blog.example.com or a dangling staging CNAME) cannot plant or overwrite session cookies on app.example.com.
5. Respect the 400-day browser lifetime cap
Under RFC 6265bis, Chromium and modern browsers clamp any Max-Age or Expires value longer than 400 days. For authenticated sessions, use much shorter rolling lifetimes (hours or days) and rotate session IDs on login and privilege changes.
Check it now. The cookie security & GDPR pre-consent checker audits HTTP Set-Cookie Secure, HttpOnly, SameSite, __Host- and 400-day lifetime rules without storing values, flags pre-consent tracking cookies/scripts and checks CDN Cache-Control safety; the Content-Security-Policy (CSP) checker audits HTTP and meta Content-Security-Policy headers against XSS bypasses (unsafe-inline, unsafe-eval, wildcards, missing object-src/base-uri), frame-ancestors clickjacking rules and live third-party script hosts. No account, and the address is not stored.
The hidden CDN killer: Set-Cookie without Cache-Control
One of the highest-impact web incidents in production occurs when an origin server sends a Set-Cookie header (such as a PHP PHPSESSID, WooCommerce cart session or logged-in token) on a response that omits Cache-Control: private or Cache-Control: no-store.
If a CDN edge rule (Cloudflare, Fastly, Varnish or Nginx FastCGI cache) overrides default cookie bypass behavior and caches that HTTP response, the next visitor requesting the same URL receives the previous visitor’s Set-Cookie header and lands directly inside their cart or account.
Always pair dynamic responses that emit Set-Cookie with:
Cache-Control: private, no-storeAnd verify that public cacheable marketing pages send zero Set-Cookie headers on a cold unauthenticated GET.
EU GDPR & ePrivacy pre-consent hygiene
Across the European Union and EEA, strictly necessary technical cookies (such as load-balancer stickiness, active shopping cart state or security CSRF tokens) do not require prior consent, whereas analytics, session-replay and advertising trackers (_ga, _gid, _fbp, _gcl_au, _uetvid, hubspotutk, _hjSession) must wait until the visitor actively opts in.
A quick cold unauthenticated check catches two frequent regressions:
- Server-side or edge cookies dropped immediately on first visit before any banner interaction.
- Unblocked
<script src="...">tags (Google Tag Manager, Meta Pixel, TikTok, Hotjar) firing in raw initial HTML without Consent Management Platform (CMP) gating.
Test any public page right now without logging in using our cookie security & GDPR pre-consent checker — it inspects names, flags, pre-consent trackers and cache headers in memory while never echoing or storing raw cookie values.
Copy-paste cookie hardening snippets
Nginx (proxy_cookie_flags)
location / {
proxy_cookie_flags ~ secure httponly samesite=lax;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
}Node / Express (__Host- session cookie)
res.cookie('__Host-session', token, {
httpOnly: true,
secure: true,
sameSite: 'lax',
path: '/',
maxAge: 7 * 24 * 60 * 60 * 1000,
});
res.setHeader('Cache-Control', 'private, no-store');How Beamfar helps
Beamfar’s daily external security checks audit session cookie flags (Secure, HttpOnly, SameSite — reading cookie names only, never storing values), verify HSTS, Content-Security-Policy and OWASP headers, and alert whenever unexpected third-party scripts appear on your live pages alongside two-region EU uptime confirmation. Test any live site free in our cookie security & GDPR pre-consent checker or Content-Security-Policy (CSP) checker.
Questions
Should CSRF cookies have the HttpOnly flag?
When using the double-submit cookie pattern where frontend JavaScript reads the CSRF token cookie to place it in a custom request header, that specific CSRF cookie cannot be HttpOnly (though it should still carry Secure and SameSite=Lax or Strict). Actual authentication and session cookies must always be HttpOnly.
Why does a marketing homepage not need Set-Cookie headers?
Static marketing pages, blog articles and documentation perform faster and stay cleaner under EU privacy rules when they send zero Set-Cookie headers on a cold visit — allowing CDNs to cache them safely at the edge with zero risk of cross-user cookie leaks.
What breaks when SameSite=None is sent without Secure?
Chrome, Firefox, Safari and Edge reject SameSite=None cookies unless the Secure attribute is also present over HTTPS, silently breaking embedded widgets or cross-site checkout redirects.
Does the Beamfar cookie checker store my site’s cookie values?
No. Both the free cookie checker and continuous security monitoring inspect only cookie names and attribute flags in memory and never echo, log or store raw cookie values.
Sources
Read on . Standards and vendor pages change; confirm the current text before you rely on it.
- IETF RFC 6265bis — HTTP State Management Mechanism (Cookies) (datatracker.ietf.org)
- MDN Web Docs, Using HTTP cookies & Cookie Prefixes (developer.mozilla.org)
- OWASP Session Management Cheat Sheet (cheatsheetseries.owasp.org)