# SameSite Cookie Attribute

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

**Field:** Software Development  
**Category:** Security  
**Also known as:** SameSite, SameSite Cookie, SameSite=Lax, SameSite=Strict, SameSite=None

## 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.

## 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

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.

## 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.

## Why it matters

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

## Common mistake

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

## Three principles

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

## Related terms

- [Cross-Site Request Forgery (CSRF)](https://learn.benibix.com/term/development/cross-site-request-forgery)
- [HttpOnly Cookie](https://learn.benibix.com/term/development/httponly-cookie)
- [Session Hijacking](https://learn.benibix.com/term/development/session-hijacking)
- [HTTP Cookie](https://learn.benibix.com/term/development/cookie)
- [Same-Origin Policy (SOP)](https://learn.benibix.com/term/development/same-origin-policy)

## Told apart from

- [HttpOnly vs SameSite](https://learn.benibix.com/compare/httponly-vs-samesite): People think HttpOnly stops forged requests, and it does not. HttpOnly hides a cookie from scripts on the page, so an XSS script cannot steal the login. The browser still sends the cookie everywhere it goes. SameSite decides where the cookie goes. It keeps the cookie off requests that start on other sites, which is what stops CSRF. A login cookie wants both.

![A browser with two tabs. In tab one, the user is logged in to bank.example and holds its cookie. In tab two, a page on bad.example sends a hidden form to bank.example, and the browser adds the bank cookie. Two lit-up guards below stop it: a secret value in the form, and a cookie marked SameSite=Lax that is left off the cross-site form.](https://learn.benibix.com/diagrams/dev-csrf.svg)

---

Source: https://learn.benibix.com/term/development/samesite-cookie
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
