diff --git a/wp-includes/SimplePie/src/Cache/Redis.php b/wp-includes/SimplePie/src/Cache/Redis.php index 3ba0a3ed5996..9975d2a23720 100644 --- a/wp-includes/SimplePie/src/Cache/Redis.php +++ b/wp-includes/SimplePie/src/Cache/Redis.php @@ -54,8 +54,22 @@ class Redis implements Base */ public function __construct(string $location, string $name, $options = null) { - //$this->cache = \flow\simple\cache\Redis::getRedisClientInstance(); $parsed = \SimplePie\Cache::parse_URL($location); + + // Validate the protocol + if ($parsed['scheme'] !== 'redis') { + throw new \InvalidArgumentException('Invalid protocol. Only "redis" protocol is supported.'); + } + + // Validate the host and port + $allowedHosts = ['localhost', '127.0.0.1']; // Add more hosts to the whitelist as needed + if (!in_array($parsed['host'], $allowedHosts)) { + throw new \InvalidArgumentException('Invalid host. Only hosts in the whitelist are allowed.'); + } + if (!is_int($parsed['port']) || $parsed['port'] < 1 || $parsed['port'] > 65535) { + throw new \InvalidArgumentException('Invalid port. Port must be an integer between 1 and 65535.'); + } + $redis = new NativeRedis(); $redis->connect($parsed['host'], $parsed['port']); if (isset($parsed['pass'])) { @@ -169,3 +183,4 @@ public function unlink() } class_alias('SimplePie\Cache\Redis', 'SimplePie_Cache_Redis'); +