fix: RateLimit graceful degradation on permission denied

Silence mkdir() with @ operator; guard file_put_contents with
is_writable() check. When storage/cache/rate_limit is not writable
by php-fpm, requests are allowed through instead of throwing
warnings that flood the nginx error log.
This commit is contained in:
Pontoporeia
2026-04-06 16:39:55 +02:00
parent 6a1b41ac93
commit 756ddb5765
4 changed files with 20 additions and 3 deletions

View File

@@ -22,7 +22,7 @@ class RateLimit {
// Create cache directory if it doesn't exist
if (!is_dir($this->cacheDir)) {
mkdir($this->cacheDir, 0755, true);
@mkdir($this->cacheDir, 0755, true);
}
}
@@ -79,8 +79,10 @@ class RateLimit {
// Add new request timestamp
$data[] = $now;
// Save updated data
file_put_contents($file, json_encode($data));
// Save updated data (silently skip if directory is not writable)
if (is_dir($this->cacheDir) && is_writable($this->cacheDir)) {
file_put_contents($file, json_encode($data));
}
return true;
}