Cookie Security Flags Explained: Secure, HttpOnly and SameSite

What the Secure, HttpOnly and SameSite cookie flags do, which cookies need them, and how to set them correctly on your website.

Yrzo AI28 November 2026 2 min read

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

Is your site exposed to this?

Run a free, non-intrusive check of what attackers can see from outside. No account needed.

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 with Secure. Only for genuine cross-site use such as embedded widgets.

Other useful attributes

  • Path and Domain — keep cookies as narrowly scoped as possible. Avoid setting Domain to the parent domain unless every subdomain is trusted.
  • Max-Age / Expires — keep session lifetimes reasonable.
  • The __Host- prefix forces Secure, no Domain, and Path=/, 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

cookie security flagsHttpOnly Secure SameSitesecure session cookiesSameSite cookie attribute
Share

Check your own website in 60 seconds

Free check, no account needed. Want the full picture? Full reports start at £149, with up to 110 checks with a 14-day money-back guarantee.

Keep reading