Skip to content

Commit 3a073d5

Browse files
committed
Fixed comments
1 parent 7f4b3e8 commit 3a073d5

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

cookbook/security/csrf_in_login_form.rst

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
Using CSRF in the Login Form
55
============================
66

7-
When using a login form, you should make sure that you are protected for CSRF
8-
(`Cross-site request forgery`_). The Security component already has build-in support
9-
form CSRF. In this article, you'll learn how you can use it in your login form.
7+
When using a login form, you should make sure that you are protected against CSRF
8+
(`Cross-site request forgery`_). The Security component already has built-in support
9+
for CSRF. In this article you'll learn how you can use it in your login form.
1010

1111
Configuring CSRF
1212
----------------
1313

14-
At first, you have to configure the security component so it can use CSRF protection.
15-
The security component needs a CSRF provider. You can set this to use the default
16-
provider provided by the Form component:
14+
At first, you have to configure the Security component so it can use CSRF protection.
15+
The Security component needs a CSRF provider. You can set this to use the default
16+
provider available in the Form component:
1717

1818
.. configuration-block::
1919

@@ -70,8 +70,8 @@ Rendering the CSRF field
7070
Now the Security component checks for CSRF tokens, you have to add a *hidden* field
7171
to the login form containing the CSRF token. By default, this field is named as
7272
``_csrf_token``. That hidden field has to contain the CSRF token, which can be generated
73-
by using the ``csrf_token`` function. That function requires a token ID, which is
74-
must be set to ``authenticate`` when using the login form:
73+
by using the ``csrf_token`` function. That function requires a token ID, which must
74+
be set to ``authenticate`` when using the login form:
7575

7676
.. configuration-block::
7777

@@ -105,11 +105,60 @@ must be set to ``authenticate`` when using the login form:
105105
<button type="submit">login</button>
106106
</form>
107107

108-
After this, you have protected your login form for CSRF attacks.
108+
After this, you have protected your login form against CSRF attacks.
109109

110110
.. tip::
111111

112-
You can change the name of the field by setting ``csrf_parameter`` and the token
113-
ID by setting ``intention`` in your configuration.
112+
You can change the name of the field by setting ``csrf_parameter`` and change
113+
the token ID by setting ``intention`` in your configuration:
114+
115+
.. configuration-block::
116+
117+
.. code-block:: yaml
118+
119+
# app/config/security.yml
120+
security:
121+
firewalls:
122+
secured_area:
123+
# ...
124+
form_login:
125+
# ...
126+
csrf_parameter: _csrf_security_token
127+
intention: a_private_string
128+
129+
.. code-block:: xml
130+
131+
<!-- app/config/config.xml -->
132+
<?xml version="1.0" encoding="UTF-8" ?>
133+
<srv:container xmlns="http://symfony.com/schema/dic/security"
134+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
135+
xmlns:srv="http://symfony.com/schema/dic/services"
136+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
137+
138+
<config>
139+
<firewall name="secured_area">
140+
<!-- ... -->
141+
142+
<form-login csrf-parameter="_csrf_security_token"
143+
intention="a_private_string" />
144+
</firewall>
145+
</config>
146+
</srv:container>
147+
148+
.. code-block:: php
149+
150+
// app/config/security.php
151+
$container->loadFromExtension('security', array(
152+
'firewalls' => array(
153+
'secured_area' => array(
154+
// ...
155+
'form_login' => array(
156+
// ...
157+
'csrf_parameter' => '_csrf_security_token',
158+
'intention' => 'a_private_string',
159+
)
160+
)
161+
)
162+
));
114163
115164
.. _`Cross-site request forgery`: http://en.wikipedia.org/wiki/Cross-site_request_forgery

0 commit comments

Comments
 (0)