HTTP Cookies: Understand How Sessions, Security and Tracking Really Work

HTTP cookies are small name–value pairs that allow Web applications to maintain state across separate HTTP requests. In this handout, we will examine cookie attributes such as Domain, Path, Secure, HttpOnly, Expires, Max-Age and SameSite, and understand how they determine when a cookie is stored and sent. We will also study session cookies, which are often used to maintain authenticated sessions, and SameSite cookies, which regulate whether cookies can accompany same-site or cross-site requests. Finally, we will analyse third-party cookies, their role in cross-site contexts and tracking, and the broader classification of cookies by lifetime, context of use and purpose.

Cookies

Key points

  • HTTP cookie = small name–value pair stored by the browser and automatically returned to the server when specified conditions are satisfied.
  • Cookies → allow applications to associate successive HTTP requests with previously stored state; HTTP itself remains a stateless protocol.
  • Cookie exchange → server sends Set-Cookie in an HTTP response; browser stores the value and returns it through the Cookie request header.
  • Cookie ≠ session: a cookie may contain a session identifier, while the corresponding authentication state and user information remain on the server.
  • Cookie attributes → control storage, scope, lifetime, and security; the browser evaluates these rules before deciding whether to send a cookie.
  • Domain → defines eligible hosts; Path → restricts URL paths; omitting Domain normally limits the cookie to the host that created it.
  • Secure → restricts transmission to secure connections; HttpOnly → prevents ordinary JavaScript access without blocking transmission through HTTP requests.
  • Expires ≠ Max-Age: Expires specifies an expiration date, while Max-Age defines a lifetime in seconds and takes precedence when both exist.
  • SameSite → controls cookie transmission in same-site and cross-site contexts, distinguishing requests associated with different websites.
  • SameSite=Strict → allows only same-site requests; Lax → also permits certain top-level cross-site navigations; None → permits cross-site use and requires Secure.
  • Cross-site navigation ≠ cross-site resource request: navigation changes the main document, while resource requests retrieve external content without leaving the current page.
  • Session management → authentication → server creates session identifier → browser stores cookie → subsequent requests identify the session → server validates access.
  • Logout → requires invalidating the server-side session and requesting cookie deletion; removing the cookie alone does not necessarily invalidate the session.
  • Session cookies ≠ persistent cookies: session cookies lack an explicit expiration time, while persistent cookies use Expires or Max-Age.
  • First-party ≠ third-party cookies: the distinction concerns the context in which cookies are used, not their purpose or whether they enable tracking.
  • Third-party cookies → may enable cross-site tracking when an external service recognizes the same browser across multiple websites, subject to browser restrictions.
  • External script ≠ third-party cookie: JavaScript downloaded from another domain can execute within the visited page and use cookies associated with that site.
  • Cookie classification → lifetime, context of use, and purpose are independent dimensions; persistence and first-party status do not determine tracking behavior.
  • Cookie purposes → technical functionality, preferences, analytics, and profiling; classification depends on actual use rather than the cookie’s name.
  • Italian privacy rules → technical cookies generally serve necessary functions; qualifying analytics cookies may be treated similarly, while profiling cookies normally require prior consent.

Do you want to help me write articles like this one?

Leave a Reply

Your email address will not be published. Required fields are marked *

No responses yet

Sostieni il progetto

Tutti i materiali che condivido nascono da una convinzione molto semplice: una buona formazione non dovrebbe limitarsi a insegnare quali pulsanti premere, ma aiutare a comprendere le idee, i principi e i processi che stanno dietro agli strumenti.

Per questo dedico una parte significativa del mio tempo a studiare, organizzare e produrre contenuti gratuiti dedicati al multimedia, al design e alla comunicazione visiva. Articoli, lezioni, approfondimenti e risorse che hanno l’obiettivo di rendere accessibili argomenti spesso affrontati in modo frammentario o superficiale.

Questo lavoro richiede però tempo, ricerca e cura. Ogni guida, ogni video, ogni materiale pubblicato gratuitamente è il risultato di molte ore di studio, scrittura e revisione.
Sostenere il progetto attraverso Patreon significa permettermi di continuare a produrre contenuti educativi di qualità, mantenerli accessibili al maggior numero possibile di persone e dedicare più energie alla costruzione di una risorsa che possa essere utile a studenti, professionisti e appassionati.

Se credi che una conoscenza più profonda, rigorosa e consapevole del multimedia abbia valore, il tuo contributo non sostiene soltanto il mio lavoro: aiuta a rendere queste risorse disponibili per tutta la comunità.
Grazie per il supporto e per la fiducia.

Patreon è troppo impegnativo?

Puoi sostenermi anche con una donazione libera, senza abbonamento e senza impegno.
Anche un piccolo contributo mi aiuta a continuare a creare giochi, contenuti didattici e materiali gratuiti con più libertà.

Support the project

All the materials I share stem from a very simple conviction: good training should not be limited to teaching which buttons to press, but should help people understand the ideas, principles, and processes behind the tools.

That is why I dedicate a significant portion of my time to researching, organizing, and producing free content focused on multimedia, design, and visual communication—articles, lessons, in-depth analyses, and resources aimed at making accessible topics that are often addressed in a fragmented or superficial way.

However, this work requires time, research, and care. Every guide, video, and piece of material published for free is the result of many hours of study, writing, and revision.
Supporting the project via Patreon enables me to continue producing high-quality educational content, keep it accessible to as many people as possible, and devote more energy to building a resource that benefits students, professionals, and enthusiasts alike.

If you believe that a deeper, more rigorous, and informed understanding of multimedia is valuable, your contribution does more than just support my work: it helps make these resources available to the entire community.
Thank you for your support and trust.

Is Patreon too demanding?

You can also support me with a voluntary donation—no subscription or commitment required.

Even a small contribution helps me continue creating games, educational content, and free materials with greater freedom.