Skip to content

Commit e16b267

Browse files
Merge branch '5.4' into 6.0
* 5.4: [HttpFoundation] Fix bad return type in IpUtils::checkIp4() [DependencyInjection] Fix order of arguments when mixing positional and named ones [HttpClient] Fix collecting data non-late for the profiler [Security/Http] Fix compat of persistent remember-me with legacy tokens Bump Symfony version to 5.4.20 Update VERSION for 5.4.19 Update CONTRIBUTORS for 5.4.19 Update CHANGELOG for 5.4.19 [Security/Http] Remove CSRF tokens from storage on successful login [HttpKernel] Remove private headers before storing responses with HttpCache
2 parents 56648fa + d043536 commit e16b267

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

IpUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public static function checkIp4(string $requestIp, string $ip): bool
7272
[$address, $netmask] = explode('/', $ip, 2);
7373

7474
if ('0' === $netmask) {
75-
return self::$checkedIps[$cacheKey] = filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
75+
return self::$checkedIps[$cacheKey] = false !== filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
7676
}
7777

7878
if ($netmask < 0 || $netmask > 32) {

Tests/IpUtilsTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,4 +137,21 @@ public function anonymizedIpData()
137137
['::123.234.235.236', '::123.234.235.0'], // deprecated IPv4-compatible IPv6 address
138138
];
139139
}
140+
141+
/**
142+
* @dataProvider getIp4SubnetMaskZeroData
143+
*/
144+
public function testIp4SubnetMaskZero($matches, $remoteAddr, $cidr)
145+
{
146+
$this->assertSame($matches, IpUtils::checkIp4($remoteAddr, $cidr));
147+
}
148+
149+
public function getIp4SubnetMaskZeroData()
150+
{
151+
return [
152+
[true, '1.2.3.4', '0.0.0.0/0'],
153+
[true, '1.2.3.4', '192.168.1.0/0'],
154+
[false, '1.2.3.4', '256.256.256/0'], // invalid CIDR notation
155+
];
156+
}
140157
}

0 commit comments

Comments
 (0)