Review main Merged

83947[BUGFIX] Use Guzzle request to fetch external error page content

Stefan Bürk CR +2 V +2 Normal +62 −0 updated 05/11/24, 17:31

Commit message

TYPO3 provides the ability to configure different error handlers for
specific (or all) error codes, as well as the error handler type
to use (core handler or custom).

The `\TYPO3\CMS\Core\Error\PageErrorHandler\PageContentErrorHandler`
allows to specify a target using the link handler. The default config
allows to define `LinkService::TYPE_PAGE` and `LinkService::TYPE_URL`.

After implementing and stabilizing the TYPO3 sub-request feature,
this particular error handler has been refactored to use an internal
sub-request to resolve the error page content: An external URL not
matching the same instance or having a page unavailable within
the TYPO3 instance will not return any content.

This change modifies the `PageContentErrorHandler` to send a Guzzle
request for an external URL instead of using internal sub-requests,
even if it would access the originating instance again. A limitation
is that the requested URL **must** return a HTTP status-code 200.

A custom request header is attached to this request. It is then
checked to avoid recurring errors or loops in the page-resolving
workflow.

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Thomas Hohn +1
    • Christian Kuhn +1
    • Benni Mack +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Christian Kuhn +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 3

Files 2

Review log 2026

Show 1 earlier messages
  1. Stefan Bürk uploaded patch set 1 04/21/24, 16:02

  1. Stefan Bürk updated the commit message in patch set 2 04/21/24, 16:03

  2. core-ci voted on patch set 1 V -1 04/21/24, 16:07 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56428

  3. core-ci voted on patch set 2 V -1 04/21/24, 16:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56429

  4. Stefan Bürk uploaded patch set 3 V -1 04/21/24, 16:15

  5. core-ci voted on patch set 3 V +1 04/21/24, 16:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56430

  6. Garvin Hicking updated the commit message in patch set 4 V +1 04/21/24, 18:02

  7. core-ci voted on patch set 4 V +1 04/21/24, 18:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56438

  8. Simon Schaufelberger commented on patch set 4 04/21/24, 18:27

    PageContentErrorHandler.php:152

    would it be better to use "Requested-By" here?

    PageContentErrorHandler.php:156

    2 spaces

    PageContentErrorHandler.php:165

    would it be better to use "Requested-By" here?

    PageContentErrorHandler.php:175

    above "Content-Type" is used. here lowercase.
  9. Stefan Bürk voted on patch set 4 CR -1 04/21/24, 19:18

  10. Stefan Bürk uploaded patch set 5 CR -1 V +1 04/21/24, 20:03

  11. core-ci voted on patch set 5 V +1 04/21/24, 20:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56440

  12. Stefan Bürk commented on patch set 5 04/21/24, 20:10

    PageContentErrorHandler.php:152 Reply

    TBH it's absolutly irrelevant, as header names are case-insensitive per RFC, see https://datatracker.ietf.org/doc/html/rfc7230#section-3.2 > Each header field consists of a case-insensitive field name followed by a colon (":"), optional leading whitespace, the field value, and optional trailing whitespace. Thus all clients, server, parser, tools, libs NOT handling request or response header name in a case-insensitive manner are broken by design. So, technically spoken we could using a randomizer for header name casings and it would still work. NOTE: Request/Response classes used by TYPO3, Guzzle and other libs uses internal lowercasing to handle the case-insenstive manner correctly. Personally, I prefer the all lower-case variant instead of a fancy, technically not relevant or required mixed case variant. However, adjusting it to match you preferences.

    PageContentErrorHandler.php:156 Reply

    Done

    PageContentErrorHandler.php:165 Reply

    see above

    PageContentErrorHandler.php:175 Reply

    See above - literally completly irrelevant. Still, adopting your preference.
  13. Simon Schaufelberger commented on patch set 5 CR +1 04/21/24, 20:18

    PageContentErrorHandler.php:175 Reply

    Please don't do things for "me" and "my preference". I just want to be "consistent" and don't do it here so and somewhere else different.
  14. Thomas Hohn voted on patch set 5 CR +1 04/23/24, 09:23

  15. Christian Kuhn uploaded patch set 6 CR +1 V +1 04/23/24, 12:30

  16. Christian Kuhn voted on patch set 6 CR +1 V +1 04/23/24, 12:31

  17. core-ci voted on patch set 6 V +1 04/23/24, 12:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/56574

  18. Thomas Hohn voted on patch set 6 CR +1 04/23/24, 12:37

  19. Benni Mack voted on patch set 6 CR +1 V +1 04/23/24, 21:25

  20. Stefan Bürk voted on patch set 6 CR +2 V +2 04/23/24, 22:16

  21. Stefan Bürk merged patch set 7 04/23/24, 22:23

  22. Benjamin Franzke commented on patch set 7 04/24/24, 07:18

    PageContentErrorHandler.php:96

    I think the subRequest code should be moved into a `sendInternalRequest()` method to match the `sendExternalRequest()` method. The code in `handlePageError` is right now mixed between being a dispatcher and direct (subrequest) logic.

    PageContentErrorHandler.php:153

    This doesn't work if the external error handler is another instance that is using TYPO3 itself (which should work, right? I mean that's what this function is about). The Requested-By Header needs some kind of instanceid (could be created with a a random number hmac'ed with the current system's encryption key).
  23. Benni Mack commented on patch set 7 04/24/24, 07:20

    PageContentErrorHandler.php:153 Reply

    I actually also had one more thing while lying in bed yesterday... one "could" link to a file. Should we just check for type === TYPE_PAGE only?
  24. Stefan Bürk commented on patch set 7 04/25/24, 01:02

    PageContentErrorHandler.php:96 Reply

    Good point. Will check and eventually push a follow up.

    PageContentErrorHandler.php:153 Reply

    @ben@bnf.dev I guess we could remove the requested-by path and avoid introducing something like a instance id. If the configured external url is hitting the same instance, and it is the same site config which matches - then it is already coverd in https://review.typo3.org/c/Packages/TYPO3.CMS/+/83947/7/typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php#84L - or if it is another siteconfig with the same external url. If it is a other instance or another matching site config, and again hitting another external error page, I guess the execution should happen. A instance id should not make a difference here - or am I wrong ? @benni@typo3.org You mean if someone enters just a relative path/file in the field OR changing the siteconfig tca to allow additional link handlers ? In latter case I argue that if someone is reconfiguring this, a custom error handler should be implemented along the way. For the first case - good question. If it is of type file, we could just retrieve the file content directly ? instead of a internal request or a external request aka "file content error handler". Maybe these should be dedicated error handlers and do some mixing in this one with a direct deprecation of external url / file handling ?
  25. Stefan Bürk commented on patch set 7 05/11/24, 17:31

    PageContentErrorHandler.php:96 Reply

    PageContentErrorHandler.php:153 Reply

    @ben@bnf.dev See https://review.typo3.org/c/Packages/TYPO3.CMS/+/84191, removed the check again. @benni@typo3.org see https://review.typo3.org/c/Packages/TYPO3.CMS/+/84191, moved the intern request into a dedicated method and introduced a type check with fallback to generic html response for unsupported link types.