Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Symfony/Component/HttpFoundation/IpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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];
}
Expand Down
15 changes: 15 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down