Skip to content

Commit 4c86c56

Browse files
committed
Merge pull request #3009 from symfony/issue-3003-password-length
[#3003] 4096 Password length details
2 parents 3e86f2a + 54adf73 commit 4c86c56

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

book/security.rst

+7
Original file line numberDiff line numberDiff line change
@@ -1410,6 +1410,13 @@ can always be determined in the following way from a controller::
14101410
$password = $encoder->encodePassword('ryanpass', $user->getSalt());
14111411
$user->setPassword($password);
14121412

1413+
.. caution::
1414+
1415+
When you allow a user to submit a plaintext password (e.g. registration
1416+
form, change password form), you *must* have validation that guarantees
1417+
that the password is 4096 characters or less. Read more details in
1418+
:ref:`How to implement a simple Registration Form <cookbook-registration-password-max>`.
1419+
14131420
Retrieving the User Object
14141421
~~~~~~~~~~~~~~~~~~~~~~~~~~
14151422

components/security/authentication.rst

+18-2
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,21 @@ Each encoder should implement :class:`Symfony\\Component\\Security\\Core\\Encode
190190
or be an array with a ``class`` and an ``arguments`` key, which allows the
191191
encoder factory to construct the encoder only when it is needed.
192192

193-
Password Encoders
194-
~~~~~~~~~~~~~~~~~
193+
Creating a Custom Password Encoder
194+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
195+
196+
There are many built-in password encoders. But if you need to create your
197+
own, it just needs to follow these rules:
198+
199+
#. The class must implement :class:`Symfony\\Component\\Security\\Core\\Encoder\\PasswordEncoderInterface`;
200+
201+
#. The first line in ``encodePassword`` and ``isPasswordValid`` must check
202+
to make sure the password is not too long (e.g. 4096). This is for security
203+
(see `CVE-2013-5750`_), and you can copy the `BasePasswordEncoder::checkPasswordLength`_
204+
implementation from Symfony 2.4.
205+
206+
Using Password Encoders
207+
~~~~~~~~~~~~~~~~~~~~~~~
195208

196209
When the :method:`Symfony\\Component\\Security\\Core\\Encoder\\EncoderFactory::getEncoder`
197210
method of the password encoder factory is called with the user object as
@@ -213,3 +226,6 @@ which should be used to encode this user's password::
213226
$user->getPassword(),
214227
$password,
215228
$user->getSalt());
229+
230+
.. _`CVE-2013-5750`: http://symfony.com/blog/cve-2013-5750-security-issue-in-fosuserbundle-login-form
231+
.. _`BasePasswordEncoder::checkPasswordLength`: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Security/Core/Encoder/BasePasswordEncoder.php

cookbook/doctrine/registration_form.rst

+18
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ You have a simple ``User`` entity mapped to the database::
4545
/**
4646
* @ORM\Column(type="string", length=255)
4747
* @Assert\NotBlank()
48+
* @Assert\Length(max = 4096)
4849
*/
4950
protected $plainPassword;
5051

@@ -85,6 +86,21 @@ the class.
8586
to implement the :ref:`UserInterface<book-security-user-entity>` of the
8687
security component.
8788

89+
.. _cookbook-registration-password-max:
90+
91+
.. sidebar:: Why the 4096 Password Limit?
92+
93+
Notice that the ``plainPassword`` has a max length of ``4096`` characters.
94+
For security purposes (`CVE-2013-5750`_), Symfony limits the plain password
95+
length to 4096 characters when encoding it. Adding this constraint makes
96+
sure that your form will give a validation error if anyone tries a super-long
97+
password.
98+
99+
You'll need to add this constraint anywhere in your application where
100+
your user submits a plaintext password (e.g. change password form). The
101+
only place where you don't need to worry about this is your login form,
102+
since Symfony's Security component handles this for you.
103+
88104
Create a Form for the Model
89105
---------------------------
90106

@@ -346,3 +362,5 @@ That's it! Your form now validates, and allows you to save the ``User``
346362
object to the database. The extra ``terms`` checkbox on the ``Registration``
347363
model class is used during validation, but not actually used afterwards when
348364
saving the User to the database.
365+
366+
.. _`CVE-2013-5750`: http://symfony.com/blog/cve-2013-5750-security-issue-in-fosuserbundle-login-form

0 commit comments

Comments
 (0)