Review main Merged

81945[FEATURE] Introduce ErrorHandler for 403 errors with redirect option

Torben Hansen CR +2 V +2 Normal +244 −0 updated 09/04/24, 11:56

Commit message

When TYPO3 is configured to create links to access protected pages
using `typolinkLinkAccessRestrictedPages = NONE` (which is default),
a 403 response is returned, if the current frontend request does not
fulfill configured access permissions.

This change introduces a new Site errorHandler, which can be used
to handle 403 responses for access restricted pages and which
redirects the user to a configured page and adds a configurable
GET parameter (`return_url` or `redirect_url`) containing the original
URL. The configurable GET parameter can be used by 3rd party extensions
to redirect the user back to the original URL after a successful
login.

The TYPO3 extensions ext:felogin and ext:oidc both support the
configurable redirect parameter introduced in the new Site
errorHandler feature.

Review

  • Code review CR +2 Done
    • Georg Ringer +2
    • Garvin Hicking +1
    • Markus Klein +1
  • Verified V +2 Done
    • Georg Ringer +2
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 1

Files 5

Review log 4257

Show 2132 earlier messages
  1. Torben Hansen uploaded patch set 1 11/23/23, 21:18

  2. core-ci voted on patch set 1 V -1 11/23/23, 21:23 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49823

  3. Torben Hansen uploaded patch set 2 V -1 11/24/23, 07:46

  4. core-ci voted on patch set 2 V -1 11/24/23, 07:53 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49832

  5. Torben Hansen uploaded patch set 3 V -1 11/24/23, 08:12

  6. core-ci voted on patch set 3 V +1 11/24/23, 08:18 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49834

  7. Torben Hansen rebased onto patch set 4 V +1 05/11/24, 10:10

  8. core-ci voted on patch set 4 V +1 05/11/24, 10:15 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/57516

  9. Torben Hansen uploaded patch set 5 V +1 05/11/24, 17:16

  10. Torben Hansen updated the commit message in patch set 6 05/11/24, 17:17

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

  12. core-ci voted on patch set 6 V +1 05/11/24, 17:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/57521

  13. Mathias Brodala commented on patch set 6 05/13/24, 09:22

    Feature-101252-IntroduceErrorHandlerFor403ErrorsWithRedirectOptionToExtfelogin.rst:14

    :php:`RedirectLoginErrorHandler` Also please add details and an example how to use it.
  14. Torben Hansen uploaded patch set 7 V +1 05/13/24, 12:52

  15. Torben Hansen commented on patch set 6 05/13/24, 12:52

    Feature-101252-IntroduceErrorHandlerFor403ErrorsWithRedirectOptionToExtfelogin.rst:14 Reply

    Done
  16. core-ci voted on patch set 7 V +1 05/13/24, 12:57 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/57621

  17. Garvin Hicking uploaded patch set 8 V +1 06/14/24, 07:34

    Minor spelling
  18. Garvin Hicking commented on patch set 8 06/14/24, 07:35

    Feature-101252-IntroduceErrorHandlerFor403ErrorsWithRedirectOptionToExtfelogin.rst:14 Reply

    Could you maybe more specifically write where/how this `loginRedirectPid` parameter would be set? It's attributed with ":php:" but I kind of believe this is a TypoScript parameter? Maybe having an example configuration/implementation code would clear this up...?
  19. Torben Hansen commented on patch set 8 06/14/24, 07:39

    Feature-101252-IntroduceErrorHandlerFor403ErrorsWithRedirectOptionToExtfelogin.rst:14 Reply

    The `loginRedirectPid` is configured in site settings, when the error handler is setup. Should I completely avoid using `loginRedirectPid` and just write "the configured page"?
  20. core-ci voted on patch set 8 V +1 06/14/24, 07:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59575

  21. Garvin Hicking commented on patch set 8 06/14/24, 10:31

    Feature-101252-IntroduceErrorHandlerFor403ErrorsWithRedirectOptionToExtfelogin.rst:14 Reply

    Ah, I see. Maybe then: When active, the :php:`RedirectLoginErrorHandler` redirects the user to the configured page (Site Settings, :php:`loginRedirectPid`) in case of a 403 error.
  22. Torben Hansen uploaded patch set 9 V +1 06/15/24, 12:26

  23. core-ci voted on patch set 9 V +1 06/15/24, 12:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/59643

  24. Torben Hansen commented on patch set 9 06/16/24, 04:34

    Feature-101252-IntroduceErrorHandlerFor403ErrorsWithRedirectOptionToExtfelogin.rst:14 Reply

    Done
  25. Torben Hansen uploaded patch set 10 V +1 07/07/24, 05:22

  26. core-ci voted on patch set 10 V +1 07/07/24, 05:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61132

  27. Georg Ringer voted on patch set 10 CR +1 V +1 07/07/24, 19:17

  28. Markus Klein commented on patch set 10 07/08/24, 10:25

    RedirectLoginErrorHandler.php:33

    I would rephrase to: ", where the ext:felogin plugin (or some other plugin handling the 'redirect_url`) ..."

    RedirectLoginErrorHandler.php:50

    that's not necessarily a pid here, it can by any valid TS syntax. so maybe `loginRedirectPid` is actually misleading
  29. Torben Hansen uploaded patch set 11 CR +1 V +1 07/08/24, 14:22

  30. Torben Hansen commented on patch set 10 07/08/24, 14:22

    RedirectLoginErrorHandler.php:33 Reply

    OK for me to change this here. But we also refer to ext:felogin in other places (e.g. error handler name), where this rephrasing does not fit UI-wise.

    RedirectLoginErrorHandler.php:50 Reply

    Changed to configuration name to `loginRedirectTarget`. The `loginRedirectPid` property is kept, since it is ensured this is always an page uid (int).
  31. core-ci voted on patch set 11 V +1 07/08/24, 14:29 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/61176

  32. Christian Kuhn commented on patch set 11 07/08/24, 14:42

    site_errorhandling.php:15

    are we sure this should be part of ext core/backend? it's kinda tailored for felogin, maybe felogin should shit it, or do you think that's not a good idea?
  1. Torben Hansen commented on patch set 11 07/08/24, 16:10

    site_errorhandling.php:15 Reply

    Thought about that too, but then you have to register the error handler as PHP Error handler (errorPhpClassFQCN configuration), where the user manually has to provide the error handler FQDN. Since this is not really user friendly, I decided against that integration. Maybe we could somehow extend `Site` object to support a more dynamic/user friendly custom error handling registration, but I currently have no idea how this could be archived.
  2. Markus Klein commented on patch set 11 07/09/24, 06:39

    site_errorhandling.php:15 Reply

    It's not really tailored for felogin. Consider ext:oidc. It's handling the redirect_url as well. And meanwhile we install ext:oidc nearly as often as felogin
  3. Torben Hansen commented on patch set 11 07/09/24, 11:09

    site_errorhandling.php:15 Reply

    So maybe we should rephrase all occurencees of "felogin" with something like you originally suggested (e.g. "a plugin which handles `return_url` GET parameter")? The error handler actually uses `return_url`, since this is evaluated before `redirect_url`)
  4. Torben Hansen uploaded patch set 12 V +1 08/06/24, 05:59

  5. Torben Hansen commented on patch set 12 08/06/24, 06:03

    site_errorhandling.php:15 Reply

    Changed the scope of this patch to not only ext:felogin, but to a general and configurable GET parameter (`return_url` and `redirect_url`). This can be used by 3rd party extensions to implement a custom login redirection process. Added to RST file, that ext:felogin and ext:oidc both support the configurable URL parameter.
  6. core-ci voted on patch set 12 V +1 08/06/24, 06:04 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/62874

  7. Garvin Hicking uploaded patch set 13 V +1 08/21/24, 11:04

    ReST update
  8. Garvin Hicking commented on patch set 13 CR +1 V +1 08/21/24, 11:06

    I just tested this and it works quite nicely, and would remove a lot of problematic custom ErrorHandler implementations I've seen in "the wild", or even more problematic, custom middlewares doing the redirects with a lot of extra mileage. (BTW: The ErrorHandler itself also works nicely in v11 and v12, we also tested it in a v11 instance)
  9. core-ci voted on patch set 13 V -1 08/21/24, 11:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63897

  10. Sandra Erbel commented on patch set 13 V +1 08/21/24, 11:28

    Garvin and me tested it in a v11.5 instance. But we used the RedirectLoginErrorHandler class not in terms of a `LoginRedirect` errorHandler but in terms of a custom `PHP` errorHandler in the error handling. We had to hard code the login pid, where to redirect, into the constructor: `$configuration = ['loginRedirectTarget' => 't3://page?uid=656', 'loginRedirectParameter' => 'return_url'];`. It was not possible to use settings.yaml (introduced with v12.1) in order to get the parameters from the site settings. As redirect mode we used `getpost`. We could omit all config settings like for example `typolinkLinkAccessRestrictedPages = ...`. But all in all it works fine. After a successful fe-login in the incognito window we were guided to the page we initially tried to get access to.
  11. Garvin Hicking commented on patch set 14 CR +1 V +1 08/21/24, 12:38

    Published edit on patch set 13.
  12. Garvin Hicking voted on patch set 14 CR +1 V +1 08/21/24, 12:38

  13. Sandra Erbel commented on patch set 14 08/21/24, 12:44

    Thanks for correcting the small typo.
  14. Sandra Erbel voted on patch set 14 V +1 08/21/24, 12:45

  15. core-ci voted on patch set 14 V +1 08/21/24, 12:48 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/63908

  16. Garvin Hicking commented on patch set 14 08/29/24, 14:30

    In the documentation patch for this (https://review.typo3.org/c/Packages/TYPO3.CMS/+/85817) the code review suggested to use final class here, and private properties, what do you think?
  17. Torben Hansen commented on patch set 14 08/29/24, 15:01

    Reply

    All other core PageErrorHandlers use protected properties and are not final. IMO we should not mix implementations (some classes of same implementation final and others not) and use the existing (non-final and protected properties). If this is really a topic for discussion, I suggest to contact a core merger to make a dicision on if we should make all PageErrorHandlers final and use private properties. I however think this is a breaking change and then something for v14.
  18. Garvin Hicking commented on patch set 14 08/29/24, 16:04

    Reply

    IMO your reasoning sounds good. I think for a custom code enhancement in the doc patch we could divert from that. To re-rail this: This patch still works well for the cases I tested.
  19. Markus Klein commented on patch set 14 09/03/24, 11:11

    RedirectLoginErrorHandler.php:42

    unused
  20. Markus Klein uploaded patch set 15 CR +1 V +1 09/03/24, 11:13

  21. Markus Klein commented on patch set 15 CR +1 09/03/24, 11:14

    RedirectLoginErrorHandler.php:42 Reply

    Done
  22. core-ci voted on patch set 15 V +1 09/03/24, 11:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/64660

  23. Garvin Hicking voted on patch set 15 CR +1 V +1 09/03/24, 12:20

  24. Georg Ringer voted on patch set 15 CR +2 V +2 09/04/24, 11:56

  25. Georg Ringer merged patch set 16 09/04/24, 11:56