Resolve recommended-profile Critical and High findings, retain narrow analyzer exceptions, and update the edge-broker WebSocket dependency to a non-vulnerable release.
29 lines
764 B
PHP
29 lines
764 B
PHP
<?php
|
|
|
|
namespace classes;
|
|
|
|
use interfaces\ratelimit_i;
|
|
use objects\ratelimit_o;
|
|
|
|
class ratelimit implements ratelimit_i
|
|
{
|
|
private int $limit; // The number of requests allowed in the time period
|
|
|
|
public function __construct(int $defaultLimit, int $defaultTime)
|
|
{
|
|
$this->limit = $defaultLimit;
|
|
unset($defaultTime); // The reset interval is managed by the rate-limit maintenance task.
|
|
}
|
|
|
|
public function enforceIP(string $ip): bool
|
|
{
|
|
global $response;
|
|
$ratelimit = (new ratelimit_o())->getOrCreateRateLimitByIp($ip);
|
|
if ($ratelimit->count->value() >= $this->limit) {
|
|
$response->rate_limit_exceeded();
|
|
}
|
|
$ratelimit->increment($ratelimit->id, 1);
|
|
return true;
|
|
}
|
|
}
|