diff --git a/docs/incoming/filters.md b/docs/incoming/filters.md index e366f9831cce..39094e1e1f80 100644 --- a/docs/incoming/filters.md +++ b/docs/incoming/filters.md @@ -312,6 +312,8 @@ class Filters extends BaseConfig You can apply filters to all requests of a certain HTTP method, like `POST`, `GET`, `PUT`, etc. Its value would be an array of filters to run: +When a POST request uses [method spoofing](methodspoofing.md), `$methods` uses the spoofed method. For example, a POST form with `_method=PUT` runs the filters configured for `PUT`, not those configured for `POST`. + ```php > */ public array $methods = [ - 'POST' => ['invalidchars', 'csrf'], - 'GET' => ['csrf'], + 'GET' => ['csrf'], + 'POST' => ['invalidchars', 'csrf'], + 'PUT' => ['invalidchars', 'csrf'], + 'PATCH' => ['invalidchars', 'csrf'], + 'DELETE' => ['invalidchars', 'csrf'], ]; // ... diff --git a/docs/incoming/methodspoofing.md b/docs/incoming/methodspoofing.md index 87b927397d36..25402891d94d 100644 --- a/docs/incoming/methodspoofing.md +++ b/docs/incoming/methodspoofing.md @@ -10,7 +10,7 @@ To spoof the method, a hidden input is added to the form with the name of `_meth ``` -This form is converted into a PUT request and is a true PUT request as far as the routing and the IncomingRequest class are concerned. +This form is converted into a PUT request and is a true PUT request as far as routing, the IncomingRequest class, and [method-specific filters](filters.md#methods) are concerned. For example, a POST form with `_method=PUT` runs filters configured for `PUT`, not filters configured for `POST`. If you configure CSRF or other security filters by method, include every method you need to protect. The form that you are using must be a POST request. GET requests cannot be spoofed. diff --git a/docs/libraries/security.md b/docs/libraries/security.md index 218219bc246f..59881996483d 100644 --- a/docs/libraries/security.md +++ b/docs/libraries/security.md @@ -253,7 +253,7 @@ class Filters extends BaseConfig } ``` -It is also possible to enable the CSRF filter only for specific methods: +It is also possible to enable the CSRF filter only for specific methods. Include every method that needs CSRF protection, including methods reached through [method spoofing](../incoming/methodspoofing.md): ```php > */ public array $methods = [ - 'GET' => ['csrf'], - 'POST' => ['csrf'], + 'GET' => ['csrf'], + 'POST' => ['csrf'], + 'PUT' => ['csrf'], + 'PATCH' => ['csrf'], + 'DELETE' => ['csrf'], ]; // ... } ``` +The `GET` entry lets `form_open()` add a CSRF field to forms displayed on GET pages. The built-in CSRF filter verifies only POST, PUT, PATCH, and DELETE requests. + !!! warning "Warning" If you use `$methods` filters, you should [disable Auto Routing (Legacy)](../incoming/routing.md#use-defined-routes-only) because [Auto Routing (Legacy)](../incoming/routing.md#auto-routing-legacy) permits any HTTP method to access a controller. Accessing the controller with a method you don't expect could bypass the filter.