What is the SameSite cookie attribute, and how does it help mitigate CSRF?

The SameSite cookie attribute allows developers to declare if their cookies should be restricted to a first-party or same-site context. This attribute can take three values: Strict, Lax, and None.

Strict : Cookies are only sent in a first-party context, providing the highest level of security against CSRF attacks but may affect user experience.
Lax : Cookies are sent with top-level navigations and GET requests initiated by third-party websites, balancing security and usability.
None : Cookies are sent with both first-party and cross-site requests, but the Secure attribute must also be set, meaning the cookie will only be sent over HTTPS connections.

By using the SameSite attribute, developers can reduce the risk of CSRF attacks by ensuring cookies are not sent with cross-site requests.