Make it harder to have routes vulnerable to CSRF

Created on 20 February 2025, 16 days ago

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

  1. Create a GET route that deletes an entity or changes a config value without a confirmation form.
  2. Don't add the _csrf_token requirement.
  3. 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 ( 📌 CSRF tokens in GET requests can be leaked and reused; stop encouraging server-site state changes with GET requests Active ) but I don't think this would be easy to do.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Feature request
Status

Active

Version

11.1 🔥

Component

routing system

Created by

🇫🇷France prudloff Lille

Live updates comments and jobs are added and updated live.
  • Security improvements

    It makes Drupal less vulnerable to abuse or misuse. Note, this is the preferred tag, though the Security tag has a large body of issues tagged to it. Do NOT publicly disclose security vulnerabilities; contact the security team instead. Anyone (whether security team or not) can apply this tag to security improvements that do not directly present a vulnerability e.g. hardening an API to add filtering to reduce a common mistake in contributed modules.

Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024