Skip to content

Cookie settings

HttpOnly attribute

The HttpOnly attribute hides a cookie from page scripts, so an injected script can't steal a visitor's session.

Scanetra rating: LowCheck CKE-02

Why it matters

If an attacker gets a script into your page, the first thing it usually does is read the session cookie and send it away. HttpOnly stops that, even when other defences fail.

What Scanetra looks for

  • Session cookies (by a framework's default name) set without HttpOnly.
  • Other cookies without HttpOnly whose purpose isn't clear (a note). CSRF cookies are left out because scripts need them.

It reads only your homepage's public response. How a scan works

How to fix it

The header

What a well-set session cookie looks like:

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

PHP

In php.ini, for PHP's own session cookie:

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

Express

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

Django

In settings.py:

SESSION_COOKIE_SECURE = True
SESSION_COOKIE_HTTPONLY = True
SESSION_COOKIE_SAMESITE = "Lax"
CSRF_COOKIE_SECURE = True

nginx (in front of an app)

When you can't change the app, nginx 1.19.3 or later can add the flags to cookies it passes on:

proxy_cookie_flags ~ secure httponly samesite=lax;

Replace example.com with your own domain, and test changes on a staging copy first where you can.

Check that it worked

The Set-Cookie header for each session cookie includes HttpOnly. Then scan again.

Check your own site

A free scan tells you whether your site passes this check, and the 24 others.

Scan a website