Problem/Motivation
The security advisories list contains many fixed CSRF vulnerabilities. It proves that it is easy to forget to add CSRF protection on GET routes that do sensitive actions.
It is easy to create a route and simply forget to add CSRF protection to it.
Steps to reproduce
- Create a GET route that deletes an entity or changes a config value without a confirmation form.
- Don't add the _csrf_token requirement.
- Your route is vulnerable to CSRF attacks.
Proposed resolution
Adding CSRF tokens to every GET route would not be a good idea, it is only needed on routes that modify config or entities.
But maybe we could make it required to specify explicitly on each route whether it needs CSRF token. (Similar for what we do for access checks on entity queries.)
This would force developers to think about it.
(Routes that return a form are already protected from CSRF attacks automatically and would not need this.)
An alternative approach would be to forbid sensitives actions in GET requests (#3384167: CSRF tokens in GET requests can be leaked and reused; stop encouraging server-site state changes with GET requests) but I don't think this would be easy to do.