@@ -117,6 +117,17 @@ CSRF Protection in Symfony Forms
117117checks them automatically for you. So, when using Symfony Forms, you don't have
118118to do anything to be protected against CSRF attacks.
119119
120+ .. note ::
121+
122+ According to `OWASP best practices `_, CSRF protection is only required for
123+ **state-changing operations **, which must not use ``GET `` requests (as per the
124+ HTTP specification). Moreover, including CSRF tokens in ``GET `` request
125+ parameters can cause them to leak through browser history, log files, network
126+ utilities, and Referer headers.
127+
128+ If one of your forms uses GET (for example, a read-only search form), you
129+ can :ref: `configure the form to disable CSRF protection <form-csrf-configuration >`.
130+
120131.. _form-csrf-customization :
121132
122133By default Symfony adds the CSRF token in a hidden field called ``_token ``, but
@@ -166,6 +177,8 @@ Globally, you can configure it under the ``framework.form`` option:
166177 ;
167178 };
168179
180+ .. _form-csrf-configuration :
181+
169182On a form-by-form basis, you can configure the CSRF protection in the ``setDefaults() ``
170183method of each form::
171184
@@ -504,6 +517,7 @@ validation has been proven effective, it remains enforced for that session.
504517 fall back to ``Origin `` / ``Referer `` checks when JavaScript is unavailable.
505518
506519.. _`Cross-site request forgery` : https://en.wikipedia.org/wiki/Cross-site_request_forgery
520+ .. _`OWASP best practices` : https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Request_Forgery_Prevention_Cheat_Sheet.html
507521.. _`BREACH` : https://en.wikipedia.org/wiki/BREACH
508522.. _`CRIME` : https://en.wikipedia.org/wiki/CRIME
509523.. _`some JavaScript` : https://github.com/symfony/recipes/blob/main/symfony/stimulus-bundle/2.20/assets/controllers/csrf_protection_controller.js
0 commit comments