CakePHP4 - How to Fix Error: CSRF token from either the request body or request headers did not match or is missing.

Here's the most common way to fix CSRF issues in CakePHP4 (when you know your CSRF is installed/setup properly).

In my case, I was developing locally, but when testing remotely, I would get the following error:
CSRF token from either the request body or request headers did not match or is missing.

Here are the steps I took to delete the site cookies in Chrome, which fixed the problem:

  • Go into your Chrome Settings (top right three vertical dots)
  • In Settings, go to "Privacy and Security" on the left
  • Go to "Cookies and other site data"
  • Click "See all site data and permissions"
  • Using the Search box in the top right, find the relevant site
  • Click that site and hit the "Clear Data" button

That should resolve the cookie issue with CSRF errors.

Share this Post