Skip to content

Commit ea6e3d5

Browse files
committed
bug symfony#14690 [HttpFoundation] IpUtils::checkIp4() should allow /0 networks (zerkms)
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes symfony#14690). Discussion ---------- [HttpFoundation] IpUtils::checkIp4() should allow `/0` networks | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | yes | Deprecations? | no | Tests pass? | yes | Fixed tickets | symfony#14674 | License | MIT Technically it's a breaking change, since the result of the IpUtils::checkIp4('1.2.3.4', '0.0.0.0/0') call was `false` now `true`. Practically - no one should ever relied on this since it's simply wrong Commits ------- 921ecff [HttpFoundation] IpUtils::checkIp4() should allow networks
2 parents af0e02c + 921ecff commit ea6e3d5

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public static function checkIp($requestIp, $ips)
6262
public static function checkIp4($requestIp, $ip)
6363
{
6464
if (false !== strpos($ip, '/')) {
65+
if ('0.0.0.0/0' === $ip) {
66+
return true;
67+
}
68+
6569
list($address, $netmask) = explode('/', $ip, 2);
6670

6771
if ($netmask < 1 || $netmask > 32) {

src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ public function testIpv4Provider()
3434
array(true, '192.168.1.1', array('1.2.3.4/1', '192.168.1.0/24')),
3535
array(true, '192.168.1.1', array('192.168.1.0/24', '1.2.3.4/1')),
3636
array(false, '192.168.1.1', array('1.2.3.4/1', '4.3.2.1/1')),
37+
array(true, '1.2.3.4', '0.0.0.0/0'),
38+
array(false, '1.2.3.4', '256.256.256/0'),
39+
array(false, '1.2.3.4', '192.168.1.0/0'),
3740
);
3841
}
3942

0 commit comments

Comments
 (0)