The Three Pillars of Cookie Security
HTTP cookies store sensitive session and authentication tokens. Protecting these tokens requires three critical attributes: Secure ensures cookies are only transmitted over encrypted HTTPS; HttpOnly blocks access from client-side JavaScript (document.cookie); and SameSite controls cross-origin transmission to prevent CSRF.
SameSite Attribute Differences
SameSite=Strict prevents cookie transmission on all cross-site requests, including top-level link navigations. SameSite=Lax (the modern browser default) allows cookies on top-level safe GET navigations while blocking them on cross-site POST requests. SameSite=None permits cross-site transmission, but strictly requires the Secure flag.
Cookie Scoping Best Practices
Always restrict cookies to specific Path and Domain scopes. Omitting the Domain attribute defaults to host-only scoping, which prevents broader subdomain inheritance.
