8000 [HttpFoundation] IPv4-mapped IPv6 addresses incorrectly rejected by bonroyage · Pull Request #48421 · symfony/symfony · GitHub
[go: up one dir, main page]

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
12 changes: 8 additions & 4 deletions src/Symfony/Component/HttpFoundation/IpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ public static function checkIp6($requestIp, $ip)
}

// Check to see if we were given a IP4 $requestIp or $ip by mistake
if (str_contains($requestIp, '.') || str_contains($ip, '.')) {
return self::$checkedIps[$cacheKey] = false;
}

if (!filter_var($requestIp, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
return self::$checkedIps[$cacheKey] = false;
}

if (str_contains($ip, '/')) {
[$address, $netmask] = explode('/', $ip, 2);

if (!filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
return self::$checkedIps[$cacheKey] = false;
}

if ('0' === $netmask) {
return (bool) unpack('n*', @inet_pton($address));
}
Expand All @@ -144,6 +144,10 @@ public static function checkIp6($requestIp, $ip)
return self::$checkedIps[$cacheKey] = false;
}
} else {
if (!filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
return self::$checkedIps[$cacheKey] = false;
}

$address = $ip;
$netmask = 128;
}
Expand Down
1 change: 1 addition & 0 deletions src/Symfony/Component/HttpFoundation/Tests/IpUtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ public function getIpv6Data()
[false, '0.0.0.0/8', '::1'],
[false, '::1', '127.0.0.1'],
[false, '::1', '0.0.0.0/8'],
[true, '::ffff:10.126.42.2', '::ffff:10.0.0.0/0'],
];
}

Expand Down
0