-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Fixed AbstractToken::hasUserChanged() #37008
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
[Security] Fixed AbstractToken::hasUserChanged() #37008
Conversation
6e9f34a
to
d4e357b
Compare
Travis failures are unrelated (failing on PHP nightly, Cache and PropertyAccess components) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this in the Symfony Demo app and it fixed the reported issue (symfony/demo#1121). Thanks Wouter!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for better reintroducing on master.
The problem reported in #36989 should have been appeared when #31177 was merged, but it came with a bug fixed in #35944. Without that bug, all that apps broken now, should have been broken with the feature introduced in #31177. There are at least 3 options.
In my opinion, current behavior is the right one, and any implementation not serializing user roles should be fixed by implementing Maybe this deserve a longer discussion. Please does not merge this PR on weekend, and let other developers to review it during next week. |
We all agree that #31177 introduced a BC break when custom roles are added to the token (that do not exist in the user), no need to discuss that. The issue is that the proposed fix (that is reverted in this PR) breaks every application (as the user's roles aren't serialized, and thus The BC break in #31177 can be fixed by using I agree with you that the situation 4.4, 5.0 and 5.1 are in is not ideal. Let's focus on fixing the complete state in 5.2 instead (given that 5.1's stable release is only days away, I don't think there is enough time to think about and test a better fix). |
I do not agree with you that #35944 breaks every application. In symfony/symfony there is only one I agree with you that #35944 breaks some applications (including symfony/demo), that decided to use a custom User class and not to serialize user roles, but reverting #35944 will break other applications too. There is other related problem. If you revert #35944, any discussion about having different roles in user and token will be completely biased. |
The same is true for the original BC break, applications using Symfony's I don't think it makes sense fixing a BC break introduced in a minor release affecting a few applications (applications that customize Security tokens) by introducing a BC break in a patch release affecting much more applications (applications that customize the User class). Reverting both PRs (as originally suggested in the PR) is also scary: Applications that are build from 4.4 or 5.0 at the start are build with the premise "user's are logged out when you remove roles". If we revert both changes these applications silently loosen their security permissions without knowing it when upgrading to 4.4.9 or 5.0.9 (there is no Symfony error). Anyway, I'll let the core team have the final call here. Your and mine arguments are clear now, I think. |
This raises the question of the next steps. What would be the plan for 5.2? Any idea? Might they influence the decision here? My current understanding is that we should merge this PR as proposed, also because we know how to deprecate things so we won't put us in a dead end, IMHO. |
d4e357b
to
f297beb
Compare
Thank you @wouterj. |
Follow up welcome :) |
Token roles and User roles have been two different things right from the start, not sure removing that behaviour is a good idea. Not every role is persisted in db and hence won't be available in User roles, some roles are applied on fly to auth token based on different conditions. As an example ROLE_PREVIOUS_ADMIN, we cannot make SwitchUserToken an exception while preventing the same behaviour for custom roles If someone wants to trigger UserHasChanged on roles change, they can implement EquatableInterface |
AFAICT, |
I gave this another try: if some implementations are not serializing user roles, we could detect if the unserialized user instance has an empty array of roles. Then we should compare the given user roles with token roles. But if the unserialized user instance has any role, then we should compare the given user roles with unserialized user roles. But then I discovered that the new SerializableUser test class introduced in this PR shares with symfony/demo and friendsofsymfony/user-bundle a common strategy. They do not serialize user roles, but when you call I think this is a flawsy implementation: if we review Well, we are here, with a known BC break in Symfony 4.4 that in fact deprecates having different roles is user and token instances, and a lot of different (IMO flawsy) I only see an easy way: deprecate any User class not implementing |
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.