Cluster 15 · HTTP Cookie Security · SameSite · Secure · HttpOnly

Set-Cookie SameSite, Secure, HttpOnly, __Host- & 13-Month Max-Age Linter

Lint HTTP Set-Cookie headers for missing Secure/HttpOnly flags, broken SameSite=None without Secure, invalid __Host- prefixes, excessive >13-month Max-Age, and leaked pre-consent trackers.

100% Browser-Side · Zero User-Data Upload · Strict CSP

Compliance & Pre-Consent Control Specification

Control / Signal Compliant Baseline Engineering & Privacy Rationale
Secure Mandatory for HTTPS & SameSite=None Prevents transmitting cookies over plaintext HTTP; browsers reject SameSite=None without Secure
HttpOnly Mandatory on session/auth cookies Blocks `document.cookie` JS access to session IDs during XSS incidents
SameSite Lax (default) or Strict Mitigates CSRF attacks; reserve `SameSite=None; Secure` strictly for cross-site embeds
__Host- Prefix Secure + Path=/ + NO Domain= Binds cookie strictly to origin host, preventing subdomain cookie tossing

Hardened Session & Consent Preference Cookies (HTTP)

hardened-set-cookie.http
Set-Cookie: __Host-session=opaque_token_here; Path=/; Secure; HttpOnly; SameSite=Lax; Max-Age=2592000
Set-Cookie: consent_prefs=v2_denied; Path=/; Secure; SameSite=Lax; Max-Age=15552000

Cloudflare Workers Set-Cookie Hardening Helper

cookie-helper.ts
export function buildConsentCookie(value: string, maxAgeSec = 15552000): string {
  const safeVal = encodeURIComponent(value.slice(0, 256));
  const cappedAge = Math.min(Math.max(60, Math.floor(maxAgeSec)), 34128000); // <= 13 months
  return `consent_prefs=${safeVal}; Path=/; Secure; SameSite=Lax; Max-Age=${cappedAge}`;
}

Implementation Steps & Key Insights

  1. Switch to Tab 2 (`Set-Cookie Security & Pre-Consent Linter`) above and paste your HTTP response `Set-Cookie` headers.
  2. Ensure every session/JWT/auth cookie sets `Secure; HttpOnly; SameSite=Lax` (or `Strict`) and uses `__Host-` with `Path=/` and no `Domain=`.
  3. Cap consent and analytics cookie lifetimes at `<= 34128000` seconds (~13 months) per CNIL/ePrivacy guidance (6 months = `15552000` for refusal storage).
  4. Eliminate pre-consent `_ga`, `_fbp`, or `__hstc` `Set-Cookie` headers on unauthenticated landing routes.
  • Modern Chrome/Firefox/Safari silently reject `SameSite=None` cookies that omit `Secure`.
  • Setting `Domain=.example.com` invalidates `__Host-` cookies and allows compromised subdomains (`blog.example.com`) to overwrite parent auth cookies.
  • Pair cookie attribute hardening with CSP + HSTS checks in Cluster 4 (`/security-headers/`).

Common Pre-Consent Pitfalls

  • Setting `SameSite=None` without `Secure` during local HTTP dev and shipping it to production.
  • Setting `Max-Age=63072000` (2 years) on tracking cookies in violation of EU 13-month retention norms.
  • Putting `HttpOnly` on a client-readable CMP cookie if your frontend JS needs to read `consent_prefs` directly (use `Secure; SameSite=Lax` without `HttpOnly` for non-sensitive UI preference flags, or store auth separately).
Verify Live: Audit your production site on consent.runglab.dev or grab the $39 ConsentCheck Compliance Pack. Not legal advice.

More GDPR, Consent Mode v2 & GPC Implementation Guides

← Back to GDPR & Consent Mode v2 Hub · ConsentCheck Live Audit → · $39 Compliance Pack → · Cluster 4: Security Headers → · Cluster 11: PCI & SRI →

Frequently Asked Questions

Why does `__Host-` forbid setting a `Domain=` attribute?

The `__Host-` prefix guarantees a cookie is scoped strictly to the exact origin hostname that set it (`Path=/`, `Secure`, no `Domain=`), defending against subdomain cookie fixation.

Should my CMP consent-preference cookie use `HttpOnly`?

Only if your server reads it exclusively; if client-side JS reads saved CMP preferences to initialize Consent Mode v2 synchronously, omit `HttpOnly` on the non-sensitive preference flag while enforcing `Secure; SameSite=Lax`.

Does ConsentCheck audit live response `Set-Cookie` headers?

Yes — visit https://consent.runglab.dev/?ref=tool-consent-cluster to audit both live HTTP `Set-Cookie` headers and headless browser runtime cookies.