Why cookie flags matter
Session cookies are the keys to your users' accounts. If an attacker steals one, they can often log in as that user without a password — see session hijacking. Three cookie flags make that much harder, and missing flags are one of the most common findings in website scans.
Secure
The Secure flag tells the browser to send the cookie only over HTTPS. Without it, the cookie can travel over plain HTTP — for example if a user types your address without https:// — and be intercepted on public Wi-Fi.
Set it on: every cookie, on any site that uses HTTPS. Pair it with HSTS so browsers never try HTTP at all.
HttpOnly
HttpOnly stops JavaScript from reading the cookie. If an attacker manages to inject a script through cross-site scripting, they cannot simply read document.cookie and steal the session.
Set it on: session and authentication cookies. Leave it off only for cookies your front-end code genuinely needs to read, and never put secrets in those.
SameSite
SameSite controls whether the cookie is sent with requests that start on other websites. It is a strong defence against cross-site request forgery.
Strict— never sent on cross-site requests. Most secure; can log users out when they follow links from email.Lax— sent on top-level navigation (clicking a link) but not on cross-site form posts or embedded requests. A good default for session cookies.None— always sent; must be combined withSecure. Only for genuine cross-site use such as embedded widgets.
Other useful attributes
PathandDomain— keep cookies as narrowly scoped as possible. Avoid settingDomainto the parent domain unless every subdomain is trusted.Max-Age/Expires— keep session lifetimes reasonable.- The
__Host-prefix forcesSecure, noDomain, andPath=/, preventing subdomains from overwriting the cookie.
How to check your cookies
Open developer tools → Application → Cookies, and check the Secure, HttpOnly and SameSite columns for each session cookie. A free scan checks this for you.
How to fix them
Most frameworks set cookie flags in session configuration — for example SESSION_SECURE_COOKIE in Laravel, cookie.secure in Express session middleware, or settings in your platform's admin. Our Laravel checklist and Next.js guide include specifics.
Yrzo AI reports which cookies are missing flags and exactly how to set them — see plans.
Related reading: HSTS Explained: Strict-Transport-Security and the Preload List · Account Takeover Prevention: Protecting Customer and Staff Accounts · Laravel Security Checklist for Production Apps