Skip to content

Commit 139674d

Browse files
Merge branch '5.2' into 5.x
* 5.2: (23 commits) [Console] Fix Windows code page support [SecurityBundle] Allow ips parameter in access_control accept comma-separated string [Form] Add TranslatableMessage support to choice_label option of ChoiceType Remove code that deals with legacy behavior of PHP_Incomplete_Class [Config][DependencyInjection] Uniformize trailing slash handling [PropertyInfo] Make ReflectionExtractor correctly extract nullability [PropertyInfo] fix attribute namespace with recursive traits [PhpUnitBridge] Fix tests with `@doesNotPerformAssertions` annotations Check redis extension version [Security] Update Russian translations [Notifier] Fix return SentMessage then Messenger not used [VarExporter] Add support of PHP enumerations [Security] Added missing Japanese translations [Security] Added missing Polish translations [Security] Add missing Italian translations #41051 [Security] Missing translations pt_BR getProtocolVersion may return null Fix return type on isAllowedProperty method Make FailoverTransport always pick the first transport [TwigBridge] Fix HTML for translatable custom-file label in Bootstrap 4 theme ...
2 parents 8dbe8cb + f409175 commit 139674d

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

DependencyInjection/SecurityExtension.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ private function createRequestMatcher(ContainerBuilder $container, string $path
10261026
foreach ($ips as $ip) {
10271027
$container->resolveEnvPlaceholders($ip, null, $usedEnvs);
10281028

1029-
if (!$usedEnvs && !$this->isValidIp($ip)) {
1029+
if (!$usedEnvs && !$this->isValidIps($ip)) {
10301030
throw new \LogicException(sprintf('The given value "%s" in the "security.access_control" config option is not a valid IP address.', $ip));
10311031
}
10321032

@@ -1084,6 +1084,25 @@ public function getConfiguration(array $config, ContainerBuilder $container)
10841084
return new MainConfiguration($this->factories, $this->userProviderFactories);
10851085
}
10861086

1087+
private function isValidIps($ips): bool
1088+
{
1089+
$ipsList = array_reduce((array) $ips, static function (array $ips, string $ip) {
1090+
return array_merge($ips, preg_split('/\s*,\s*/', $ip));
1091+
}, []);
1092+
1093+
if (!$ipsList) {
1094+
return false;
1095+
}
1096+
1097+
foreach ($ipsList as $cidr) {
1098+
if (!$this->isValidIp($cidr)) {
1099+
return false;
1100+
}
1101+
}
1102+
1103+
return true;
1104+
}
1105+
10871106
private function isValidIp(string $cidr): bool
10881107
{
10891108
$cidrParts = explode('/', $cidr);

Tests/DependencyInjection/SecurityExtensionTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,33 @@ public function testRememberMeCookieInheritFrameworkSessionCookie($config, $same
388388
$this->assertEquals($secure, $definition->getArgument(3)['secure']);
389389
}
390390

391+
/**
392+
* @dataProvider acceptableIpsProvider
393+
*/
394+
public function testAcceptableAccessControlIps($ips)
395+
{
396+
$container = $this->getRawContainer();
397+
398+
$container->loadFromExtension('security', [
399+
'providers' => [
400+
'default' => ['id' => 'foo'],
401+
],
402+
'firewalls' => [
403+
'some_firewall' => [
404+
'pattern' => '/.*',
405+
'http_basic' => [],
406+
],
407+
],
408+
'access_control' => [
409+
['ips' => $ips, 'path' => '/somewhere', 'roles' => 'IS_AUTHENTICATED_FULLY'],
410+
],
411+
]);
412+
413+
$container->compile();
414+
415+
$this->assertTrue(true, 'Ip addresses is successfully consumed: '.(\is_string($ips) ? $ips : json_encode($ips)));
416+
}
417+
391418
public function testCustomRememberMeHandler()
392419
{
393420
$container = $this->getRawContainer();
@@ -430,6 +457,16 @@ public function sessionConfigurationProvider()
430457
];
431458
}
432459

460+
public function acceptableIpsProvider(): iterable
461+
{
462+
yield [['127.0.0.1']];
463+
yield ['127.0.0.1'];
464+
yield ['127.0.0.1, 127.0.0.2'];
465+
yield ['127.0.0.1/8, 127.0.0.2/16'];
466+
yield [['127.0.0.1/8, 127.0.0.2/16']];
467+
yield [['127.0.0.1/8', '127.0.0.2/16']];
468+
}
469+
433470
public function testSwitchUserWithSeveralDefinedProvidersButNoFirewallRootProviderConfigured()
434471
{
435472
$container = $this->getRawContainer();

0 commit comments

Comments
 (0)