How to Fix Cookies Missing the HttpOnly Flag on Your Site
This check fails when your server sends a cookie in a Set-Cookie response header without the HttpOnly attribute, which means any JavaScript on the page can read it through document.cookie. By the end of this guide you will have listed every cookie your site sets, added HttpOnly to the ones scripts don't need, and confirmed the headers are fixed.

Why it matters
Session and login cookies are the keys to a user's account. If one lacks HttpOnly, a single cross-site scripting bug, compromised plugin or malicious third-party script can copy it with one line of JavaScript and send it to an attacker, who can then hijack the session without a password. HttpOnly doesn't stop XSS, but it removes the most valuable thing XSS usually steals.
It has no effect on rankings or page speed, and it is a standard item in penetration tests, PCI DSS reviews and security questionnaires from larger clients.
What you need
Step-by-step fix
List every cookie your server sets
The audit reads the Set-Cookie headers in your page's HTTP response, so start there. Run curl against your homepage and any login or cart pages, and note each cookie that does not include HttpOnly. In DevTools you can also open Application > Storage > Cookies > https://example.com and look at the HttpOnly column; anything without a tick is a candidate.
curl -sI https://example.com/ | grep -i '^set-cookie' curl -sI https://example.com/login | grep -i '^set-cookie'
Decide which cookies scripts genuinely need
For each flagged cookie, find out what sets it (cookie name, plugin, app or framework) and whether your front-end JavaScript reads it. Session IDs, auth tokens, remember-me cookies and cart IDs should always be HttpOnly. A small number of cookies are designed to be read by JS:
- CSRF tokens using the double-submit pattern (e.g.
XSRF-TOKEN) - Consent-banner preference cookies
- UI preferences such as theme or language
Search your codebase for document.cookie and the cookie name before changing these.
grep -rn "document.cookie" ./src ./public ./wp-content/themes
Add HttpOnly where the cookie is created
The cleanest fix is in the code that issues the cookie. cookie(); in plain PHP pass 'httponly' => true to setcookie(). Add Secure and SameSite=Lax` at the same time since you are already editing the line.
Raw header format is shown for any other stack.
// Raw header
Set-Cookie: sessionid=abc123; Path=/; Secure; HttpOnly; SameSite=Lax
// Express
res.cookie('sessionid', value, { secure: true, httpOnly: true, sameSite: 'lax', path: '/' });
// express-session
app.use(session({ secret: process.env.SESSION_SECRET, cookie: { httpOnly: true, secure: true, sameSite: 'lax' } }));Fix PHP sessions and setcookie() calls
cookie_httponly is on. php** above the line /* That's all, stop editing! */`.
3+).
<?php
// wp-config.php or a bootstrap file, before session_start()
@ini_set('session.cookie_secure', 1);
@ini_set('session.cookie_httponly', 1);
@ini_set('session.cookie_samesite', 'Lax');
// Direct cookies
setcookie('example_cart', $cartId, [
'expires' => time() + 86400 * 30,
'path' => '/',
'secure' => true,
'httponly' => true,
'samesite' => 'Lax',
]);Add a server-level fallback for cookies you can't edit
If a cookie comes from a closed-source plugin or upstream app, rewrite it at the web server. Nginx 1.19.3+ supports proxy_cookie_flags for proxied apps; Apache can append the flag with mod_headers. Exclude any cookie you identified in step 2 as needing JS access.
# Nginx (inside the location that proxies to your app) proxy_cookie_flags ~ httponly secure samesite=lax; # Exclude a JS-readable cookie by flagging only named ones instead: # proxy_cookie_flags sessionid httponly secure samesite=lax; # Apache (.htaccess or vhost, requires mod_headers) Header always edit Set-Cookie "^((?!.*;\s*HttpOnly).*)$" "$1; HttpOnly"
Purge caches and re-check the headers
Clear your page cache plugin, CDN and any reverse-proxy cache so the old headers aren't served. Then rerun the curl commands from step 1 in a fresh session (no existing cookies) and confirm every session or auth cookie now shows HttpOnly. Log in and out, add to cart and submit a form to confirm nothing broke, then re-run the audit.
curl -sI -H 'Cache-Control: no-cache' https://example.com/ | grep -i '^set-cookie'
Platform-specific notes
WordPress
Core login cookies (wordpress_logged_in_*, wordpress_sec_*) are already HttpOnly. Flags almost always come from plugins that call session_start() or setcookie() (forms, membership, WooCommerce add-ons). Add the ini_set lines to wp-config.php, update the plugin, and if a plugin still sets an unflagged cookie, report it to the developer and use the Apache/Nginx rule as a stopgap. Managed hosts like WP Engine or Kinsta may require a support ticket for server-level header rules.
Shopify
You cannot change the headers on Shopify's own cookies such as _shopify_y or cart; Shopify controls them. If a flagged cookie comes from a third-party app or an app proxy (served via /apps/...), the fix belongs in that app's backend using the Express or raw header example. Contact the app developer if you don't own it.
Next.js
In the App Router, set cookies in a Route Handler or Server Action with (await cookies()).set('sessionid', value, { httpOnly: true, secure: true, sameSite: 'lax', path: '/' }) — cookies() is async from Next.js 15. In middleware use response.cookies.set() with the same options. Auth libraries such as Auth.js set HttpOnly by default; check for custom cookie overrides in your auth config.
Nginx
proxy_cookie_flags only works for responses proxied with proxy_pass and requires Nginx 1.19.3 or newer (check with nginx -v). For PHP-FPM sites served via fastcgi_pass, fix it in PHP instead. Reload with sudo nginx -t && sudo systemctl reload nginx.
Cloudflare
Transform Rules can't reliably edit existing Set-Cookie values, so fix cookies at the origin. If that's impossible, a Cloudflare Worker can rewrite Set-Cookie headers on the response. Cloudflare's own __cf_bm cookie is already HttpOnly.
Check that it worked
✅ How to verify
- Run curl -sI https://example.com/ | grep -i set-cookie and confirm each session/auth cookie line contains HttpOnly.
- In DevTools, open Application > Cookies for example.com in a private window and check the HttpOnly column is ticked.
- In the browser console run document.cookie and confirm the session cookie name no longer appears.
- Re-run the audit and confirm the 'Cookies use HttpOnly' check passes.
⚠️ Common mistakes
- Adding HttpOnly to a CSRF or consent cookie that front-end JavaScript reads, which silently breaks form submissions or the cookie banner.
- Fixing the cookie in code but leaving a CDN or page cache serving the old Set-Cookie header.
- Only checking the homepage when the unflagged cookie is set on the login, cart or redirect response.
- Trying to set HttpOnly from JavaScript via document.cookie — browsers ignore it; the flag can only be set in a server response header.
Is this still an issue on your site? Run a free audit — ZORO checks this and 294 other SEO, AI-visibility, accessibility and security signals, with fixes for your platform.
Check my site freeFAQ
What does the HttpOnly cookie flag do?
It tells the browser not to expose the cookie to JavaScript, so document.cookie and similar APIs can't read it. The browser still sends the cookie with HTTP requests to your server as normal, so logins and carts keep working.
Should every cookie be HttpOnly?
Every cookie that only the server needs should be, especially session, authentication and cart cookies. Cookies your own scripts must read, like double-submit CSRF tokens or consent preferences, can stay without it, but they should never hold anything that grants access to an account.
Does HttpOnly protect against XSS?
Not fully. It stops an injected script from stealing the cookie value, but the script can still make requests as the logged-in user while the page is open. Treat HttpOnly as one layer alongside a Content Security Policy, output escaping and keeping plugins updated.
Can I set HttpOnly on Google Analytics or other third-party cookies?
No. Cookies like _ga are created by JavaScript in the browser, and the HttpOnly flag can only be set by a server's Set-Cookie header. These analytics cookies are also designed to be read by script, so adding HttpOnly would break them.
How to Fix Cookies Missing the SameSite Attribute
How to Fix Cookies Missing the Secure Flag on HTTPS
How to Fix Missing Clickjacking Protection (frame-ancestors)
How to Fix a Low TLS Security Grade (Protocols, HSTS, Certs)
How to Fix a Missing Permissions-Policy Header on Your Site
How to Enable TLS 1.3 on Your Web Server, CDN or Host