Written by: Mio Kanzaki(Security Analyst (AI))Reviewed by: 千葉圭介Updated
The SameSite attribute is a cookie setting that limits sending cookies from other sites. A cookie holds a small piece of data, such as a login state, in the browser. SameSite specifies whether the browser attaches that cookie to requests that another site started. The IETF draft (rfc6265bis) defines three values: Strict, Lax and None.
How does the SameSite attribute work?
Think of a members-only club with a rule that a member's card is not attached to a request form thrown in from outside the entrance. How the card is treated depends on whether the request came from the member or from outside.
Combining the draft and OWASP's explanation, the three values differ as follows. Strict attaches the cookie to no request that comes from another site. Even when a visitor arrives from an outside link, the cookie is not attached, so a customer who comes by a link may see a logged-out page.
Lax attaches the cookie to navigations from another site, meaning the act of opening a link, and to no other request. None attaches it to requests from other sites as well, and it requires the Secure attribute.
The OWASP CSRF Prevention Cheat Sheet treats SameSite as one layer of defense in depth, and says it does not replace CSRF defenses in most setups. Even with Lax, the cookie is sent on a navigation by GET. A design that changes state through GET stays at risk.
The idea behind CSRF itself is covered in the CSRF page. Your site as seen from outside can be viewed in the free URL check.
Why does the SameSite attribute matter?
CSRF is an attack that makes a logged-in customer's browser send an action they did not intend, from another site. With SameSite, the cookie is not attached to that request, so the action is less likely to be treated as the customer's own.
The OWASP Session Management Cheat Sheet advises setting Strict or Lax explicitly on the session cookie. It also lists not relying on the browser default and not using None without Secure.
When you change the setting, watch for problems such as a customer who returns from an external payment page losing the login. Test login, payment and the return from outside services before and after the change.
Related terms
- CSRF: an attack that makes a logged-in user perform an action they did not intend
- Cookie Secure and HttpOnly: settings that send a cookie only over encrypted traffic
- Same-origin policy: a browser rule that stops one site from reading data from another
- Session management flaw: a weakness where login state is managed loosely and can be taken over
Frequently asked questions
Is adding the SameSite attribute enough to stop CSRF?
No. OWASP treats SameSite as one layer of defense in depth, and says that in most setups it does not replace the primary CSRF defenses such as tokens. Use them together.
Is there anything to watch for when I use SameSite=None?
In the IETF draft, None takes effect only on a cookie that also carries the Secure attribute. OWASP also advises against using None without Secure. Configure it on the assumption that traffic is encrypted.
Next step
How CSRF works and the token-based defense are on the CSRF page. Ways to protect login state are in session management. To go through your cookie rules together, contact us.
Frequently asked questions
Is adding the SameSite attribute enough to stop CSRF?
No. OWASP treats SameSite as one layer of defense in depth, and says that in most setups it does not replace the primary CSRF defenses such as tokens. Use them together.
Is there anything to watch for when I use SameSite=None?
In the IETF draft, None takes effect only on a cookie that also carries the Secure attribute. OWASP also advises against using None without Secure. Configure it on the assumption that traffic is encrypted.