[Security] Support hashing the hashed password using crc32c when putting the user in the session#59562
Merged
chalasr merged 1 commit intosymfony:7.3from Feb 10, 2025
Merged
Conversation
e45fa9e to
b8f77ae
Compare
nicolas-grekas
commented
Jan 20, 2025
src/Symfony/Component/Security/Core/Tests/Authentication/Token/Fixtures/CustomUser.php
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/Firewall/ContextListener.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/Tests/Firewall/AccessListenerTest.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/Tests/Firewall/ContextListenerTest.php
Outdated
Show resolved
Hide resolved
46faf11 to
d1ee5c4
Compare
d1ee5c4 to
53a1aab
Compare
53a1aab to
2dcb3d9
Compare
Member
Author
|
PR ready /cc @symfony/mergers |
9cab9e1 to
7f7247b
Compare
Member
Author
|
(PR rebased) |
welcoMattic
reviewed
Feb 3, 2025
7f7247b to
05f606b
Compare
welcoMattic
approved these changes
Feb 3, 2025
8243e9a to
f6742c6
Compare
GromNaN
reviewed
Feb 10, 2025
Member
There was a problem hiding this comment.
LGTM. Just a question in tests.
src/Symfony/Component/Security/Http/Firewall/ContextListener.php
Outdated
Show resolved
Hide resolved
| } | ||
|
|
||
| if ($originalUser instanceof LegacyPasswordAuthenticatedUserInterface && $refreshedUser instanceof LegacyPasswordAuthenticatedUserInterface && $originalUser->getSalt() !== $refreshedUser->getSalt()) { | ||
| if ($originalUser instanceof LegacyPasswordAuthenticatedUserInterface && $originalUser->getSalt() !== $refreshedUser->getSalt()) { |
Member
There was a problem hiding this comment.
The psalm false-positive is reported vimeo/psalm#9956
chalasr
approved these changes
Feb 10, 2025
…ing the user in the session
f6742c6 to
a4f8a76
Compare
GromNaN
approved these changes
Feb 10, 2025
Member
|
Thank you @nicolas-grekas. |
BAC0
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR builds on #59539 following the discussion that happened there.
Here is what I added to PasswordAuthenticatedUserInterface to explain what this PR enables:
crc32c is selected because its probability to change when the password hash changes is high, so that the invalidation of sessions is effective. But it's also selected because there are many possible valid password hashes that generate the same crc32c. This protects against brute-forcing the password hash: let's say one is able to find a password hash that has the same crc32c as the real password hash: one would still be unable to confirm that this password hash is the correct one. To do so, they would have to brute-force the password hash itself, and this would require brute-forcing bcrypt et al. The cost of doing so on one bcrypted-password is already prohibitive. Doing so with a very high number of possible candidates (as collisions are generated) would be even more prohibitive.
Note that to generate a collision, one just needs to generate a random string that's formatted as a real hash, like this line for a bcrypted-password:
(one could likely create a crc32c-aware collision generator for this purpose, but that wouldn't reduce the difficulty of validating the generated hashes).
On the contrary, using a more collision resistant hashing algorithm would make it too easy to validate that a generated hash is the real hash.