SECURITY & PRIVACYAI-REVIEWED

What are HTTP cookies?

Useful first: HTTP · optional, not a requirement

Choose your depth

Stay with the essentials, or look closer.

Simple explanation
2 min read · estimate

YOUR GOALUnderstand how a cookie helps a website remember something between requests.

A small note for the next visit.

Remember a choice

Imagine choosing a compact layout on a reading website. The site can ask your browser to save a cookie such as layout=compact. On a later matching request, the browser can return that value so the server can use your choice.

A cookie is data, not a program that runs by itself.

[1]

The same mechanism has different uses

Cookies can support preferences, sign-in sessions, and tracking. Their purpose depends on how a site uses the values. Calling something a cookie does not tell you whether it is necessary or privacy-friendly.

Browsers can block or delete cookies, so a website cannot assume its note will always come back.

[1] [3]

Cookies or cache?

A browser cache can keep copies of responses, such as images, to reuse later. Cookies instead carry small remembered values, such as a layout choice or a sign-in identifier, with matching requests.

Deleting cookies can reset preferences or make a site ask you to sign in again. Clearing only cached images and files is a different action: it removes those saved copies. Check which data categories your browser will remove.

[1] [7] [8] [9]
THE IDEA TO KEEP

A cookie carries a small remembered value into later eligible requests.

ONE THING TO WATCH OUT FOR

Every cookie is a tracking program.

A cookie is stored data; preferences, sessions, and tracking are different uses of it.

A QUICK CHECK, NOT A TEST
A reading site receives layout=compact in a later request. What can this help it do?
Show the explanation

Choose the layout associated with that preference. The value can inform the site's response. Cookies do not automatically execute code or grant access to all other websites' data.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP
Was this explanation clear?
Report a mistake by email
Basic explanation
2 min read · estimate

YOUR GOALDistinguish response instructions, returned values, and the scope that selects a cookie.

Follow the value across two requests.

Two headers, opposite directions

A response from https://read.example might contain:

Set-Cookie: layout=compact; Path=/; Max-Age=3600; Secure; SameSite=Lax

If accepted, a later same-site HTTPS request to that host may include:

Cookie: layout=compact

Set-Cookie tells the browser what to store. Cookie carries selected name-value pairs back. The request does not repeat the expiry or security attributes.

[2] [3] [4]

Where the note can travel

With no Domain attribute, this cookie belongs only to read.example; it is not also sent to images.read.example. Setting an allowed Domain expands host coverage to that domain and its subdomains.

Path=/ covers all paths on the eligible host. A cookie scoped to /notes matches /notes/42, but not /notebook. Other cookie rules must still pass. Path filtering is not a security wall between applications.

[2]

How long can it last?

Max-Age=3600 requests a one-hour lifetime, not guaranteed retention. A session cookie omits both Max-Age and Expires. Browser session restoration can preserve it across restarts, so closing a window is not reliable logout.

[1] [2]

A session identifier is not the whole session

In a server-managed session, the cookie holds an opaque identifier: a value meaningful to the server rather than a readable account record. The server looks it up to find the associated session and permissions.

Removing that browser cookie and invalidating the server's session are different actions. A proper logout must also make the old server session unusable.

[6]
THE IDEA TO KEEP

Storage instructions go in Set-Cookie; eligible values return in Cookie, with server state managed separately.

ONE THING TO WATCH OUT FOR

Deleting a cookie necessarily deletes the matching server session.

Deleting browser storage does not itself invalidate the server-side record.

A QUICK CHECK, NOT A TEST
read.example sets a cookie with no Domain and Path=/notes. Which later same-site HTTPS request matches both host and path rules?
Show the explanation

https://read.example/notes/42 Only the original host and the matching /notes path qualify here; expiry, security settings, and browser policy must also allow sending.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP
Was this explanation clear?
Report a mistake by email
Advanced explanation
3 min read · estimate

YOUR GOALEvaluate cookie protections without mistaking any one attribute for complete session security.

Separate transport, script access, and request context.

Different controls protect different boundaries

For an ordinary remote website, Secure requires HTTPS when sending the cookie; it does not encrypt the stored value. HttpOnly prevents page JavaScript from reading it through cookie APIs, but eligible JavaScript-initiated requests can still carry it.

SameSite limits cross-site sending. Explicit Lax permits some top-level navigations using safe methods, such as following a GET link. None permits cross-site use and requires Secure; browser privacy restrictions can still block it.

[3] [4]

Why HttpOnly is not proof of user intent

Suppose an application accepts a change-of-address request merely because a session cookie accompanies it. An attacker may try to make the visitor's browser send that request without permission. This is cross-site request forgery, or CSRF; the attacker need not read the cookie first.

Use the framework's CSRF defenses, such as server-validated tokens for state-changing requests, and suitable request-origin checks. SameSite is useful protection, but its presence alone does not establish that every action was intended.

[5]

Recognize the limits of a token

A session cookie is a credential when possession lets someone act as the signed-in user. The server must enforce session expiry and invalidate the session at logout; a browser-side lifetime is not a substitute.

For a hypothetical notes app, protecting the session token and checking permission to edit each note are separate requirements. Receiving a valid session does not automatically authorize every operation.

[6]
THE IDEA TO KEEP

Cookie attributes reduce specific risks; the server still owns authorization and session lifetime.

ONE THING TO WATCH OUT FOR

HttpOnly means JavaScript cannot cause an authenticated request.

It restricts cookie access, but the browser can attach the cookie to eligible requests initiated by scripts.

A QUICK CHECK, NOT A TEST
A valid session cookie is Secure and HttpOnly. A same-origin HTTPS fetch meets all sending rules. What happens?
Show the explanation

The browser can attach it even though page JavaScript cannot read its value. Reading a cookie through JavaScript and the browser attaching it to a permitted request are different operations.

Progress is saved only in this browser.

KEEP EXPLORINGHTTP
Was this explanation clear?
Report a mistake by email
GO STRAIGHT TO THE SOURCE

Keep asking. Check the details.

Source-checked using AI (OpenAI Codex) on . The checks covered sources, examples, and quizzes for this article version.

No human review is claimed. AI review can miss errors; check the original sources below.

  1. MDN — Using HTTP cookies
  2. RFC 6265 — Cookie scope, lifetime, and returned attributes
  3. MDN — Cookie request header
  4. MDN — Set-Cookie security and SameSite attributes
  5. OWASP — Cross-Site Request Forgery Prevention
  6. OWASP — Session Management
  7. MDN — HTTP caching guide
  8. Chrome Help — What deleting cookies can change
  9. Chrome Help — Separate browsing-data categories
How explanations are prepared