8000 bug #49758 [HttpFoundation] Use separate caches for IpUtils checkIp4 … · symfony/symfony@c42e033 · GitHub
[go: up one dir, main page]

Skip to content

Commit c42e033

Browse files
committed
bug #49758 [HttpFoundation] Use separate caches for IpUtils checkIp4 and checkIp6 (danielburger1337)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [HttpFoundation] Use separate caches for IpUtils checkIp4 and checkIp6 | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix #49749 | License | MIT | Doc PR | N/A Fixed issue #49749 Commits ------- cf9b132 [HttpFoundation] Use separate caches for IpUtils checkIp4 and checkIp6
2 parents 6fe1067 + cf9b132 commit c42e033

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/Symfony/Component/HttpFoundation/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
}

src/Symfony/Component/HttpFoundation/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)
0