Set secure session cookies
For administrators of HTTPS-only sites. By default the session cookie is Secure only when the request itself came
over HTTPS (CookieSecure=auto); true forces it, so the cookie is never sent over plain HTTP
(13.7 Sessions and cookies).
Contents
Before you start
- The site is served only over HTTPS; behind a proxy,
TrustedProxies[]lists it and it setsX-Forwarded-Proto. - Agree a session timeout with editors (shipped: 31104000 seconds, 360 days, for both
SessionTimeoutandRememberMeTimeout).
Steps
In
settings/override/site.ini.append.php:[Session] CookieSecure=true CookieHttponly=true CookieSameSite=Lax SessionTimeout=28800In PHP's configuration for the site,
session.use_strict_mode=1.php bin/php/ezcache.php --clear-tag=ini --allow-root-user; reload PHP-FPM or deploy on Velocity.
Check that it worked
curl -sI https://www.example.gov/user/login | grep -i set-cookieshows Secure; HttpOnly; SameSite=Lax on the session cookie. Sign in and work for a while: you stay signed in.
If something goes wrong
- Signed out on every page: the kernel thinks requests are plain HTTP (proxy not trusted, or no
X-Forwarded-Proto); fix the proxy settings (Proxies and trusted headers). SameSite=Strictdrops the session on the first click from an e-mail; keepLaxunless you know you needStrict.
Related pages
- Sessions and cookies
- Separate session cookies for the administration
- Add HSTS
- Free documentation: this page is free to copy, translate and improve under the GNU FDL 1.3.
Become an Exponential Partner
Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.