Skip to content

Commit 8459dff

Browse files
committed
Minor tweaks
1 parent 62380d3 commit 8459dff

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

reference/configuration/security.rst

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,20 @@ erase_credentials
5151
**type**: ``boolean`` **default**: ``true``
5252

5353
If ``true``, the ``eraseCredentials()`` method of the user object is called
54-
after authentication.
54+
after authentication::
55+
56+
use Symfony\Component\Security\Core\User\UserInterface;
57+
58+
class User implements UserInterface
59+
{
60+
// ...
61+
62+
public function eraseCredentials(): void
63+
{
64+
// If you store any temporary, sensitive data on the user, clear it here
65+
// $this->plainPassword = null;
66+
}
67+
}
5568

5669
.. deprecated:: 7.3
5770

security.rst

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2779,22 +2779,21 @@ object) are "compared" to see if they are "equal". By default, the core
27792779
your user will be logged out. This is a security measure to make sure that malicious
27802780
users can be de-authenticated if core user data changes.
27812781

2782-
Note that storing the (plain or hashed) password in the session storage can be seen
2783-
as a security risk. In order to address this risk, the ``__serialize()`` magic method
2784-
can be implemented on the user class to filter out the password before storing the
2785-
serialized user object in the session.
2786-
Two strategies are supported while serializing:
2787-
2788-
#. Removing the password entirely. In this case, ``getPassword()`` will return ``null``
2789-
after unserialization and Symfony will refresh the user without checking the
2790-
password. Use this strategy if you store plaintext passwords (not recommended.)
2791-
#. Hashing the password using the ``crc32c`` algorithm. In this case Symfony will
2792-
compare the password of the refreshed user after crc32c-hashing it. This is a good
2793-
strategy if you use hashed passwords since it allows invalidating concurrent
2794-
sessions when a password changes without storing the password hash in the session.
2795-
2796-
Here is an example of how to implement this, assuming the password is found in a
2797-
private property named ``password``::
2782+
Storing the (plain or hashed) password in the session can be a security risk.
2783+
To mitigate this, implement the ``__serialize()`` magic method in your user class
2784+
to exclude or transform the password before storing the serialized user object
2785+
in the session.
2786+
2787+
Two strategies are supported:
2788+
2789+
#. Remove the password completely. After unserialization, ``getPassword()`` returns
2790+
``null`` and Symfony refreshes the user without checking the password. Use this
2791+
only if you store plaintext passwords (not recommended).
2792+
#. Hash the password using the ``crc32c`` algorithm. Symfony will hash the password
2793+
of the refreshed user and compare it to the session value. This approach avoids
2794+
storing the real hash and lets you invalidate sessions on password change.
2795+
2796+
Example (assuming the password is stored in a private property called ``password``)::
27982797

27992798
public function __serialize(): array
28002799
{
@@ -2804,6 +2803,11 @@ Two strategies are supported while serializing:
28042803
return $data;
28052804
}
28062805

2806+
.. versionadded:: 7.3
2807+
2808+
Support for hashing passwords with ``crc32c`` in session serialization was
2809+
introduced in Symfony 7.3.
2810+
28072811
If you're having problems authenticating, it could be that you *are* authenticating
28082812
successfully, but you immediately lose authentication after the first redirect.
28092813

0 commit comments

Comments
 (0)