Guides · Security headers

Cookie flags: Secure, SameSite and HttpOnly

One of the checks in every audibot report. This page says exactly what audibot reads, what passes, and how to fix it.

What audibot checks

Every Set-Cookie header on the home page response. A cookie counts as weak if it lacks Secure or lacks SameSite. If the home page sets no cookies, this check does not appear.

Why it matters

Secure stops the browser from sending the cookie over plain HTTP, where it can be read in transit. SameSite stops it from being attached to requests other sites trigger, which is how cross-site request forgery works. HttpOnly keeps it out of reach of page scripts, so an XSS bug cannot read a session.

How do I set the Secure and SameSite flags on cookies?

Set Secure and SameSite=Lax (or Strict) on every cookie, and HttpOnly on any the page's own JavaScript does not need to read. Fix it where the cookie is created; the proxy rule below is a fallback.

The header

Set-Cookie: session=…; Path=/; Secure; HttpOnly; SameSite=Lax

Express

res.cookie('session', value, { secure: true, httpOnly: true, sameSite: 'lax' })

PHP (php.ini)

session.cookie_secure = 1
session.cookie_httponly = 1
session.cookie_samesite = "Lax"

nginx 1.19.3+ (cookies from an upstream)

proxy_cookie_flags ~ secure samesite=lax;

Related tools

Other checks in Security headers

Security headers in the methodology ·All guides

This check is one step of the website launch checklist.

Check your site

audibot runs this check and every other one in a single audit, and publishes the report with a recommendation for each finding.