8000 [HttpFoundation] IpUtils::checkIp4() should allow `/0` networks by zerkms · Pull Request #14690 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpFoundation] IpUtils::checkIp4() should allow /0 networks #14690

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
bug #14674 [HttpFoundation] Added a check for 0.0.0.0/0 explicitly,…
… since it's the only allowed network of a `/0` size
  • Loading branch information
zerkms committed May 19, 2015
commit fadbba99cc8ef55090bf43f34e9b7a49b2ae2cb0
10 changes: 5 additions & 5 deletions src/Symfony/Component/HttpFoundation/IpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ 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 < 0 || $netmask > 32) {
if ($netmask < 1 || $netmask > 32) {
return false;
}

if ('0' === $netmask) {
return filter_var($address, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4);
}
} else {
$address = $ip;
$netmask = 32;
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public function testIpv4Provider()
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'),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example must be: array(false, '1.2.3.256', '0.0.0.0/0')

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example must be: array(false, '1.2.3.256', '0.0.0.0/0')

I do not agree - it's not an IpValidation class

array(false, '1.2.3.4', '192.168.1.0/0'),
);
}

Expand Down
0