diff --git a/rate-limiter.php b/rate-limiter.php index 67be859..827a764 100644 --- a/rate-limiter.php +++ b/rate-limiter.php @@ -15,6 +15,8 @@ 'id' => getenv('RATE_LIMIT_ID'), 'interval' => getenv('RATE_LIMIT_INTERVAL'), 'host' => 'localhost', + 'auth' => ['redis-username', 'redis-password'], + 'db' => 0, 'prefix' => 'waf:ratelimit:', ]); @@ -33,15 +35,23 @@ function rate_limit(array $options): void } $key = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $key); - + try { $redis = new Redis(); if (!$redis->connect($host, 6379)) { error_log('Failed to connect to Redis server.'); return; } + if (!$redis->auth($options['auth'])) { + error_log('Failed to authenticate to Redis server.'); + return; + } + if (!$redis->select($options['db'])) { + error_log('Failed to select Redis database.'); + return; + } } catch (\RedisException $e) { - error_log('Redis connection failed: ' . $e->getMessage()); + error_log('Redis connection error: ' . $e->getMessage()); return; }