-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] Fix user role restriction. #35533
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
Changes from all commits
4cf925b
2478205
4f84a99
429dee7
9de09f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,4 +73,86 @@ public function getSalt() | |
$token->setUser($impersonated); | ||
$this->assertTrue($token->isAuthenticated()); | ||
} | ||
|
||
public function testRestrictUserRolesDoesNotDeauthenticate() | ||
{ | ||
$impersonator = new class() implements UserInterface { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's better to create a separate unit for this |
||
public function getUsername() | ||
{ | ||
return 'impersonator'; | ||
} | ||
|
||
public function getPassword() | ||
{ | ||
return null; | ||
} | ||
|
||
public function eraseCredentials() | ||
{ | ||
} | ||
|
||
public function getRoles() | ||
{ | ||
return ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH']; | ||
} | ||
|
||
public function getSalt() | ||
{ | ||
return null; | ||
} | ||
}; | ||
|
||
$originalToken = new UsernamePasswordToken($impersonator, 'foo', 'provider-key', ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH']); | ||
|
||
$token = new SwitchUserToken($impersonator, 'foo', 'provider-key', ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH', 'ROLE_PREVIOUS_ADMIN'], $originalToken); | ||
$token->setUser($impersonator); | ||
$this->assertTrue($token->isAuthenticated()); | ||
|
||
$token = new SwitchUserToken($impersonator, 'foo', 'provider-key', ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_PREVIOUS_ADMIN'], $originalToken); | ||
$token->setUser($impersonator); | ||
$this->assertTrue($token->isAuthenticated()); | ||
|
||
$token = new SwitchUserToken($impersonator, 'foo', 'provider-key', ['ROLE_ADMIN', 'ROLE_PREVIOUS_ADMIN'], $originalToken); | ||
$token->setUser($impersonator); | ||
$this->assertTrue($token->isAuthenticated()); | ||
} | ||
|
||
public function testAddUserRolesDeauthenticate() | ||
{ | ||
$impersonator = new class() implements UserInterface { | ||
public function getUsername() | ||
{ | ||
return 'impersonator'; | ||
} | ||
|
||
public function getPassword() | ||
{ | ||
return null; | ||
} | ||
|
||
public function eraseCredentials() | ||
{ | ||
} | ||
|
||
public function getRoles() | ||
{ | ||
return ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH']; | ||
} | ||
|
||
public function getSalt() | ||
{ | ||
return null; | ||
} | ||
}; | ||
|
||
$originalToken = new UsernamePasswordToken($impersonator, 'foo', 'provider-key', ['ROLE_USER', 'ROLE_ADMIN', 'ROLE_ALLOWED_TO_SWITCH']); | ||
|
||
$token = new SwitchUserToken($impersonator, 'foo', 'provider-key', ['ROLE_TEST', 'ROLE_PREVIOUS_ADMIN'], $originalToken); | ||
$token->setUser($impersonator); | ||
$this->assertFalse($token->isAuthenticated()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
||
$token = new SwitchUserToken($impersonator, 'foo', 'provider-key', ['ROLE_USER', 'ROLE_TEST', 'ROLE_PREVIOUS_ADMIN', 'ROLE_ALLOWED_TO_SWITCH'], $originalToken); | ||
$token->setUser($impersonator); | ||
$this->assertFalse($token->isAuthenticated()); | ||
} | ||
} |
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.
Can you please update also
symfony/src/Symfony/Component/Security/Core/User/User.php
Line 148 in 4f4c30d
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.
Done https://github.com/gorshkov-ag/symfony/commit/429dee7efb5d018a67d0654bfbc956cb08d1b86c
Uh oh!
There was an error while loading. Please reload this page.
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.
Now is it problem in User equals test: User without role now is equivalent with user with role "ROLE", but opposite is not true.
https://github.com/gorshkov-ag/symfony/blob/9de09f0cfbfed2af1f7ae0a63597171615a51ac3/src/Symfony/Component/Security/Core/Tests/User/UserTest.php#L120