Skip to content

A session cookie without its protective flags

cookie-flags-insecuremoderate
On this page

Why it matters

  • A session cookie is the key to a visitor's session: their cart, their account. RFC 6265bis gives two attributes to guard it. HttpOnly “limits the scope of the cookie to HTTP requests”, so page scripts cannot read it. Secure limits it to secure channels, so it does not travel over plain HTTP.
  • Without HttpOnly, one injected script, from a compromised plugin or a third-party tag, can read the session and use it elsewhere.
  • Without Secure, a visitor who opens an http:// link (on a network that watches) sends the session in clear.
  • SameSite=None without Secure is refused outright by current browsers: the cookie is not stored, and whatever needs it (an embedded checkout, a login across sites) fails.

How to fix

Set the flags where the session cookie is made:

http
Set-Cookie: PHPSESSID=…; Path=/; Secure; HttpOnly; SameSite=Lax
  • PHP: session.cookie_httponly = 1 and session.cookie_secure = 1 in php.ini, or session_set_cookie_params.
  • Laravel: 'http_only' => true and 'secure' => true in config/session.php. Express: cookie: { httpOnly: true, secure: true }.
  • Leave the CSRF token cookie (XSRF-TOKEN) readable: the page's own script must send it back. This check does not ask for HttpOnly there.

How we detect

  1. We read every Set-Cookie header of the page's own response. Cookies set by scripts, or by other requests of the page, are not read.
  2. A cookie is a session cookie by its name: the common platforms' (PHPSESSID, JSESSIONID, ASP.NET_SessionId, connect.sid, laravel_session, sessionid, ci_session and others), or a name built on sess, session or session_id. CSRF tokens are left out.
  3. A session cookie without HttpOnly is reported; on an HTTPS page, one without Secure too. Any cookie with SameSite=None and no Secure is reported.

A cookie's value is never shown in the report. Preference and analytics cookies are not judged.