Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Remove call to undefined function, fix typing
Signed-off-by: Côme Chilliet <[email protected]>
  • Loading branch information
come-nc committed Aug 1, 2022
commit 4664375cbc204b3466b91b29d6e281415ed358bc
33 changes: 11 additions & 22 deletions lib/private/Http/IpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
* @author Fabien Potencier <[email protected]>
*/
class IpUtils {
/**
* @var array<string,bool>
*/
private static $checkedIps = [];

/**
Expand All @@ -31,13 +34,7 @@ private function __construct() {
*
* @return bool
*/
public static function checkIp(?string $requestIp, $ips) {
if (null === $requestIp) {
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);

return false;
}

public static function checkIp(string $requestIp, $ips) {
if (!\is_array($ips)) {
$ips = [$ips];
}
Expand All @@ -61,13 +58,7 @@ public static function checkIp(?string $requestIp, $ips) {
*
* @return bool Whether the request IP matches the IP, or whether the request IP is within the CIDR subnet
*/
public static function checkIp4(?string $requestIp, string $ip) {
if (null === $requestIp) {
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);

return false;
}

public static function checkIp4(string $requestIp, string $ip) {
$cacheKey = $requestIp.'-'.$ip;
if (isset(self::$checkedIps[$cacheKey])) {
return self::$checkedIps[$cacheKey];
Expand All @@ -81,9 +72,11 @@ public static function checkIp4(?string $requestIp, string $ip) {
[$address, $netmask] = explode('/', $ip, 2);

if ('0' === $netmask) {
return self::$checkedIps[$cacheKey] = filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
return self::$checkedIps[$cacheKey] = (bool)filter_var($address, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4);
}

$netmask = (int)$netmask;

if ($netmask < 0 || $netmask > 32) {
return self::$checkedIps[$cacheKey] = false;
}
Expand Down Expand Up @@ -113,13 +106,7 @@ public static function checkIp4(?string $requestIp, string $ip) {
*
* @throws \RuntimeException When IPV6 support is not enabled
*/
public static function checkIp6(?string $requestIp, string $ip) {
if (null === $requestIp) {
trigger_deprecation('symfony/http-foundation', '5.4', 'Passing null as $requestIp to "%s()" is deprecated, pass an empty string instead.', __METHOD__);

return false;
}

public static function checkIp6(string $requestIp, string $ip) {
$cacheKey = $requestIp.'-'.$ip;
if (isset(self::$checkedIps[$cacheKey])) {
return self::$checkedIps[$cacheKey];
Expand All @@ -136,6 +123,8 @@ public static function checkIp6(?string $requestIp, string $ip) {
return (bool) unpack('n*', @inet_pton($address));
}

$netmask = (int)$netmask;

if ($netmask < 1 || $netmask > 128) {
return self::$checkedIps[$cacheKey] = false;
}
Expand Down