diff --git a/src/Symfony/Component/HttpFoundation/IpUtils.php b/src/Symfony/Component/HttpFoundation/IpUtils.php index 2f31284e36c69..49d9a9d74c251 100644 --- a/src/Symfony/Component/HttpFoundation/IpUtils.php +++ b/src/Symfony/Component/HttpFoundation/IpUtils.php @@ -73,7 +73,7 @@ public static function checkIp4(?string $requestIp, string $ip) return false; } - $cacheKey = $requestIp.'-'.$ip; + $cacheKey = $requestIp.'-'.$ip.'-v4'; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; } @@ -126,7 +126,7 @@ public static function checkIp6(?string $requestIp, string $ip) return false; } - $cacheKey = $requestIp.'-'.$ip; + $cacheKey = $requestIp.'-'.$ip.'-v6'; if (isset(self::$checkedIps[$cacheKey])) { return self::$checkedIps[$cacheKey]; } diff --git a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php index 085790cf606a8..f5ac4053b62a6 100644 --- a/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php +++ b/src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php @@ -19,6 +19,21 @@ class IpUtilsTest extends TestCase { use ExpectDeprecationTrait; + public function testSeparateCachesPerProtocol() + { + $ip = '192.168.52.1'; + $subnet = '192.168.0.0/16'; + + $this->assertFalse(IpUtils::checkIp6($ip, $subnet)); + $this->assertTrue(IpUtils::checkIp4($ip, $subnet)); + + $ip = '2a01:198:603:0:396e:4789:8e99:890f'; + $subnet = '2a01:198:603:0::/65'; + + $this->assertFalse(IpUtils::checkIp4($ip, $subnet)); + $this->assertTrue(IpUtils::checkIp6($ip, $subnet)); + } + /** * @dataProvider getIpv4Data */