-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Fixed SwitchUserListener when exiting an impersonation with AnonymousToken #18425
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
Conversation
@@ -162,7 +163,7 @@ private function attemptExitUser(Request $request) | |||
throw new AuthenticationCredentialsNotFoundException('Could not find original Token object.'); | |||
} | |||
|
|||
if (null !== $this->dispatcher) { | |||
if (null !== $this->dispatcher && !$original instanceof AnonymousToken) { |
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 think it would be better to check if $original->getUser
is an instance of the UserInterface
to also support custom tokens that might return something else.
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.
you are right. I updated the code and added some tests.
👍 |
@@ -149,6 +149,54 @@ public function testExitUserDispatchesEventWithRefreshedUser() | |||
$listener->handle($this->event); | |||
} | |||
|
|||
public function testExitUserDontDispatchesEventWithStringUser() |
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.
testExitUserDoesNotDispatchEventWithStringUser
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.
@xabbuh thanks & fixed.
@lyrixx are you really allowing anonymous users to impersonate users ? This looks weird. But the fix is indeed valid |
@stof Yes I do that. It's an awesome idea for demo app (you may see it on thursday).
|
…ith AnonymousToken If you configure a firewall with switch user with `role: IS_AUTHENTICATED_ANONYMOUSLY` it's impossible to exit the impersonation because the next line `$this->provider->refreshUser($original->getUser())` will fail. It fails because `RefreshUser` expects an instance of `UserInterface` and here it's a string. Therefore, it does not make sense to refresh an Anonymous Token, right ?
Thank you @lyrixx. |
…onation with AnonymousToken (lyrixx) This PR was merged into the 2.3 branch. Discussion ---------- [Security] Fixed SwitchUserListener when exiting an impersonation with AnonymousToken | Q | A | ------------- | --- | Branch? | 2.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - If you configure a firewall with switch user with `role: IS_AUTHENTICATED_ANONYMOUSLY` it's impossible to exit the impersonation because the next line `$this->provider->refreshUser($original->getUser())` will fail. It fails because `RefreshUser` expects an instance of `UserInterface` and here it's a string. Therefore, it does not make sense to refresh an Anonymous Token, right ? Commits ------- 59fea72 [Security] Fixed SwitchUserListener when exiting an impersonication with AnonymousToken
If you configure a firewall with switch user with
role: IS_AUTHENTICATED_ANONYMOUSLY
it's impossible to exit theimpersonation because the next line
$this->provider->refreshUser($original->getUser())
will fail. It fails becauseRefreshUser
expects an instance of
UserInterface
and here it's a string.Therefore, it does not make sense to refresh an Anonymous Token, right ?