-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[security-core] Wrong roles comparison in hasUserChanged method #35941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Sorry for multiple pull requests, it's my first PR |
This looks similar to #35509. |
See also #35533 |
I'm with @pevdh. It's technically a BC break. I think that the intended purpose of the if ($token->isAuthenticated()) {
assert($token->setUser($token->getUser())->isAuthenticated());
} But 4f4c30d broke the assertion. @chalasr mentioned in #35533 (comment) that:
With #35944 that hardcoded exception to the rule can (and should) be removed. The token roles and the user roles are (currently) two different things, and the |
@wouterj in case it helps debug this issue, @ajgarlag shared this example showing the BC break: https://gist.github.com/ajgarlag/43ec84816d72bdd513dc238c0dba6de4 Thanks. |
The fix for this issue has already been provided: #35944 But another PR that tried to fix this was rejected: #35533 So I'm not sure what should be done here. From my point of view, this is a BC break and we should do the following things:
|
@wouterj Works for me. |
This PR was merged into the 4.4 branch. Discussion ---------- [Security/Core] Fix wrong roles comparison | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #35941 | License | MIT Fix wrong roles comparison. Commits ------- 7d2ad4b Fix wrong roles comparison
This PR was squashed before being merged into the 4.4 branch. Discussion ---------- [Security] Fixed AbstractToken::hasUserChanged() | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #36989 | License | MIT | Doc PR | - This PR completely reverts #35944. That PR tried to fix a BC break (ref #35941, #35509) introduced by #31177. However, this broke many authentications (ref #36989), as the User is serialized in the session (as hinted by @stof). Many applications don't include the `roles` property in the serialization (at least, the MakerBundle doesn't include it). In 5.2, we should probably deprecate having different roles in token and user, which fixes the BC breaks all together. Commits ------- f297beb [Security] Fixed AbstractToken::hasUserChanged()
Uh oh!
There was an error while loading. Please reload this page.
Symfony version(s) affected: 4.4 / 5.0
Description
It seems there is mistake here :
https://github.com/symfony/security-core/blob/6251c8e432640106e6f2f045ac3b365f1af36d44/Authentication/Token/AbstractToken.php#L326
How to reproduce
When simulating authentication, roles passed to UsernamePasswordToken have to be identical to user roles retrieve by user_provider. It doesn't make any sense. The fourth parameter of UsernamePasswordToken is useless in this case.
Possible Solution
It should be :
instead of
The text was updated successfully, but these errors were encountered: