CSRF Best Practices
Strict:
Use
SameSite=Strictfor cookies containing sensitive information or those used in critical operations (e.g., authentication cookies).Example:
httpCopy codeSet-Cookie: authToken=xyz789; Secure; HttpOnly; SameSite=Strict
Lax:
Use
SameSite=Laxfor cookies that should generally be sent in same-site contexts but still allow some cross-site requests (e.g., navigations from external links).Example:
httpCopy codeSet-Cookie: trackingId=def456; Secure; HttpOnly; SameSite=Lax
None:
Use
SameSite=Noneonly when cross-site requests are necessary and ensure theSecureattribute is present to enforce HTTPS.Example:
httpCopy codeSet-Cookie: thirdParty=ghi123; Secure; HttpOnly; SameSite=None
Last updated
Was this helpful?