Skip to content

Commit 58460c5

Browse files
committed
minor #9175 Reworded the CSRF article to better explain how to install and enable/disable it (javiereguiluz)
This PR was squashed before being merged into the 4.0 branch (closes #9175). Discussion ---------- Reworded the CSRF article to better explain how to install and enable/disable it This finishes #8955. Commits ------- 3695b0d Reworded the CSRF article to better explain how to install and enable/disable it
2 parents dfa477e + 3695b0d commit 58460c5

File tree

1 file changed

+39
-6
lines changed

1 file changed

+39
-6
lines changed

security/csrf.rst

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,57 @@ CSRF protection works by adding a hidden field to your form that contains a
1212
value that only you and your user know. This ensures that the user - not some
1313
other entity - is submitting the given data.
1414

15-
Before enabling the CSRF protection, install the CSRF support in your project
16-
(which in turn requires installing the Symfony Form component):
15+
Before using the CSRF protection, install it in your project (which in turn
16+
requires installing the Symfony Form component):
1717

1818
.. code-block:: terminal
1919
2020
$ composer require security-csrf form
2121
22+
Then, enable/disable the CSRF protection with the ``csrf_protection`` option.
23+
(see the :ref:`CSRF configuration reference <reference-framework-csrf-protection>`
24+
for more information):
25+
26+
.. configuration-block::
27+
28+
.. code-block:: yaml
29+
30+
# config/packages/framework.yaml
31+
framework:
32+
# ...
33+
csrf_protection: ~
34+
35+
.. code-block:: xml
36+
37+
<!-- config/packages/framework.xml -->
38+
<?xml version="1.0" encoding="UTF-8" ?>
39+
<container xmlns="http://symfony.com/schema/dic/services"
40+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
41+
xmlns:framework="http://symfony.com/schema/dic/symfony"
42+
xsi:schemaLocation="http://symfony.com/schema/dic/services
43+
http://symfony.com/schema/dic/services/services-1.0.xsd
44+
http://symfony.com/schema/dic/symfony
45+
http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
46+
47+
<framework:config>
48+
<framework:csrf-protection enabled="true" />
49+
</framework:config>
50+
</container>
51+
52+
.. code-block:: php
53+
54+
// config/packages/framework.php
55+
$container->loadFromExtension('framework', array(
56+
'csrf_protection' => null,
57+
));
58+
2259
CSRF Protection in Symfony Forms
2360
--------------------------------
2461

2562
Forms created with the Symfony Form component include CSRF tokens by default
2663
and Symfony checks them automatically, so you don't have to anything to be
2764
protected against CSRF attacks.
2865

29-
This automatic protection is enabled/disabled with the ``csrf_protection`` option
30-
in the ``config/packages/framework.yaml`` file. For more information, see the
31-
:ref:`CSRF configuration reference <reference-framework-csrf-protection>`.
32-
3366
.. _form-csrf-customization:
3467

3568
By default Symfony adds the CSRF token in a hidden field called ``_token``, but

0 commit comments

Comments
 (0)