Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita5a91a7

Browse files
committed
bug#19725 [Security] $attributes can be anything, but RoleVoter assumes strings (Jonatan Männchen)
This PR was merged into the 2.7 branch.Discussion----------[Security] $attributes can be anything, but RoleVoter assumes strings| Q | A| ------------- | ---| Branch? | 2.7| Bug fix? | yes| New feature? | no| BC breaks? | yes| Deprecations? | no| Tests pass? | yes| Fixed tickets |#18042| License | MIT| Doc PR | reference to the documentation PR, if anyCommits-------ad3ac95 bug#18042 [Security] $attributes can be anything, but RoleVoter assumes strings
2 parentsd040748 +ad3ac95 commita5a91a7

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

‎src/Symfony/Component/Security/Core/Authorization/Voter/RoleVoter.php‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespaceSymfony\Component\Security\Core\Authorization\Voter;
1313

1414
useSymfony\Component\Security\Core\Authentication\Token\TokenInterface;
15+
useSymfony\Component\Security\Core\Role\RoleInterface;
1516

1617
/**
1718
* RoleVoter votes if any attribute starts with a given prefix.
@@ -37,7 +38,7 @@ public function __construct($prefix = 'ROLE_')
3738
*/
3839
publicfunctionsupportsAttribute($attribute)
3940
{
40-
return0 ===strpos($attribute,$this->prefix);
41+
returnis_string($attribute) &&0 ===strpos($attribute,$this->prefix);
4142
}
4243

4344
/**
@@ -57,6 +58,10 @@ public function vote(TokenInterface $token, $object, array $attributes)
5758
$roles =$this->extractRoles($token);
5859

5960
foreach ($attributesas$attribute) {
61+
if ($attributeinstanceof RoleInterface) {
62+
$attribute =$attribute->getRole();
63+
}
64+
6065
if (!$this->supportsAttribute($attribute)) {
6166
continue;
6267
}

‎src/Symfony/Component/Security/Core/Tests/Authorization/Voter/RoleVoterTest.php‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@ public function getVoteTests()
4343
array(array('ROLE_FOO'),array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
4444
array(array('ROLE_FOO'),array('FOO','ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
4545
array(array('ROLE_BAR','ROLE_FOO'),array('ROLE_FOO'), VoterInterface::ACCESS_GRANTED),
46+
47+
// Test mixed Types
48+
array(array(),array(array()), VoterInterface::ACCESS_ABSTAIN),
49+
array(array(),array(new \stdClass()), VoterInterface::ACCESS_ABSTAIN),
50+
array(array('ROLE_BAR'),array(newRole('ROLE_BAR')), VoterInterface::ACCESS_GRANTED),
51+
array(array('ROLE_BAR'),array(newRole('ROLE_FOO')), VoterInterface::ACCESS_DENIED),
4652
);
4753
}
4854

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp