CSRF and form tokens
This page is for administrators and developers. In a cross-site request forgery, another site makes a signed-in
editor's browser send a form: publish, delete, change a role. Exponential's ezformtoken extension adds a per-session
token to every HTML form and checks it on every POST; a forged form cannot know the token
(13.8 Form tokens against cross-site request forgery).
Contents
How it works
- The setup wizard activates
ezformtokenon every new installation. - Event listeners add the token to forms in the output and check it on input.
- Session cookies are
SameSite=Laxas defense in depth. - A page carrying a token is sent
Cache-Control: private, so no shared cache stores it. - Some views must accept browser POSTs without a token by design, such as
csp/reportfor Content Security Policy reports with their specific content types; the view only writes a log line.
Keep it active
Check that it is in [ExtensionSettings] ActiveExtensions[]:
php bin/php/console exp:ini where site.ini/ExtensionSettings/ActiveExtensions --allow-root-useror Setup > Extensions. If it is missing on a live site, every form is open to forgery; add it in the override and clear caches.
Custom code
- Custom AJAX code that sends POST requests must send the token too; the kernel's own scripts and ezjscore do. The
extension's
README.rstshows how. - A reverse proxy must not override
Cache-Control: privateon pages with a token. - Extensions that add their own forms get the token automatically when they render normal HTML forms through the templates.
When a token is refused
The answer is 403 with the "form expired" page; no token is written to the log (Form expired page). Common harmless causes: the session timed out while a form was open, or the user signed in again in another tab. Repeated refusals for many users after a change point to a proxy or caching problem.
Related pages
- 13.8 Form tokens
- Spam protection for forms
- Security standards: OWASP cheat sheets
- 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.