Review main Merged

92849[FEATURE] Introduce rate limiting for extbase actions

Torben Hansen CR +2 V +2 Hard +548 −5 updated 02/24/26, 09:27

Commit message

This change introduces a native rate limiting mechanism
for Extbase controller actions by implementing the new
`\TYPO3\CMS\Extbase\Attribute\RateLimit` PHP attribute.
The implementation integrates the Symfony RateLimiter
component with the TYPO3 Caching Framework to persist
consumption states across requests.

If the defined limit for an extbase action is exceeded,
the controller flow is interrupted and a PSR-7 response
with a HTTP 429 status (Too Many Requests) is returned.

To provide extensibility, the new PSR-14 event
`\TYPO3\CMS\Extbase\Event\Mvc\BeforeActionRateLimitResponseEvent`
is dispatched when a limit is hit, enabling listeners
to modify the response or to perform additional logic
(e.g. throw exception or invoke TYPO3 page error
handling).

Review

  • Code review CR +2 Done
    • Garvin Hicking +2
    • Sven Liebert +1
    • Simon Schaufelberger +1
  • Verified V +2 Done
    • Garvin Hicking +2
    • Sven Liebert +1
    • Simon Schaufelberger +1
    • core-ci +1 CI

Issues 1

Files 11

Review log 3447

Show 1522 earlier messages
  1. Torben Hansen uploaded patch set 1 02/14/26, 14:30

  2. Torben Hansen uploaded patch set 2 02/14/26, 14:33

  3. core-ci voted on patch set 1 V +1 02/14/26, 14:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95900

  4. Torben Hansen uploaded patch set 3 02/14/26, 14:43

  5. core-ci voted on patch set 2 V +1 02/14/26, 14:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95901

  6. Torben Hansen marked it work in progress 02/14/26, 14:48

  7. Torben Hansen uploaded patch set 4 02/14/26, 14:53

  8. core-ci voted on patch set 3 V +1 02/14/26, 14:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95902

  9. core-ci voted on patch set 4 V +1 02/14/26, 15:03 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95904

  10. Torben Hansen uploaded patch set 5 V +1 02/14/26, 15:24

  11. Torben Hansen marked it ready for review 02/14/26, 15:24

  12. Torben Hansen uploaded patch set 6 02/14/26, 15:26

  13. core-ci voted on patch set 6 V +1 02/14/26, 15:35 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95908

  14. Simon Schaufelberger commented on patch set 6 02/14/26, 15:51

    RateLimitService.php:33

    can this also be readonly? And why is this public and not protected?
  15. core-ci voted on patch set 5 V +1 02/14/26, 15:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95907

  16. Torben Hansen uploaded patch set 7 V +1 02/15/26, 06:01

  17. Torben Hansen commented on patch set 6 02/15/26, 06:01

    RateLimitService.php:33 Reply

    Done
  18. core-ci voted on patch set 7 V +1 02/15/26, 06:09 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95929

  19. Simon Schaufelberger voted on patch set 7 CR +1 V +1 02/15/26, 08:14

  20. Garvin Hicking commented on patch set 7 V +1 02/16/26, 13:41

    This works, just few minor comments / questions

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:33

    ```suggestion * :php:`message`: An optional, localizable translation key (not a hard-coded string) for the error message shown when the limit is reached like `messages.rate_limit_message` (the translation domain like `my_extension` will be automatically used, and must not be part of the key here), or `LLL:EXT:my_extension/Resources/Private/Language/locallang.xlf:rate_limit_message`. ``` Something like that. I first tried to use something like `core.tca:editlock` as a dummy message but that does not resolve because the usage of translationservice always uses the own scope. So you can never use a short-hand notation here of any other extension (or core message label). Maybe we should better use the long-form notation here ("my_extension.messages:blabla") by using the sL() methods internally, so a custom domain key can be used?

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:44

    ```suggestion .. code-block:: php :caption: EXT:my_extension/Classes/Controller/MyController.php ```

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:52

    ```suggestion #[RateLimit(limit: 3, interval: '1 minute', message: 'messages.ratelimitexceeded')] ```

    ActionController.php:923

    I'm thinking if we could make the integration a bit less impactful in terms of required individual reflection by maybe requiring an Extbase Controller to implement a specific interface like "RateLimitedControllerInterface"? Then we could only perform this introspecting when the interface is declared, which is available on simple runtime? It does seem to be cached to me, so maybe not that impactful. Another upside would be that we could build registries easier by collecting all controllers that implement the interface. A downside of course is that it would require integrators/developers to do two steps (interface implementation + attribute usage). (So, just an honest question 😊)
  21. Torben Hansen uploaded patch set 8 CR +1 V +1 02/16/26, 17:21

  22. Torben Hansen commented on patch set 8 02/16/26, 17:21

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:33 Reply

    I changed it. It is however not possible to use `sl()` method here, as it does not always work in Frontend context (also see comment in `TYPO3\CMS\Core\Localization\LanguageService`).

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:44 Reply

    Done

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:52 Reply

    Done

    ActionController.php:923 Reply

    I do not really see, how we could implement the "upside", since we always need the call to `handleRateLimit` from within the `callActionMethod` method. Implementing the interface would just save the check for the rate limit via reflection, but as you wrote, require the user to implement 2 steps. I think it is better to keep it as it is to make it as most easy for extension developers as possible to use the new feature.
  1. Garvin Hicking commented on patch set 8 02/16/26, 17:27

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:63

    Could you create a test and simple eventlistener example like with other PSR-14 events? And I think the Event class should have a "Event.php" suffix.
  2. core-ci voted on patch set 8 V -1 02/16/26, 17:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95986

  3. core-ci voted on patch set 8 V +1 02/16/26, 18:13 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95986

  4. Torben Hansen uploaded patch set 9 V +1 02/16/26, 18:14

  5. Torben Hansen commented on patch set 8 02/16/26, 18:14

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:63 Reply

    Done
  6. core-ci voted on patch set 9 V +1 02/16/26, 18:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95991

  7. Garvin Hicking commented on patch set 10 V +1 02/16/26, 19:01

    Published edit on patch set 9.
  8. Garvin Hicking commented on patch set 10 02/16/26, 19:04

    Can't do it well on mobile: commit message lacks the "...Event" siffix, and the listener code example needs a "use" statement to hace the fqcn in it

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:67

    ```suggestion The new PSR-14 event :php:`\TYPO3\CMS\Extbase\Event\Mvc\BeforeActionRateLimitResponseEvent` ```

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:80

    ```suggestion public function __invoke(BeforeActionRateLimitResponseEvent $event): void ```
  9. Torben Hansen commented on patch set 11 02/16/26, 19:09

    Published edit on patch set 10.
  10. Torben Hansen updated the commit message in patch set 12 02/16/26, 19:10

  11. Torben Hansen commented on patch set 12 02/16/26, 19:10

    Reply

    Done

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:67 Reply

    Fix applied.
  12. core-ci voted on patch set 10 V +1 02/16/26, 19:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95994

  13. Garvin Hicking commented on patch set 12 CR +1 V +1 02/16/26, 19:13

    Thanks 😊
  14. core-ci voted on patch set 11 V +1 02/16/26, 19:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95996

  15. core-ci voted on patch set 12 V +1 02/16/26, 19:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/95997

  16. Simon Schaufelberger commented on patch set 12 02/16/26, 20:40

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:77

    The convention is to have the suffix EventListener
  17. Torben Hansen commented on patch set 12 02/17/26, 06:59

    Feature-108982-IntroduceRateLimitingForExtbaseActions.rst:77 Reply

    Although this is mentioned as "Best practice" in the docs (https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/Events/EventDispatcher/Index.html#implementing-an-event-listener-in-your-extension), we use many classes in TYPO3 Core, which act as event listeners and do not have a `EventListener` suffix. Also the docs mix this up, so I do not agree, this is a convention. I prefer to keep it as it is, since the class name describes what it does and it is clearly identified as event listener via the php attribute and the subfolder. No need to increase the length of the class name with the suffix here.
  18. Simon Schaufelberger voted on patch set 12 CR +1 V +1 02/17/26, 22:21

  19. Sven Liebert voted on patch set 12 CR +1 V +1 02/23/26, 18:02

  20. Garvin Hicking voted on patch set 12 CR +2 V +2 02/23/26, 18:50

  21. Garvin Hicking merged patch set 13 02/23/26, 18:50

  22. Benni Mack commented on patch set 13 02/23/26, 19:05

    RateLimitService.php:31

    I assume we can drop the SingletonInterface...

    RateLimitService.php:65

    I had a similar change in my local stash, because I want to use the Rate Limiter in more places than just in login. My goal is actually to extend the RateLimiterFactory of core, and extend it. With this change right now, we cannot change the CF Storage now for this implementation.
  23. Garvin Hicking commented on patch set 13 02/23/26, 19:58

    RateLimitService.php:65 Reply

    But this service is internal, so we could adapt it for this? Can we address it in a follow-up with your patch?
  24. Torben Hansen commented on patch set 13 02/24/26, 08:14

    RateLimitService.php:65 Reply

    I just thought in the extbase context for this patch. If we want to use the rate limiter more globally, we could also move the service to e.g. ext:core and make it more flexible. I am open to help on any changes in this area.
  25. Benni Mack commented on patch set 13 02/24/26, 09:27

    RateLimitService.php:31 Reply

    Done

    RateLimitService.php:65 Reply