8000 bug #25330 [HttpFoundation] Support 0 bit netmask in IPv6 (`::/0`) (s… · symfony/symfony@0a7c659 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0a7c659

Browse files
committed
bug #25330 [HttpFoundation] Support 0 bit netmask in IPv6 (::/0) (stephank)
This PR was squashed before being merged into the 2.7 branch (closes #25330). Discussion ---------- [HttpFoundation] Support 0 bit netmask in IPv6 (`::/0`) | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | — | License | MIT | Doc PR | — Proxy settings allow `0.0.0.0/0` but not `::/0`. This PR adds IpUtils support for 0 masked bits in IPv6. Tests pass in the sense that results before and after are unchanged on my local PHP 7.2 / macOS setup. The IpUtils test cases were extended for the changes in this PR. I've rebased on 2.7, but the issue is present up to 4.0 and master. Commits ------- 9f1c9bd [HttpFoundation] Support 0 bit netmask in IPv6 ()
2 parents b78c0ae + 9f1c9bd commit 0a7c659

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ public static function checkIp6($requestIp, $ip)
123123
if (false !== strpos($ip, '/')) {
124124
list($address, $netmask) = explode('/', $ip, 2);
125125

126+
if ('0' === $netmask) {
127+
return (bool) unpack('n*', @inet_pton($address));
128+
}
129+
126130
if ($netmask < 1 || $netmask > 128) {
127131
return self::$checkedIps[$cacheKey] = false;
128132
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public function getIpv6Data()
6262
array(false, '2a01:198:603:0:396e:4789:8e99:890f', '::1'),
6363
array(true, '0:0:0:0:0:0:0:1', '::1'),
6464
array(false, '0:0:603:0:396e:4789:8e99:0001', '::1'),
65+
array(true, '0:0:603:0:396e:4789:8e99:0001', '::/0'),
66+
array(true, '0:0:603:0:396e:4789:8e99:0001', '2a01:198:603:0::/0'),
6567
array(true, '2a01:198:603:0:396e:4789:8e99:890f', array('::1', '2a01:198:603:0::/65')),
6668
array(true, '2a01:198:603:0:396e:4789:8e99:890f', array('2a01:198:603:0::/65', '::1')),
6769
array(false, '2a01:198:603:0:396e:4789:8e99:890f', array('::1', '1a01:198:603:0::/65')),

0 commit comments

Comments
 (0)
0