Skip to content

Commit 55730c4

Browse files
committed
feature #5021 Explained the "Remember Me" firewall options (javiereguiluz)
This PR was merged into the 2.3 branch. Discussion ---------- Explained the "Remember Me" firewall options | Q | A | ------------- | --- | Doc fix? | no | New docs? | yes | Applies to | 2.3+ | Fixed tickets | #4193 This PR started just for adding a note about setting different cookie names for the "Remember Me" feature when using multiple firewalls ... but then I realized that the options of this important firewall weren't explained. Commits ------- 63890b1 Put the default value alongside the name of the option to improve readability aa91c37 Fixed a wrong explanation of the "httponly" option 7e45958 Added the (important) missing "key" option 91172bc Explained the "Remember Me" firewall options
2 parents 38e9cf1 + 63890b1 commit 55730c4

File tree

1 file changed

+51
-10
lines changed

1 file changed

+51
-10
lines changed

cookbook/security/remember_me.rst

Lines changed: 51 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ Once a user is authenticated, their credentials are typically stored in the
88
session. This means that when the session ends they will be logged out and
99
have to provide their login details again next time they wish to access the
1010
application. You can allow users to choose to stay logged in for longer than
11-
the session lasts using a cookie with the ``remember_me`` firewall option.
12-
The firewall needs to have a secret key configured, which is used to encrypt
13-
the cookie's content. It also has several options with default values which
14-
are shown here:
11+
the session lasts using a cookie with the ``remember_me`` firewall option:
1512

1613
.. configuration-block::
1714

@@ -22,9 +19,8 @@ are shown here:
2219
main:
2320
remember_me:
2421
key: "%secret%"
25-
lifetime: 31536000 # 365 days in seconds
22+
lifetime: 604800 # 1 week in seconds
2623
path: /
27-
domain: ~ # Defaults to the current domain from $_SERVER
2824
2925
.. code-block:: xml
3026
@@ -33,9 +29,8 @@ are shown here:
3329
<firewall>
3430
<remember-me
3531
key = "%secret%"
36-
lifetime = "31536000" <!-- 365 days in seconds -->
32+
lifetime = "604800" <!-- 1 week in seconds -->
3733
path = "/"
38-
domain = "" <!-- Defaults to the current domain from $_SERVER -->
3934
/>
4035
</firewall>
4136
</config>
@@ -48,14 +43,60 @@ are shown here:
4843
'main' => array(
4944
'remember_me' => array(
5045
'key' => '%secret%',
51-
'lifetime' => 31536000, // 365 days in seconds
46+
'lifetime' => 604800, // 1 week in seconds
5247
'path' => '/',
53-
'domain' => '', // Defaults to the current domain from $_SERVER
5448
),
5549
),
5650
),
5751
));
5852
53+
The ``remember_me`` firewall defines the following configuration options:
54+
55+
``key`` (default value: ``null``)
56+
The value used to encrypt the cookie's content. It's common to use the
57+
``secret`` value defined in the ``app/config/parameters.yml`` file.
58+
59+
``name`` (default value: ``REMEMBERME``)
60+
The name of the cookie used to maintain the user logged in. If you enable the
61+
"Remember Me" feature in several firewalls of the same application, make sure
62+
to choose a different name for the cookie of each firewall. Otherwise, you'll
63+
face lots of security related problems.
64+
65+
``lifetime`` (default value: ``31536000``)
66+
The number of seconds during which the user will remain logged in. By default
67+
users are logged in for one year.
68+
69+
``path`` (default value: ``/``)
70+
The path where the cookie associated with this feature is used. By default
71+
the cookie will be applied to the entire website but you can restrict to a
72+
specific section (e.g. ``/forum``, ``/admin``).
73+
74+
``domain`` (default value: ``null``)
75+
The domain where the cookie associated with this feature is used. By default
76+
cookies use the current domain obtained from ``$_SERVER``.
77+
78+
``secure`` (default value: ``false``)
79+
If ``true``, the cookie associated with this feature is sent to the user
80+
through an HTTPS secure connection.
81+
82+
``httponly`` (default value: ``true``)
83+
If ``true``, the cookie associated with this feature is accessible only
84+
through the HTTP protocol. This means that the cookie won't be accessible
85+
by scripting languages, such as JavaScript.
86+
87+
``remember_me_parameter`` (default value: ``_remember_me``)
88+
The name of the form field checked to decide if the "Remember Me" feature
89+
should be enabled or not. Keep reading this article to know how to enable
90+
this feature conditionally.
91+
92+
``always_remember_me`` (default value: ``false``)
93+
If ``true``, the value of the ``remember_me_parameter`` is ignored and the
94+
"Remember Me" feature is always enabled, regardless of the desire of the
95+
end user.
96+
97+
Forcing the User to Opt-Out of the Remember Me Feature
98+
------------------------------------------------------
99+
59100
It's a good idea to provide the user with the option to use or not use the
60101
remember me functionality, as it will not always be appropriate. The usual
61102
way of doing this is to add a checkbox to the login form. By giving the checkbox

0 commit comments

Comments
 (0)