What the message looks like
CSRF check failedCommon causes
- Session cookie not stored, e.g. a Secure cookie over HTTP behind a TLS proxy.
- Reverse proxy without matching
overwriteprotocolandtrusted_proxies. - PHP cannot write sessions (permissions on
session.save_path, full disk). - Redis as session store unreachable or full.
- Login page left open too long so the session expired, or access via two different hostnames.
Check
- Check whether and how the session cookie is set
curl -sI https://cloud.example.com/login | grep -i '^set-cookie' - Show the Nextcloud proxy settings
sudo -u www-data php /var/www/nextcloud/occ config:system:get overwriteprotocol; sudo -u www-data php /var/www/nextcloud/occ config:system:get trusted_proxies - Show PHP session storage
php -i | grep -E 'session.save_(handler|path)' - Show cache and Redis configuration
sudo -u www-data php /var/www/nextcloud/occ config:system:get memcache.distributed; sudo -u www-data php /var/www/nextcloud/occ config:system:get redis
Fix
- Behind a TLS proxy set
'overwriteprotocol' => 'https'and add the proxy IP totrusted_proxies. - Always use the same hostname and set
overwrite.cli.urlto match. - Make the session directory writable or check Redis:
redis-cli ping. - Clear browser cookies for the domain and reload the login page.
- Check disk space – without free space session files fail silently.
Typical scenario
A user leaves the Nextcloud login open in the morning, goes to a meeting and submits it in the afternoon. Instead of the file view she sees 'CSRF check failed'. A second case occurs when Nextcloud runs behind a load balancer with two backends that do not share sessions. First check whether the error also occurs after freshly loading the login page. If so, it is not an expired page but the session storage or the proxy.
FAQ
Is “CSRF check failed” an attack?
In practice almost never. It means the token from the form does not match the current session – usually a lost or new session.
Why does it only hit some users?
Often browser extensions, blocked cookies or a bookmark to a different hostname are to blame. A private window narrows it down quickly.
Is the message a sign of an attack?
Almost never. CSRF protection requires the form token to match the session. If the session or the page is lost between loading and submitting, the check fails. So the message mostly points to a timeout or an infrastructure issue, not to an attacker.
Why does it only happen with several backend servers?
If each server keeps its sessions locally on its filesystem, the submit request may land on a server that does not know the session. The fix is sticky sessions at the load balancer or a shared session store such as Redis.
Why does the error show up after a PHP update?
If the session directory was recreated or belongs to a different user, PHP can no longer write sessions. Then no matching token ever exists. session.save_path and its permissions are the first thing to check.