Review main Merged

77158[BUGFIX] Send correct content type for cached Extbase actions

Helmut Hummel CR +2 V +2 Easy +9 −11 updated 03/16/23, 22:29

Commit message

The setContentType method on TyposcripFrontendController
was introduced to allow Extbase plugins to change the
content-type header of the server http response.

However this currently only works, when the Extbase plugin
action is uncached. Once a plugin, that is rendered on a page
ist cached in page cache, the content type of subsequent
requests is always "text/html", because the value of the
contentType property is not stored in cache.

Storing this value into cache allows creating e.g.
Json APIs as Extbase Plugins, that can be fully cached
without adding hacks like modifying config.additionalHeaders

Review

  • Code review CR +2 Done
    • Helmut Hummel +2
    • Daniel Goerz +1
    • Markus Klein +1
    • Guido Schmechel +1
    • Benni Mack +1
  • Verified V +2 Done
    • Helmut Hummel +2
    • Markus Klein +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 2629

Show 34 earlier messages
  1. Helmut Hummel uploaded patch set 1 12/14/22, 17:59

  2. Helmut Hummel marked it work in progress 12/14/22, 18:00

  3. core-ci voted on patch set 1 V -1 12/14/22, 18:08 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/35117

  4. Benni Mack commented on patch set 1 12/14/22, 18:25

    Can you elaborate why you added the config. TS option? because AFAICS you did this to keep this in scenarios with USER + USER_INTs?
  1. Markus Klein commented on patch set 1 12/14/22, 19:40

    Please definitely add more comments on this config thingy.

    Reply

    Please add your thoughts as comments to the code. This will be extremely valuable in some years.
  2. Sascha Egerer commented on patch set 1 12/15/22, 10:24

    Bootstrap.php:169

    IMO the server should decide if it can answer with the requested Content-Type. With this implementation it feels a bit unsafe as one can inject any value into the response content-type header. This may introduce a security issue if other internals change.
  3. Helmut Hummel commented on patch set 1 12/15/22, 10:32

    Reply

    uh, yeah, sorry. I can explain my thoughts, and maybe it is indeed valuable to write them down as code comments and not only in the ticket or here.
  4. Helmut Hummel commented on patch set 1 12/15/22, 10:41

    Bootstrap.php:169 Reply

    Context here is, that the code reads the response from an Extbase Plugin and does something with it. Current State: Any Extbase Plugin can set any content-type and TYPO3 will happily send it. It will send it on first request for cached actions and on all subsequent requests for uncached actions. For cached actions this code is never executed, thus content-type will always be text/html when the page comes from cache. Plugins that are rendered later, will override headers of plugins that are rendered earlier. My change does not change much on this state, except that the behaviour of cached actions and uncached actions is aligned and thus allows cached pages with a different content type. If there is a security issue with this code (which I don't see right now), it would be good to fix anyway 😊
  5. Sascha Egerer commented on patch set 1 12/15/22, 10:42

    Sorry... did not read carefully. Forgot about my comment

    Bootstrap.php:169 Reply

    Oh sorry, nevermind. I assumed that a header is read from the request, because I only read the getHeader. 🫣
  6. Benni Mack commented on patch set 1 12/15/22, 10:46

    Bootstrap.php:169 Reply

    OK. For this reason, if you're OK with it, I'd like to put this not in $this->config['config']['contentType'] but in $this->config['contentType'] - or just decide if we add the contentType to the caching information (which is easy to do, I can do that if you like, I had some hurdles with that with asset collector back then)
  7. Benni Mack commented on patch set 1 12/15/22, 10:46

    And of course, I agree with the approach in general (Extbase can send more than just JSON) :)
  8. Helmut Hummel uploaded patch set 2 V -1 12/15/22, 17:03

  9. Helmut Hummel commented on patch set 2 12/15/22, 17:03

    Bootstrap.php:169 Reply

    Yes, the config stuff is just a hack to get the value into the cache. I can take care.
  10. Helmut Hummel commented on patch set 2 12/15/22, 17:04

    This change is ready for review.

    Reply

    Changed that like Benni also suggested.
  11. core-ci voted on patch set 2 V -1 12/15/22, 17:12 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/35175

  12. Benni Mack commented on patch set 2 12/20/22, 16:55

    Perfect change for me (once CI is green)
  13. Helmut Hummel uploaded patch set 3 V -1 12/20/22, 21:31

  14. Helmut Hummel commented on patch set 2 12/20/22, 21:31

    Reply

    Thanks! Fingers crossed ;)
  15. core-ci voted on patch set 3 V +1 12/20/22, 21:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/35249

  16. Benni Mack voted on patch set 3 CR +1 12/20/22, 22:18

  17. Markus Klein voted on patch set 3 CR +1 12/21/22, 11:57

  18. Daniel Goerz voted on patch set 3 CR +1 12/22/22, 10:45

  19. Guido Schmechel voted on patch set 3 CR +1 12/28/22, 15:31

  20. Benni Mack voted on patch set 3 V +1 12/28/22, 22:55

  21. Markus Klein voted on patch set 3 V +1 01/04/23, 10:50

  22. Helmut Hummel voted on patch set 3 V +2 CR +2 01/04/23, 13:53

  23. Helmut Hummel commented on patch set 3 01/04/23, 13:54

    Thanks a lot for your feedback and reviews!
  24. Helmut Hummel merged patch set 4 01/04/23, 13:54

  25. Benni Mack commented on patch set 4 03/16/23, 22:29

    This change introduced a regression, see here for the fix: https://review.typo3.org/c/Packages/TYPO3.CMS/+/78132