Review main Merged Breaking

74183[!!!][FEATURE] Introduce CSRF-like request-token handling

Oliver Hader CR +2 V +2 Expert +1846 −9 updated 09/29/22, 11:54

Commit message

A CSRF-like request-token handling has been introduced, to
mitigate potential cross-site requests on actions with side-effects.
This approach does not require an existing server-side user session,
but uses a nonce (number used once) as a "pre-session". The main scope
is to ensure a user actually has visited a page, before submitting
data to the web server.

Introduces package https://packagist.org/packages/firebase/php-jwt
> composer req firebase/php-jwt

Besides that, AbstractUserAuthentication has been changed to require
this introduced request-token, to mitigate Login CSRF attacks.

The security enhancement potentially break custom login templates
and application handlers - this is why it is introduced and enforced
for TYPO3 v12.0.

Review

  • Code review CR +2 Done
    • Oliver Hader +2
    • Torben Hansen +1
    • Stefan Bürk +1
    • Benni Mack +1
  • Verified V +2 Done
    • Oliver Hader +2
    • Torben Hansen +1
    • Stefan Bürk +1
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 30

Show 10 more files

Review log 6299

Show 4274 earlier messages
  1. Oliver Hader uploaded patch set 1 04/05/22, 15:41

  2. core-ci voted on patch set 1 V -1 04/05/22, 15:57 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/25533

  3. Oliver Hader uploaded patch set 2 05/05/22, 20:19

  4. core-ci voted on patch set 2 V -1 05/05/22, 20:35 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26886

  5. Oliver Hader uploaded patch set 3 05/05/22, 21:14

  6. Oliver Hader uploaded patch set 4 05/05/22, 21:20

  7. core-ci voted on patch set 3 V -1 05/05/22, 21:26 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26887

  8. core-ci voted on patch set 4 V -1 05/05/22, 21:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26888

  9. Oliver Hader uploaded patch set 5 05/06/22, 07:02

  10. core-ci voted on patch set 5 V -1 05/06/22, 07:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26892

  11. Oliver Hader uploaded patch set 6 09/24/22, 10:01

  12. core-ci voted on patch set 6 V -1 09/24/22, 10:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31499

  13. Oliver Hader uploaded patch set 7 09/24/22, 14:24

  14. core-ci voted on patch set 7 V -1 09/24/22, 14:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31502

  15. Oliver Hader uploaded patch set 8 09/25/22, 11:43

  16. core-ci voted on patch set 8 V -1 09/25/22, 11:56 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31513

  17. Oliver Hader uploaded patch set 9 09/25/22, 12:18

  18. core-ci voted on patch set 9 V -1 09/25/22, 12:26 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31514

  19. Oliver Hader commented on patch set 9 09/25/22, 12:37

  20. Simon Schaufelberger commented on patch set 9 09/25/22, 13:01

    Breaking-97305-IntroduceCSRF-likeLoginToken.rst:71

    linking between rest files should be done with the identifier in the top of every file.
  21. Chris Müller uploaded patch set 10 09/25/22, 14:22

  22. Chris Müller commented on patch set 10 09/25/22, 14:22

    Breaking-97305-IntroduceCSRF-likeLoginToken.rst:71 Reply

    Done
  23. core-ci voted on patch set 10 V -1 09/25/22, 14:29 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31515

  24. Chris Müller uploaded patch set 11 09/25/22, 16:31

  25. core-ci voted on patch set 11 V -1 09/25/22, 16:39 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31516

  26. Chris Müller uploaded patch set 12 09/25/22, 17:20

  27. core-ci voted on patch set 12 V -1 09/25/22, 17:29 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31517

  28. Oliver Hader uploaded patch set 13 09/26/22, 06:31

  29. core-ci voted on patch set 13 V -1 09/26/22, 06:38 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31525

  30. Oliver Hader uploaded patch set 14 09/26/22, 06:40

  31. core-ci voted on patch set 14 V -1 09/26/22, 06:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31526

  32. Oliver Hader uploaded patch set 15 09/26/22, 08:28

  33. core-ci voted on patch set 15 V +1 09/26/22, 08:38 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31529

  34. Oliver Hader uploaded patch set 16 09/26/22, 09:47

  35. core-ci voted on patch set 16 V +1 09/26/22, 09:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31532

  36. Oliver Hader uploaded patch set 17 09/26/22, 10:32

  37. core-ci voted on patch set 17 V +1 09/26/22, 10:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31534

  38. Oliver Hader uploaded patch set 18 09/26/22, 14:46

  39. core-ci voted on patch set 18 V -1 09/26/22, 14:55 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31541

  40. Oliver Hader uploaded patch set 19 09/26/22, 15:01

  41. Oliver Hader commented on patch set 19 09/26/22, 15:08

    RequestToken.php:89

    Ooooh, this actually currently reveals the secret nonce (as b64).
  42. core-ci voted on patch set 19 V +1 09/26/22, 15:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31542

  43. Oliver Hader uploaded patch set 20 09/26/22, 15:31

  44. core-ci voted on patch set 20 V -1 09/26/22, 15:41 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31546

  45. Oliver Hader uploaded patch set 21 09/26/22, 16:32

  46. core-ci voted on patch set 21 V +1 09/26/22, 16:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31547

  47. Oliver Hader uploaded patch set 22 09/26/22, 19:21

  48. Oliver Hader uploaded patch set 23 09/26/22, 19:24

  49. core-ci voted on patch set 22 V -1 09/26/22, 19:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31551

  50. core-ci voted on patch set 22 V -1 09/26/22, 19:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31551

  51. core-ci voted on patch set 23 V -1 09/26/22, 19:29 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31552

  52. Oliver Hader uploaded patch set 24 09/26/22, 19:33

  53. Oliver Hader commented on patch set 24 09/26/22, 19:35

    RequestToken.php:89 Reply

    Done
  54. core-ci voted on patch set 24 V +1 09/26/22, 19:41 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31554

  55. Oliver Hader commented on patch set 24 09/26/22, 19:42

    This change is ready for review.
  56. Stefan Bürk commented on patch set 24 09/27/22, 02:57

    Started a nightly on this, after failed "main nightlies": https://git.typo3.org/typo3/CI/cms/-/pipelines/31558
  57. core-ci voted on patch set 24 V -1 09/27/22, 03:24 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31558

  58. Oliver Hader commented on patch set 24 09/27/22, 05:39

    Reply

    Fails in "Change inline1n inline input" which seems to be very unrelated... I just restarted the failed jobs, since I could not spot any errors in the artifact files.
  59. core-ci voted on patch set 24 V +1 09/27/22, 05:43 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31558

  60. Oliver Hader commented on patch set 24 09/27/22, 05:43

    Reply

    Nightlies are green now
  61. Oliver Hader uploaded patch set 25 09/27/22, 07:25

  62. core-ci voted on patch set 25 V +1 09/27/22, 07:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31565

  63. Benni Mack commented on patch set 25 CR -1 09/27/22, 13:46

    The changes of composer.json also needs to be added to typo3/sysext/core/composer.json
  64. Chris Müller uploaded patch set 26 09/27/22, 16:57

  65. Oliver Hader commented on patch set 26 CR -2 09/27/22, 17:00

    What happened to patchset 26?
  66. Oliver Hader uploaded patch set 27 09/27/22, 17:05

  67. Oliver Hader commented on patch set 27 CR 0 09/27/22, 17:06

    I restored patchset 26, adjusted core/composer.json and added test-case for NoncePool
  68. Oliver Hader uploaded patch set 28 09/27/22, 17:08

  69. core-ci voted on patch set 26 V -1 09/27/22, 17:13 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31605

  70. core-ci voted on patch set 28 V +1 09/27/22, 17:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31608

  71. Oliver Hader uploaded patch set 29 09/27/22, 17:19

  72. core-ci voted on patch set 27 V +1 09/27/22, 17:20 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31607

  73. core-ci voted on patch set 29 V +1 09/27/22, 17:27 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31610

  74. Benni Mack commented on patch set 29 09/27/22, 19:10

    should we name it CSRFToken instead of RequestToken? I think most devs understand CSRF more than the generic Request Token

    RequestTokenMiddleware.php:76

    use $normalizedParams instead.

    RequestTokenMiddleware.php:123

    can use normalizedParams from $request instead.

    FormViewHelper.php:181

    should this only be added with method="POST" or should we throw an exception that a nonce is not allowed in combination with GET?
  1. Oliver Hader commented on patch set 29 09/27/22, 20:26

    Reply

    I'd go with `csrf={token}` in Fluid (like in Laravel) and for the class name `CsrfToken`. Fine?

    RequestTokenMiddleware.php:76 Reply

    Ack

    RequestTokenMiddleware.php:123 Reply

    Ack

    FormViewHelper.php:181 Reply

    This is checked in that particular method body, currently it's ``` if (strtolower((string)($this->arguments['method'] ?? '')) === 'get') { throw new \LogicException('Cannot apply request token for forms sent via HTTP GET', 1651775963); } ```
  2. Oliver Hader uploaded patch set 30 09/28/22, 07:00

  3. Oliver Hader rebased onto patch set 31 09/28/22, 07:00

  4. Oliver Hader commented on patch set 31 09/28/22, 07:07

    Reply

    I was half way through renaming variables and classes, then I discovered the term "RequestToken" being used with backend deep-linking, e.g. "MissingRequestTokenException". I'd prefer "RequestToken", otherwise we'd have a bunch of terms for similar concepts: * RequestToken * CSRF/CsrfToken * FormProtectionToken and just $token (and we actually use it most times in URIs, but not in Forms)

    RequestTokenMiddleware.php:76 Reply

    Done

    RequestTokenMiddleware.php:123 Reply

    Done

    FormViewHelper.php:181 Reply

    Done
  5. core-ci voted on patch set 30 V -1 09/28/22, 07:17 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31633

  6. core-ci voted on patch set 31 V -1 09/28/22, 07:17 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31634

  7. core-ci commented on patch set 31 09/28/22, 07:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31634

  8. Oliver Hader commented on patch set 31 09/28/22, 08:41

    RequestTokenMiddleware.php:148

    Idiot!
  9. Oliver Hader uploaded patch set 32 09/28/22, 08:41

  10. Oliver Hader commented on patch set 32 09/28/22, 08:43

    RequestTokenMiddleware.php:148 Reply

    Done
  11. core-ci voted on patch set 32 V +1 09/28/22, 08:49 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31638

  12. Benni Mack commented on patch set 32 09/28/22, 10:41

    RequestTokenMiddleware.php:125

    $normalizedParams please
  13. Benni Mack uploaded patch set 33 09/28/22, 13:28

  14. Benni Mack commented on patch set 33 CR +1 09/28/22, 13:29

    RequestTokenMiddleware.php:125 Reply

    Done
  15. Benni Mack voted on patch set 33 V +1 09/28/22, 13:30

  16. core-ci voted on patch set 33 V +1 09/28/22, 13:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31655

  17. Stefan Bürk commented on patch set 33 09/28/22, 14:07

    I'm late to the party - but have one question. See comment.

    SecurityAspect.php:35

    Do we really need this multi type declation ? If we add a "valid" flag to RequestToken, we can avoid these multitype declarations for the property and the setter/getter below. ``` $noToken = $securtyAspect->get('receivedRequestToken') === null; $tokenValid = ($securtyAspect->get('receivedRequestToken')?->isValid() ?? false); $tokenState = ($securtyAspect->get('receivedRequestToken')?->isValid() ?? null); if ($tokenState === null) { // no token provided } elseif ($tokenState === false) { // token provided, but invalid } else { // token valid } ``` What do you think ?
  18. Oliver Hader commented on patch set 33 09/28/22, 20:08

    SecurityAspect.php:35 Reply

    Having a `RequestToken::$valid` would violate the the requirement of this domain object (if there's an instance, it is complete and valid). Having an instance that is invalid requires any consumer to verify again (and again) that a particular object is valid. I personally don't see a problem in union types - which is a specific class-type and two distinct native types in this case. In case the `bool` type shall be avoided, there would be the possibility of having an explicit type for this as well. ``` interface RequestTokenInterface {} class RequestToken implements RequestTokenInterface {} class InvalidRequestToken implements RequestTokenInterface {} class SecurityAspect { protected ?RequestTokenInterface $receivedRequestToken = null; } ``` This way consumers cannot continue with a `InvalidRequestToken` since the type in signatures would be `RequestToken`. Thus, `$requestToken instanceof RequestToken` would be needed as well - like now...
  19. Stefan Bürk commented on patch set 33 V +1 CR +1 09/28/22, 20:43

    SecurityAspect.php:35 Reply

    Don't like these kind of mixed type, but this should not be about personal taste. Anyway ... ack, the InvalidRequestToken extend is not that nice either. Instead a "RequestTokenResult/State" wrapper class may be more usefull .. with methods etc. Maybe something we may discuss in general some day. Let's keep it as is.
  20. Oliver Hader commented on patch set 33 09/28/22, 21:14

    SecurityAspect.php:35 Reply

    Ack!
  21. Torben Hansen commented on patch set 33 V +1 CR +1 09/29/22, 06:43

    SecurityAspect.php:32

    Typo: "taken" -> "token"

    RequestToken.php:54

    We should move this into the try/catch and then catch the `Firebase\JWT\DomainException` and throw a `RequestTokenException` instead (which just will be logged). In the current state, a `Firebase\JWT\DomainException` is thrown, when a random string is provided as request token (might occur, when a remote user fiddles around with the `__RequestToken` parameter and JSON is malformed)
  22. Oliver Hader commented on patch set 33 V +2 CR +2 09/29/22, 11:25

    Going to tackle Torben's comments in a separate commit...
  23. Oliver Hader merged patch set 34 09/29/22, 11:25

  24. Oliver Hader commented on patch set 34 09/29/22, 11:54

  25. Oliver Hader commented on patch set 34 09/29/22, 11:54

    SecurityAspect.php:32 Reply

    Done

    RequestToken.php:54 Reply

    Done