Closed
Description
Symfony version(s) affected: 5.2
Description
When using "no_limit" policy with rate limiter, for example during tests, NoLimiter passes \INF
as constructor argument to RateLimit which expects integer and this will result in TypeError.
TypeError: Argument 1 passed to Symfony\Component\RateLimiter\RateLimit::__construct() must be of the type int, float given, called in /home/jontsa/Code/demo/vendor/symfony/rate-limiter/Policy/NoLimiter.php on line 37
How to reproduce
Install symfony/rate-limiter component and configure limit using no_limit policy
# config/packages/rate_limiter.yaml
framework:
rate_limiter:
anonymous_api:
policy: 'no_limit'
limit: 10
interval: '1 minute'
Then attempt to consume one token using this limiter:
private function checkAnonymousRateLimit(Request $request, RateLimiterFactory $anonymousApiLimiter) : void
{
$limiter = $anonymousApiLimiter->create($request->getClientIp());
$limit = $limiter->consume(1);
if (false === $limit->isAccepted()) {
throw new TooManyRequestsHttpException();
}
}
Possible Solution
Additional context