Definition
HTTP Cookie
A cookie is a small piece of data that a server attaches to an HTTP response via the
Set-Cookieheader. Because HTTP itself is stateless — each request is processed independently — cookies let the application implement stateful behaviour, such as authentication, personalisation, and (cross-site) tracking, by being sent back on subsequent requests.The browser stores cookies in a cookie jar, one per site, and attaches them to every request whose URL matches. Only the cookie name/value is attached to outgoing requests; attributes and flags are only specified when the cookie is set.
Attributes and Flags
Cookie attributes and flags
Attribute / flag Meaning Expires,Max-Agewhen the cookie expires; Max-Agetakes precedence; unset deleted when the browser closes; negativeMax-Ageor pastExpiresdelete nowDomainscope widening: if set, cookie is sent to the host and all its subdomains; the value can reach up to eTLD+1 of the setting domain. A same-site attacker can both read and set domain cookies — set it only when unavoidable Paththe cookie is sent only if its path is a prefix of the request URL’s path SameSitewhether the cookie is sent on cross-site requests — see SameSite Cookie Securecookie is sent only over HTTPS, and cannot be set or overwritten via HTTP (protection against a network attacker) HttpOnlyJavaScript cannot read the cookie via document.cookie; defence in depth against XSS stealing the session cookie
Leading dot makes no difference
Domain=.example.comandDomain=example.comare equivalent — the dot is cosmetic. Subdomain cookies reach the apex; never setDomainunless the application genuinely spans origins.
SameSite behaviour
Definition
Link to originalSameSite Cookie
The
SameSiteattribute of an HTTP cookie determines whether the cookie is attached to cross-site requests — requests where the site that initiates the request differs from the site the cookie belongs to. It has four possible values:
Value Behaviour Noneattach to cross-site requests; Securemust be enabledLaxattach only to top-level cross-site navigations using a safe method ( GET)Strictnever attach to cross-site requests (unspecified) usually defaults to Laxafter 2 minutesA request from
example.comthat embeds an image frompics.comcrosses sites; whether the cookie onpics.comis sent topics.comalong with that image fetch is exactly whatSameSitedecides.