Monitory
← All guides

Guides

Cookie consent and cookie security: what to check and fix

Which cookies need consent before a visitor agrees, which flags every cookie needs and how to keep both under control.

Two different problems

Cookies raise two questions that are easy to confuse. Consent: may you set this cookie before the visitor agrees? Security: is the cookie protected against theft and forgery? Both can be checked automatically.

Consent

Under the GDPR and the ePrivacy Directive, tracking must wait until the visitor agrees to it. A first visit, with nothing clicked, should therefore show:

  • No tracking cookies: none from Google Analytics (_ga, _gid), Google Ads, the Meta pixel (_fbp), Hotjar, Microsoft Clarity and Ads, LinkedIn, TikTok and similar.
  • Tracker scripts held back by a consent manager: Google Analytics, Google Tag Manager, the Meta pixel, Hotjar, LinkedIn Insight, the TikTok pixel and Microsoft scripts.
  • No Google Fonts loaded from Google's servers. Loading them sends every visitor's IP address to Google before any consent. A German court fined a site for this in 2022. Download the fonts and serve them from your own domain instead.

To fix tracking before consent, load tracking only after consent with a consent manager such as Cookiebot, OneTrust, Didomi, Axeptio or Klaro, and enable Google Consent Mode in Tag Manager. This is a first signal, not legal advice: ask your data protection officer about your own situation.

Security

Every cookie your site sets should carry three flags:

  • HttpOnly: session cookies must not be readable by JavaScript, so a cross-site scripting bug cannot steal them.
  • Secure: on an HTTPS site, a cookie should only travel over HTTPS.
  • SameSite: declare Lax, Strict or None, which protects against cross-site request forgery.

In Laravel, set SESSION_SECURE_COOKIE=true and keep http_only set to true and same_site set to lax in config/session.php. In plain PHP, set session.cookie_secure, session.cookie_httponly and session.cookie_samesite. Cookies from a plugin or tracker need the plugin updated or configured.

Keep watching

New trackers arrive with a marketing tag or a plugin update. The consent check visits your page once a day as a first-time visitor and fails when tracking cookies are set before consent. The cookie security check inspects every cookie once a day and fails when a session cookie is missing HttpOnly or Secure.

Keep reading