Skip to content
BENIBIX Learn

SameSite Cookie Attribute

Development🔐 SecurityDefences

Also known as SameSite, SameSite Cookie, SameSite=Lax, SameSite=Strict, SameSite=None

A cookie setting. It keeps the cookie off requests that start on other sites.

Think of it like

Think of it like a pass that only works at the front door. Use a side door, and it does not count.

Example

Emma sets her login cookie to SameSite=Lax. A bad page posts a hidden form to her app. The browser sends it with no cookie, so the request fails.

Why it matters

One word on the cookie stops most forged requests, even where an app forgot its form check.

Definition

SameSite is a setting on a cookie that says when the browser may send it. A request that starts on another site can leave the cookie behind. Lax keeps it off forms and hidden requests from other sites, but sends it when you click a link. Strict keeps it off every request that starts on another site. None always sends it, and then the cookie must be Secure.

Example code

http
Set-Cookie: session=7f3a9c; Secure; HttpOnly; SameSite=Lax
Lax: the cookie goes with links from other sites, but not with their forms.
The lit-up box on the right: Lax leaves the cookie off a form from another site.

Common mistake

Setting it to None to fix a login bug. Then the cookie goes with every request from other sites again.

Key takeaways

  1. 1
    Lax. Sent on links, not on forms from other sites.
  2. 2
    Strict. Never sent on requests from other sites.
  3. 3
    None. Always sent, and must be Secure.

Compare