Skip to main content
MediumInfo disclosureOWASP A05:2021CWE-1004

How to fix: Rails Session Cookie Missing HttpOnly Flag

A Rails-style session cookie (matching the *_session naming pattern) was found in the Set-Cookie header without the HttpOnly flag. HttpOnly prevents client-side JavaScript from reading the cookie value, which blocks XSS-based session hijacking.

Why it matters

Without HttpOnly, any injected JavaScript on the page can read the session cookie via document.cookie and exfiltrate it to an attacker-controlled server. This enables full session hijacking even when the XSS vulnerability itself has limited reach.

Rails session cookies use a *_session suffix by default (e.g., myapp_session). When the HttpOnly flag is absent, client-side scripts have unrestricted access to the cookie. An attacker who achieves XSS on any page in the same origin can steal the session and impersonate the authenticated user.

How to fix it

  1. 1In Rails, enable HttpOnly on the session cookie via config.session_store :cookie_store, httponly: true in config/application.rb.
  2. 2In config/initializers/session_store.rb, verify :httponly => true is set.
  3. 3For non-Rails cookies, always include HttpOnly in the Set-Cookie header: Set-Cookie: name=value; HttpOnly; Secure; SameSite=Strict.
  4. 4Audit all cookies set by the application and ensure none are readable by JavaScript unnecessarily.

Code examples

Rails (config/initializers/session_store.rb)

Ruby
Rails.application.config.session_store :cookie_store,
  key: '_myapp_session',
  httponly: true,
  secure: Rails.env.production?,
  same_site: :strict

PHP (generic HttpOnly cookie)

PHP
// Set session cookie with HttpOnly and Secure flags
session_set_cookie_params([
  'lifetime' => 0,
  'path'     => '/',
  'domain'   => '',
  'secure'   => true,
  'httponly' => true,
  'samesite' => 'Strict',
]);
session_start();

Express.js (express-session)

JavaScript
app.use(session({
  name: 'sid',
  secret: process.env.SESSION_SECRET,
  cookie: {
    httpOnly: true,
    secure: true,
    sameSite: 'strict',
  },
  resave: false,
  saveUninitialized: false,
}));

References

Detected automatically by VulnRadar. The check id is rails-cookie-httponly, stable across every scan so you can filter or diff on it.

See every info disclosure check

Questions

How severe is Rails Session Cookie Missing HttpOnly Flag?
VulnRadar rates this medium severity in the info disclosure category. The severity is fixed per check, not scored per site, so the same finding is the same severity on every scan.
Does VulnRadar check for this automatically?
Yes. It runs as part of every scan under the check id rails-cookie-httponly, which stays the same between runs so you can filter, diff, or gate CI on it.
Which standards does Rails Session Cookie Missing HttpOnly Flag map to?
It maps to CWE-1004. In the OWASP Top 10 it falls under A05:2021.

Missing a check?

The detection set is open. If you know a misconfiguration this does not catch, propose it: the issue template asks for the threat model, how to detect it, the false-positive risk, and a test fixture, which is the same thing a maintainer would have to work out anyway.

Propose a checkHow a check is built

Scan your own site for rails session cookie missing httponly flag

VulnRadar runs this check and hundreds more against a URL in seconds. No agent to install, just paste a URL.

Or scan this site as a demoRead the docs

Rails Session Cookie Missing HttpOnly Flag fix | VulnRadar