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

Commit495b2ce

Browse files
committed
Ensure placeholders strictly matches roles
1 parent0240d67 commit495b2ce

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

‎src/Symfony/Component/Security/Core/Role/RoleHierarchy.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,6 @@ private function getPlaceholderPattern(string $role): string|false
134134
/** @var int $count */
135135
$placeholderPattern =preg_replace(pattern:'/(?<=_)\\\\\*(?=_|$)/', replacement:'[^\*]*', subject:preg_quote($role), count:$count);
136136

137-
return ($count >0) ?sprintf('/%s/',$placeholderPattern) :false;
137+
return ($count >0) ?sprintf('/^%s$/',$placeholderPattern) :false;
138138
}
139139
}

‎src/Symfony/Component/Security/Core/Tests/Role/RoleHierarchyTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function testGetReachableRoleNamesWithPlaceholders()
3737
'ROLE_BAZ_*' => ['ROLE_USER'],
3838
'ROLE_FOO_*' => ['ROLE_BAZ_FOO'],
3939
'ROLE_BAR_*' => ['ROLE_BAZ_BAR'],
40+
'ROLE_QUX_*_BAR' => ['ROLE_FOOBAR'],
4041
]);
4142

4243
$this->assertEquals(['ROLE_BAZ_A','ROLE_USER'],$role->getReachableRoleNames(['ROLE_BAZ_A']));
@@ -47,6 +48,10 @@ public function testGetReachableRoleNamesWithPlaceholders()
4748

4849
// Multiple roles matching multiple placeholders
4950
$this->assertEquals(['ROLE_FOO_A','ROLE_BAR_A','ROLE_BAZ_FOO','ROLE_BAZ_BAR','ROLE_USER'],$role->getReachableRoleNames(['ROLE_FOO_A','ROLE_BAR_A']));
51+
52+
// Test placeholders don't match more than the pattern
53+
$this->assertEquals(['FOO_ROLE_FOO_A'],$role->getReachableRoleNames(['FOO_ROLE_FOO_A']));// Doesn't start with ROLE_FOO_
54+
$this->assertEquals(['ROLE_QUX_A_BARA'],$role->getReachableRoleNames(['ROLE_QUX_A_BARA']));// Doesn't end with _BAR
5055
}
5156

5257
publicfunctiontestGetReachableRoleNamesWithRecursivePlaceholders()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp