@@ -12,24 +12,57 @@ CSRF protection works by adding a hidden field to your form that contains a
12
12
value that only you and your user know. This ensures that the user - not some
13
13
other entity - is submitting the given data.
14
14
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):
17
17
18
18
.. code-block :: terminal
19
19
20
20
$ composer require security-csrf form
21
21
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
+
22
59
CSRF Protection in Symfony Forms
23
60
--------------------------------
24
61
25
62
Forms created with the Symfony Form component include CSRF tokens by default
26
63
and Symfony checks them automatically, so you don't have to anything to be
27
64
protected against CSRF attacks.
28
65
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
-
33
66
.. _form-csrf-customization :
34
67
35
68
By default Symfony adds the CSRF token in a hidden field called ``_token ``, but
0 commit comments