Skip to content

Commit 023087f

Browse files
danielburger1337GromNaN
authored andcommitted
[HttpFoundation] Use separate caches for IpUtils checkIp4 and checkIp6
1 parent c63f733 commit 023087f

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

IpUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static function checkIp4(?string $requestIp, string $ip)
7373
return false;
7474
}
7575

76-
$cacheKey = $requestIp.'-'.$ip;
76+
$cacheKey = $requestIp.'-'.$ip.'-v4';
7777
if (isset(self::$checkedIps[$cacheKey])) {
7878
return self::$checkedIps[$cacheKey];
7979
}
@@ -126,7 +126,7 @@ public static function checkIp6(?string $requestIp, string $ip)
126126
return false;
127127
}
128128

129-
$cacheKey = $requestIp.'-'.$ip;
129+
$cacheKey = $requestIp.'-'.$ip.'-v6';
130130
if (isset(self::$checkedIps[$cacheKey])) {
131131
return self::$checkedIps[$cacheKey];
132132
}

Tests/IpUtilsTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ class IpUtilsTest extends TestCase
1919
{
2020
use ExpectDeprecationTrait;
2121

22+
public function testSeparateCachesPerProtocol()
23+
{
24+
$ip = '192.168.52.1';
25+
$subnet = '192.168.0.0/16';
26+
27+
$this->assertFalse(IpUtils::checkIp6($ip, $subnet));
28+
$this->assertTrue(IpUtils::checkIp4($ip, $subnet));
29+
30+
$ip = '2a01:198:603:0:396e:4789:8e99:890f';
31+
$subnet = '2a01:198:603:0::/65';
32+
33+
$this->assertFalse(IpUtils::checkIp4($ip, $subnet));
34+
$this->assertTrue(IpUtils::checkIp6($ip, $subnet));
35+
}
36+
2237
/**
2338
* @dataProvider getIpv4Data
2439
*/

0 commit comments

Comments
 (0)