Review main Merged Breaking

69337[!!!][TASK] Send user session cookies as hash-signed JWT

Oliver Hader CR +2 V +2 Normal +145 −12 updated 10/03/22, 19:28

Commit message

Several performance analysis showed that `AbstractUserAuthentication`
takes a reasonable amount of processing time, even if a session ID
are not given or invalid. In order to reduce database invocations
for invalid sessions, user session cookies are sent as hash-signed
JWT - which allows to check their validity without invoking storages.

Required typo3/testing-framework preparation has been merged with
https://github.com/TYPO3/testing-framework/pull/365 and updated.

Custom implementations, handling cookies on their own, have to use the
introduced method \TYPO3\CMS\Core\Session\UserSession::getJwt() instead
of existing \TYPO3\CMS\Core\Session\UserSession::getIdentifier().

Review

  • Code review CR +2 Done
    • Oliver Hader +2
    • Kevin Appelt +1
    • Stefan Bürk +1
    • Christian Kuhn +1
  • Verified V +2 Done
    • Oliver Hader +2
    • Stefan Bürk +1
    • Christian Kuhn +1
    • core-ci +1 CI

Issues 1

Files 8

Review log 6181

Show 4156 earlier messages
  1. Oliver Hader uploaded patch set 1 05/31/21, 13:33

  2. core-ci voted on patch set 1 V -1 05/31/21, 13:47 Core CI is not happy: https://gitlab.typo3.org/TYPO3/CI/cms/-/pipelines/12039

  3. Oliver Hader commented on patch set 1 05/31/21, 14:05

  4. Oliver Hader marked it work in progress 11/18/21, 10:48

  5. Benni Mack wrote 11/29/21, 10:16

    Change destination moved from master to main
  6. Benni Mack updated the commit message in patch set 2 11/29/21, 14:02

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

  8. Oliver Hader rebased onto patch set 3 03/25/22, 13:53

  9. Oliver Hader commented on patch set 3 03/25/22, 13:56

    Testing framework is failing currently due to the missing session-id signature
  10. core-ci voted on patch set 3 V -1 03/25/22, 14:06 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/25140

  11. Oliver Hader uploaded patch set 4 05/06/22, 09:01

  12. core-ci voted on patch set 4 V -1 05/06/22, 09:13 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26894

  13. Oliver Hader uploaded patch set 5 05/06/22, 10:07

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

  15. core-ci commented on patch set 5 05/06/22, 10:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26899

  16. core-ci commented on patch set 5 05/06/22, 10:40 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26899

  17. core-ci commented on patch set 5 05/06/22, 10:48 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26899

  18. Oliver Hader uploaded patch set 6 05/06/22, 11:23

  19. core-ci voted on patch set 6 V +1 05/06/22, 11:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26904

  20. Mathias Brodala commented on patch set 6 05/06/22, 12:41

    JwtTrait.php:27

    Should we throw an error instead? I could imagine that this silent fallback affects security.
  21. Oliver Hader commented on patch set 6 05/06/22, 12:57

    JwtTrait.php:27 Reply

    There's a check during the bootstrap, I guess that's enough... https://github.com/TYPO3/typo3/blob/14cbf0f76778a0253d347fd847d6cfc1d8e709f1/typo3/sysext/core/Classes/Core/Bootstrap.php#L470-L478 But it means, the fallback can be removed...
  22. Mathias Brodala commented on patch set 6 05/06/22, 12:58

    JwtTrait.php:27 Reply

    Basically yes but PHPStan or similar may complain about this. ;-)
  23. Oliver Hader uploaded patch set 7 05/06/22, 12:59

  24. core-ci voted on patch set 7 V -1 05/06/22, 13:08 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26913

  25. Oliver Hader commented on patch set 7 05/06/22, 13:12

    This change is ready for review.
  26. core-ci voted on patch set 7 V +1 05/06/22, 13:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/26913

  27. Stefan Bürk commented on patch set 7 05/07/22, 13:05

    Would suggest to leave "[WIP]" here until TF is mergend and fork removed/tf update added.
    Would this not be a "breaking task backport" into LTS version ?

    composer.json:43

    Patch should be marked as "[WIP]" as long as the fork is used. Additionally patch can be only merged after corresponding TF change is properly merged into corresponding TF branches AND raised in core versions (main/11) - see comment in TF draft pull-request.

    composer.json:64

    Code makes this extension mandantory. So this *must* be added to `typo3/sysext/core/composer.json`. This however will introduce a new required dependency to a LTS version - was this on the screen and decided as valid to introduce ?
  28. Oliver Klee commented on patch set 7 05/07/22, 13:22

    JwtTrait.php:27

    Just to be safe for incomplete installations, we should use ?? for the array access.
  29. Oliver Klee commented on patch set 7 05/07/22, 14:10

    UserSession.php:285

    Do we expect cases where the cookie has no value (or an empty value), and we could improve performance to catch this early before trying to decode it?
  30. Mathias Brodala commented on patch set 7 05/09/22, 07:04

    Reply

    Or switch back to WIP on Gerrit. No need for the [WIP] workaround.
  31. Oliver Hader commented on patch set 7 05/09/22, 07:39

    Reply

    Ack

    Reply

    Actually I don't know whether there are extensions that fiddle around with the cookie handling in AbstractUserAuthentication, but the possibility exists. I'd be fine with taking that into `main` only or use a feature flag for LTS branches.

    composer.json:43 Reply

    Yes, thing this is, that not many people review patches that are "WIP" - however, I'd like to have that feedback and reviews.

    composer.json:64 Reply

    See my recent comment above (in commit message). There's no other possibility than introducing a new package dependency in order to make use of its features. What kind of problems would you expect for v11 LTS in this particular case?

    JwtTrait.php:27 Reply

    UserSession.php:285 Reply

    Good one, empty cookie-values can be filtered out
  32. Oliver Hader marked it work in progress 05/09/22, 07:39

  33. Oliver Klee commented on patch set 7 05/09/22, 09:22

    JwtTrait.php:27 Reply

    Ack
  34. Oliver Hader uploaded patch set 8 05/09/22, 12:07

  35. Oliver Hader commented on patch set 8 05/09/22, 12:09

    This change is ready for review.

    Reply

    I'm giving up 11.5 for the time being, I just cannot oversee possible implications.

    composer.json:43 Reply

    Done

    composer.json:64 Reply

    Used `^5.5 || ^6.0` now

    UserSession.php:285 Reply

    Done
  36. core-ci voted on patch set 8 V +1 05/09/22, 12:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27024

  37. Oliver Klee commented on patch set 8 05/09/22, 13:09

    JwtTrait.php:23

    Please add a short explanation about what this trait does. And should it be @internal?

    UserSession.php:225

    If the return value is guaranteed to be non-empty, we can make this more specific to help static code analysis: @return non-empty-string
  38. Oliver Klee commented on patch set 8 CR -1 05/09/22, 15:26

    composer.json:39

    I think we need to mark the changeset as WIP as long as this snippet is here to keep people from merging this prematurely.

    JwtTrait.php:31

    Please add a PHPDoc with a more specific annotation for $payload.

    UserSessionManagerTest.php:182

    Why do we need a logger Prophecy-stub here? Wouldn't the (real) NullLogger suffice?
  39. Oliver Hader commented on patch set 8 06/01/22, 13:36

    composer.json:39 Reply

    Chicken-egg problem... nobody looks into changes that did not pass CI-run or are marked WIP. But yeah it's obvious this has to be adjusted before actually merging it.

    JwtTrait.php:31 Reply

    "more specific" in terms of "types"?

    UserSessionManagerTest.php:182 Reply

    Because of `class UserSessionManager implements LoggerAwareInterface`
  40. Oliver Klee commented on patch set 8 06/01/22, 13:43

    JwtTrait.php:31 Reply

    Yes. (This will help both human readers as well as allow PHPStan to do more specific static analysis.)
  41. Oliver Klee commented on patch set 8 06/01/22, 13:44

    composer.json:39 Reply

    Ack
  42. Oliver Hader commented on patch set 8 06/01/22, 13:49

    UserSessionManagerTest.php:182 Reply

    I misread the question - yes, `NullLogger` instance can be used directly here... the stub stems from an older version of this change that aimed to assert `debug` method would be invoked.
  43. Oliver Hader uploaded patch set 9 06/01/22, 14:01

  44. Oliver Hader commented on patch set 9 06/01/22, 14:01

    JwtTrait.php:31 Reply

    Done

    UserSessionManagerTest.php:182 Reply

    Done
  45. core-ci voted on patch set 9 V -1 06/01/22, 14:14 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/27623

  46. Oliver Klee commented on patch set 9 09/25/22, 18:31

    Is there any chance to get this into 12LTS?

    composer.json:58

    If this is main-only now, we use the latest ^6.3.0 directly.
  47. Oliver Hader commented on patch set 9 09/26/22, 08:34

    Reply

    https://review.typo3.org/c/Packages/TYPO3.CMS/+/74183 should be tackled first (and covers those JWT topics)... Cookie signing is also deadlocked by testing-framework...
  48. Georg Ringer commented on patch set 9 10/01/22, 20:02

    Reply

    merged now
  49. Oliver Hader uploaded patch set 10 10/03/22, 08:47

  50. Markus Klein commented on patch set 10 CR +1 10/03/22, 08:55

    Very lovely. Thank you!
  51. core-ci voted on patch set 10 V -1 10/03/22, 09:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31930

  52. Oliver Hader uploaded patch set 11 10/03/22, 09:20

  53. Oliver Hader commented on patch set 11 10/03/22, 09:32

    composer.json:58 Reply

    Irrelevant for the latest state of this change

    JwtTrait.php:23 Reply

    Irrelevant for this change

    UserSession.php:225 Reply

    I did not manage to do this without having to create a cascade of changes, due to `should return non-empty-string but returns string` in the whole call-hierarchy. Skipped for this patch.
  54. core-ci voted on patch set 11 V -1 10/03/22, 09:33 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31931

  55. Oliver Hader uploaded patch set 12 10/03/22, 09:50

  56. Oliver Hader uploaded patch set 13 10/03/22, 09:56

  1. core-ci voted on patch set 12 V -1 10/03/22, 10:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31933

  2. core-ci voted on patch set 13 V +1 10/03/22, 10:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31934

  3. Benni Mack voted on patch set 13 CR +1 10/03/22, 17:58

  4. Georg Ringer voted on patch set 13 CR +1 10/03/22, 18:48

  5. Stefan Bürk uploaded patch set 14 10/03/22, 18:53

  6. Stefan Bürk voted on patch set 14 V +1 CR +1 10/03/22, 18:58

  7. Christian Kuhn voted on patch set 14 V +1 CR +1 10/03/22, 19:00

  8. Georg Ringer voted on patch set 14 CR +1 10/03/22, 19:00

  9. core-ci voted on patch set 14 V +1 10/03/22, 19:02 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31954

  10. Georg Ringer commented on patch set 14 CR -1 10/03/22, 19:02

    Breaking-94243-SendUserSessionCookiesAsHash-signedJWT.rst:42

    I guess there is something missing
  11. Oliver Hader commented on patch set 15 10/03/22, 19:06

    Published edit on patch set 14.
  12. Oliver Hader commented on patch set 15 10/03/22, 19:06

    Breaking-94243-SendUserSessionCookiesAsHash-signedJWT.rst:42 Reply

    Done
  13. Christian Kuhn uploaded patch set 16 10/03/22, 19:07

  14. Christian Kuhn commented on patch set 14 V +1 CR +1 10/03/22, 19:07

    Breaking-94243-SendUserSessionCookiesAsHash-signedJWT.rst:42 Reply

    Done
  15. Christian Kuhn voted on patch set 16 V +1 CR +1 10/03/22, 19:07

  16. Stefan Bürk voted on patch set 16 V +1 CR +1 10/03/22, 19:07

  17. Christian Kuhn commented on patch set 16 10/03/22, 19:09

    sorry oli, seems we pushed the same thing in the same minute.
  18. core-ci voted on patch set 16 V +1 10/03/22, 19:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31956

  19. Kevin Appelt voted on patch set 16 CR +1 10/03/22, 19:17

  20. core-ci voted on patch set 15 V +1 10/03/22, 19:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/31955

  21. Oliver Hader commented on patch set 16 CR +1 10/03/22, 19:21

    Fine for me. Any other objections?
  22. Christian Kuhn commented on patch set 16 10/03/22, 19:22

    Reply

    go ahead.
  23. Oliver Hader voted on patch set 16 V +2 CR +2 10/03/22, 19:27

  24. Oliver Hader merged patch set 17 10/03/22, 19:27

  25. Oliver Hader commented on patch set 17 10/03/22, 19:28

    Thanks folks ❤️