The FBI says over 1,000 hacked WordPress sites hid ransomware lures in Google. You can open yours and see a normal page.

Details

Security tests

Secure cookies

Enable secure session cookie flags in WordPress with Security Ninja Pro or a wp-config.php snippet.

Last updated ( published )

Secure cookie flags help keep session cookies on HTTPS and less reachable from JavaScript. That reduces some XSS and cookie-theft paths. Your site must already work over HTTPS.

Secure Cookies enable or disable

One-click fix (Pro)

  1. Go to Security Ninja → Fixes.
  2. Enable Secure Cookies.
  3. Security Ninja writes the matching @ini_set lines into wp-config.php.

Manual setup

Add these lines to wp-config.php above the “That’s all, stop editing!” line:

@ini_set( 'session.cookie_httponly', true );
@ini_set( 'session.cookie_secure', true );
@ini_set( 'session.use_only_cookies', true );

What the three lines do

  • session.cookie_httponly: the session cookie can’t be read by JavaScript, so a malicious script injected into a page can’t steal it.
  • session.cookie_secure: the browser only sends the session cookie over HTTPS, never over plain HTTP.
  • session.use_only_cookies: PHP won’t accept a session ID in the URL (for example ?PHPSESSID=...), which stops session IDs leaking through links and logs.

These settings apply to PHP sessions. WordPress itself doesn’t always use PHP sessions; they’re mainly started by some plugins and themes (shops, forms, membership plugins). The fix makes sure those session cookies are protected if and when one is created.

How to check it works

  1. Confirm the fix shows as enabled under Security Ninja → Fixes (Pro), or that the three lines are in wp-config.php above “That’s all, stop editing!”.
  2. Open your site over https:// (check the padlock in the address bar).
  3. Clear cookies for your site, then log in to WordPress again.
  4. Open developer tools: right-click the page and choose Inspect, or press F12 (Mac: Cmd+Option+I).
  5. Chrome/Edge: open the Application tab, then Storage > Cookies in the left sidebar, then click your site’s address. Firefox: Storage tab, then Cookies. Safari: enable the Develop menu first (Settings > Advanced), then Develop > Show Web Inspector > Storage > Cookies.
  6. Look at the HttpOnly and Secure columns. A tick (✓) means the flag is set.
  7. What you should see:
    • PHPSESSID (if present): ticks in both HttpOnly and Secure. This is the cookie the fix controls.
    • wordpress_sec_* and wordpress_logged_in_*: WordPress sets these when you log in. On an HTTPS site they should also show HttpOnly and Secure. They’re a good sanity check that your login cookies are protected, but they’re controlled by WordPress core, not by these three lines.

No PHPSESSID in the list? That’s normal. It only appears when a plugin or theme starts a PHP session. Nothing is broken, and the fix will apply as soon as one is created.

Not working? Check these

  • Still seeing HTTP: the site must load over HTTPS everywhere. Check Settings > General (WordPress Address and Site Address both start with https://) and that HTTP redirects to HTTPS. With session.cookie_secure on, sessions won’t work over plain HTTP.
  • Caching: clear the site cache, any host or CDN cache (for example Cloudflare), and browser cookies, then log in again.
  • Lines missing: if wp-config.php isn’t writable, the one-click fix can’t add the lines. Add them manually as shown above, or ask your host.
  • Host overrides: some hosts block ini_set or set session options in their own PHP config. If PHPSESSID exists but lacks the flags, ask your host to set session.cookie_httponly = 1, session.cookie_secure = 1 and session.use_only_cookies = 1 in PHP settings (php.ini / .user.ini).
  • Still stuck: email [email protected] with a screenshot of the cookie list.

Related: Fixes overview.

Still stuck? Get help or contact us.

Larger screenshot

Enlarged image