Skip to content
Open
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
17 changes: 16 additions & 1 deletion wp-includes/SimplePie/src/Cache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand Down Expand Up @@ -169,3 +183,4 @@ public function unlink()
}

class_alias('SimplePie\Cache\Redis', 'SimplePie_Cache_Redis');