BeforeActionRateLimitResponseEvent
New in version 14.2 Feature: #108982 - Introduce rate limiting for Extbase actions
The PSR-14 event
\TYPO3\ is
dispatched when an Extbase action annotated with
#[RateLimit]
has reached its limit, before the response leaves the controller. A listener
can replace that response or act on the event, for example to write a log
entry.
Without a listener, Extbase answers with HTTP 429 Too many requests.
Example: let the site error handler answer instead
The following listener passes the request to the error handler of the site. A visitor who reaches the limit then sees the error page of the site, and not a bare 429 response:
<?php
declare(strict_types=1);
namespace MyVendor\MyExtension\EventListener;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Http\PropagateResponseException;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Event\Mvc\BeforeActionRateLimitResponseEvent;
use TYPO3\CMS\Frontend\Controller\ErrorController;
final readonly class RateLimitErrorPageListener
{
#[AsEventListener('my_extension/rate-limit-error-page')]
public function __invoke(BeforeActionRateLimitResponseEvent $event): void
{
$response = GeneralUtility::makeInstance(ErrorController::class)
->accessDeniedAction(
$event->getRequest(),
$event->getRateLimit()->message,
);
throw new PropagateResponseException($response, 1771077885);
}
}
Calling
set instead returns a response of your own and keeps
the request in Extbase.
API
-
final class
BeforeActionRateLimitResponseEvent -
- Fully qualified name
-
\TYPO3\CMS\ Extbase\ Event\ Mvc\ Before Action Rate Limit Response Event
Event that is triggered, when an extbase action is rate limitied and before the rate limit response is sent.
Extension developers can use this event to provide an alternative response or to implement a custom logic.