Skip to content

Commit b6db638

Browse files
committed
bug #48050 [HttpFoundation] Check IPv6 is valid before comparing it (PhilETaylor)
This PR was submitted for the 5.4 branch but it was merged into the 4.4 branch instead. Discussion ---------- [HttpFoundation] Check IPv6 is valid before comparing it | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #48049 | License | MIT Ensure that the `checkIp6` only validates IPv6 addresses and ipv6 subnets. PR Assumes that IPv6 and ipv6 subnets can never have a period in them (which as far as I know, is correct). Commits ------- 2b7ff11 [HttpFoundation] Check IPv6 is valid before comparing it
2 parents 6303708 + 2b7ff11 commit b6db638

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

src/Symfony/Component/HttpFoundation/IpUtils.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ public static function checkIp6($requestIp, $ip)
124124
throw new \RuntimeException('Unable to check Ipv6. Check that PHP was not compiled with option "disable-ipv6".');
125125
}
126126

127+
// Check to see if we were given a IP4 $requestIp or $ip by mistake
128+
if (str_contains($requestIp, '.') || str_contains($ip, '.')) {
129+
return self::$checkedIps[$cacheKey] = false;
130+
}
131+
132+
if (!filter_var($requestIp, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
133+
return self::$checkedIps[$cacheKey] = false;
134+
}
135+
127136
if (str_contains($ip, '/')) {
128137
[$address, $netmask] = explode('/', $ip, 2);
129138

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function getIpv6Data()
7373
[false, '2a01:198:603:0:396e:4789:8e99:890f', 'unknown'],
7474
[false, '', '::1'],
7575
[false, null, '::1'],
76+
[false, '127.0.0.1', '::1'],
77+
[false, '0.0.0.0/8', '::1'],
78+
[false, '::1', '127.0.0.1'],
79+
[false, '::1', '0.0.0.0/8'],
7680
];
7781
}
7882

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy