skipnothing/HTTP & Networking

Cookies & SameSite

Run curl -v -b jar -c jar https://app.example.com twice and the second run prints a line you never typed: a Cookie header carrying the value the server handed back on the first response, replayed with no code re-sending it.

  • ▸One URL pair, two verdicts: the read is blocked as cross-origin, yet the cookie still rides to the neighbor subdomain.
  • ▸Do nothing and Chromium still drops the cookie when another page embeds yours: its silent 2020 default change stripped it.
  • ▸Reach for the most permissive value and the browser still discards the cookie unless you also lock it to https.
BUILDS ON
01

The Set-Cookie Round-Trip

A server answers your request with an extra line: Set-Cookie: session=9f3a; Path=/. You did nothing with it. Yet load the same host again in a browser and a line you never wrote appears in what it sends: Cookie: session=9f3a. (curl -v prints that line only when you hand it a cookie jar with -b jar -c jar.) The browser stored the value the server handed back and replayed it, unasked, on the next request to that host. A cookie is that round-trip: the server writes it once with Set-Cookie, the client returns it on every later request in the Cookie header, and nothing in your code re-sends it.

Change the host you request and the replay stops, as long as the cookie names no Domain: the browser then attaches it only to requests headed back to the host that set it. Domain=example.com widens it to every subdomain, api.example.com included.

BUILD THE SET-COOKIE THAT REACHES THE RIGHT HOSTS

Keep going, sign up to unlock the rest

4 more parts in this topic, plus 23+ more topics in HTTP & Networking.

Sign up, it's freeSee the full HTTP & Networking