Skip to content

Commit

Permalink
[HttpFoundation] IpUtils::checkIp4() should allow networks
Browse files Browse the repository at this point in the history
  • Loading branch information
zerkms authored and fabpot committed May 20, 2015
1 parent af0e02c commit 921ecff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/IpUtils.php
Expand Up @@ -62,6 +62,10 @@ public static function checkIp($requestIp, $ips)
public static function checkIp4($requestIp, $ip)
{
if (false !== strpos($ip, '/')) {
if ('0.0.0.0/0' === $ip) {
return true;
}

list($address, $netmask) = explode('/', $ip, 2);

if ($netmask < 1 || $netmask > 32) {
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Expand Up @@ -34,6 +34,9 @@ public function testIpv4Provider()
array(true, '192.168.1.1', array('1.2.3.4/1', '192.168.1.0/24')),
array(true, '192.168.1.1', array('192.168.1.0/24', '1.2.3.4/1')),
array(false, '192.168.1.1', array('1.2.3.4/1', '4.3.2.1/1')),
array(true, '1.2.3.4', '0.0.0.0/0'),
array(false, '1.2.3.4', '256.256.256/0'),
array(false, '1.2.3.4', '192.168.1.0/0'),
);
}

Expand Down

0 comments on commit 921ecff

Please sign in to comment.