Quick Summary
- HTTP cookies are small data files stored by the browser to maintain state.
- First-party cookies are set by your domain; third-party cookies are set by external domains.
- Third-party cookies enable cross-site user profiling and retargeting.
- Safari and Firefox block third-party cookies by default; Chrome is following.
- Under the ePrivacy Directive, all non-essential cookies require explicit consent.
Introduction
Cookies are the backbone of how the web remembers users. Every login session, shopping cart, and “remember me” checkbox depends on them. But cookies have a dark side: the same technology that powers essential functionality is also the primary mechanism for tracking users across the internet.
Understanding the difference between first-party and third-party cookies, and how regulations like the GDPR and ePrivacy Directive govern them, is essential for anyone building or managing a website. Getting it wrong can result in regulatory fines, broken user trust, and compliance failures.
This guide explains how cookies work, the different types, how they enable tracking, and what you need to do to stay compliant. Whether you are a developer implementing a cookie consent banner or a founder trying to understand what your marketing tools are doing, this is the guide for you.
Session vs Persistent Cookies
Cookie Lifespans
| Type | Lifetime | Deleted When | Use Case | Risk Level |
|---|---|---|---|---|
| Session | Browser session | Browser closes | Shopping cart, navigation | Low |
| Persistent | Defined expiry (days/years) | Expiry date or manual clear | Remember login, track users | Medium–High |
Long-Lived Cookies
Max-Age=31536000) are commonly used for permanent user tracking and are a key regulatory concern. GDPR regulators view unnecessarily long cookie durations as disproportionate data collection.From a privacy perspective, session cookies are generally lower risk because they disappear when the browser closes. Persistent cookies, however, can track a user for months or years, even if they clear their browsing history, the cookie remains until its expiry date.
First-Party vs Third-Party Cookies
Who Owns the Cookie?
| Aspect | First-Party | Third-Party |
|---|---|---|
| Set by | Your domain (e.g., siteprivacyscore.com) | External domain (e.g., facebook.com) |
| Purpose | Core site functionality | Advertising, retargeting |
| Cross-site tracking | No | Yes, builds profiles across sites |
| Browser support | Fully supported | Blocked in Safari, Firefox; Chrome phasing out |
| Consent required | Only if non-essential | Always (used for marketing) |
How Third-Party Cookies Connect the Web
How Third-Party Tracking Works
A user views shoes on Site A. An ad network drops a third-party cookie. When the user visits Site B with the same ad network, it reads the cookie and shows shoe ads. The ad network now knows the user visited both sites, building a cross-site browsing profile without the user's knowledge.
This cross-site profiling is the core reason third-party cookies have become the primary target of both browser vendors and privacy regulations. When a user visits 50 sites that all load the same ad network pixel, that network can build a comprehensive browsing history.
Want to see which cookies your website is setting?
Run Free Cookie ScannerReal-World Examples
Regulatory Actions
Cookie tracking has been at the center of some of the largest privacy enforcement actions:
| Organization | Fine / Action | Issue |
|---|---|---|
| Google (CNIL, France) | €150 million | Non-compliant cookie consent, reject option harder than accept |
| Amazon (CNIL, France) | €35 million | Dropping cookies without prior consent |
| Clearview AI | €20 million | Collecting biometric data via cookies without consent |
| Criteo | €40 million | Cross-site tracking cookies without valid opt-in |
The Cookie Wall Ban
How to Detect Cookie Issues
- Run a cookie scan: Use the Cookie Scanner to identify every cookie your site sets, including domain, duration, and classification (essential vs. marketing).
- Check browser DevTools: Open DevTools → Application tab → Cookies. Look for cookies from external domains, these are third-party cookies.
- Test consent behavior: Reject all cookies via your banner, then check whether third-party cookies still appear. If they do, your consent banner is non-functional.
- Run a GDPR check: Use the GDPR Quick Check for a comprehensive compliance assessment that includes cookie analysis.
- Check for trackers: Many trackers set cookies. Run the Tracker Detector to identify all tracking scripts on your pages.
How to Fix Cookie Issues
Compliance & Development Steps
- Implement a compliant consent banner: See the Cookie Consent Banner guide for requirements. The banner must actually block non-essential scripts until the user explicitly opts in.
- Classify your cookies: Audit every cookie your site sets and classify each as “strictly essential” (no consent needed) or “non-essential” (requires consent).
- Use secure cookie attributes:
Secure Cookie Configuration
Set-Cookie: session=abc; HttpOnly; Secure; SameSite=Lax; Path=/HttpOnly prevents JavaScript access. Secure ensures HTTPS only. SameSite=Lax mitigates CSRF attacks.
- Minimize cookie durations: Set the shortest
Max-Agenecessary. Session cookies (no Max-Age) are preferable when possible. - Self-host analytics: Replace third-party analytics with self-hosted alternatives (e.g., Plausible, Umami) to eliminate third-party cookie dependencies entirely.
Best Practices
- Always use HttpOnly and Secure flags, prevents JavaScript from reading session cookies and ensures they are only sent over HTTPS.
- Set SameSite=Lax or Strict, mitigates cross-site request forgery (CSRF) and limits cookie sending to same-site contexts.
- Minimize cookie scope, use
Path=/only when necessary. Restrict cookies to the specific paths that need them. - Audit cookies quarterly, marketing teams frequently add new scripts that set cookies. Regular audits prevent “cookie creep.”
- Document every cookie, maintain a cookie register listing each cookie, its purpose, its duration, and whether it requires consent.
- Implement consent before scripts, ensure your consent banner actually blocks script execution, not just hides a popup.
- Use security headers, headers like CSP and Referrer-Policy complement cookie security by restricting which domains can be contacted.
Common Mistakes
The False Illusion of Compliance
- Showing a banner but not blocking scripts: The most common violation. The banner appears, but analytics and ad scripts fire immediately on page load, before any consent is given.
- Treating first-party analytics as “essential”: Analytics cookies are not essential under the ePrivacy Directive, even if they are first-party. They still require consent.
- Setting cookies with unnecessarily long lifetimes: A 10-year cookie for a preference setting is disproportionate. Use the shortest duration necessary.
- Missing HttpOnly on session cookies: Without
HttpOnly, a successful XSS attack can steal session cookies via JavaScript. - Forgetting server-side cookies: Cookies set by server-side code (e.g., tracking pixels, A/B testing) are often overlooked in audits. They still need consent if non-essential.
- Not testing in all browsers: Safari and Firefox block third-party cookies by default. A feature that works in Chrome may silently fail in Safari if it depends on third-party cookies.
Conclusion
Cookies are a fundamental web technology, but their use for tracking has made them the most regulated aspect of web development. Understanding the difference between session and persistent cookies, first-party and third-party cookies, and the legal frameworks that govern them is not optional, it is a compliance requirement.
Start by auditing your current cookies, implement a compliant consent mechanism, and establish a regular review process to catch new cookies added by marketing scripts.
Scan Your Website
Related Guides
Frequently Asked Questions
Can I use LocalStorage instead to avoid the cookie law?+
What defines an 'essential' cookie that doesn't need consent?+
Are first-party cookies safe?+
What happens when third-party cookies are fully blocked?+
How do I scan my website's cookies?+
How long should cookies last?+
Do I need a cookie banner if I only use essential cookies?+
Scan Your Website's Cookies
Ensure you aren't quietly dropping third-party cookies that violate the ePrivacy Directive and GDPR.
For deeper runtime checks, run the full privacy audit →