Review main Merged

93047[TASK] Use HKDF for JWT key derivation

Benjamin Franzke CR +2 V +2 Normal +60 −19 updated 04/01/26, 12:26

Commit message

Use the designated "HMAC-based Extract-and-Expand Key Derivation
Function" (HKDF) [1] instead of `hash('sha256', …)` to derive the
JWT subkey from the TYPO3 encryption key.

Please note that there are no known (security) issues with sha256
hashes, but HKDF is perceived to provide better security, since it
was reviewed by security experts [1][2] and is therefore basically
the recommended choice. We switch to it to avoid having to switch
in case issues with the simpler hash arise, since switching
the derivation function revokes all issued tokens, which is ideally
to be avoided in a BUGFIX release.

[1] https://datatracker.ietf.org/doc/html/rfc5869
[2] https://crypto.stackexchange.com/a/13251

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Hannes Lau +1
    • Andreas Kienast +1
    • Oliver Hader +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Andreas Kienast +1
    • Oliver Hader +1
    • core-ci +1 CI

Issues 1

Files 4

Review log 1417

  1. Benjamin Franzke uploaded patch set 1 03/03/26, 19:33

  2. core-ci voted on patch set 1 V +1 03/03/26, 19:42 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/97218

  3. Benjamin Franzke wrote 03/04/26, 08:57

    Hashtag added: actions
  4. Hannes Lau voted on patch set 1 CR +1 03/30/26, 19:30

  5. Josef Glatz commented on patch set 1 CR -1 03/31/26, 04:02

    Why not using `hash_hkdf` with salt as stated in the official docs https://www.php.net/manual/en/function.hash-hkdf.php ? I'm not a security expert, so please take my comments with a grain of salt 😉
  6. Benjamin Franzke commented on patch set 1 03/31/26, 06:04

    Reply

    Because `salt` is meant to be random, and we have no *random* salt, which is why I decided to use the `$info` parameter (which is basically the subkey identifier instead), since I wanted to avoid adding non-random data to a parameter that is meant for random data. (because if something is supposed to be random and is not, that's a false "sense" of security) Of course I'd love to add some random salt, but that would need to be a permanently known one, and we don't have that. But this is for sure discussable, we'll see, thanks for you comment, it's good to talk this through :)
  7. Oliver Hader uploaded patch set 2 CR +1 V +1 03/31/26, 11:23

  8. Oliver Hader commented on patch set 2 CR +1 V +1 03/31/26, 11:34

    Reply

    Salt is an optional non-secret value (see https://datatracker.ietf.org/doc/html/rfc5869#section-2.2). If we would use that, it needs to be bundled to the JWT as well (somehow™). Thus, it's fine to omit it. Using HKDF is better than expanding the key by pure SHA256, since HKDF takes are of internal padding, separated secret and context and used HMAC internally). (HS256 in JWT internally uses HMAC as well on the provided key material - thus, the previous version was not insecure, but using HKDF for deriving secrets is definitively the better choice)
  9. Josef Glatz commented on patch set 2 03/31/26, 11:39

    Reply

    Acknowledged
  10. core-ci voted on patch set 2 V -1 03/31/26, 11:59 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/99253

  11. Benjamin Franzke uploaded patch set 3 CR +1 V +1 03/31/26, 16:40

  12. core-ci voted on patch set 3 V +1 03/31/26, 16:50 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/99297

  13. Oliver Hader voted on patch set 3 CR +1 V +1 03/31/26, 16:58

  14. Hannes Lau voted on patch set 3 CR +1 04/01/26, 09:18

  15. Andreas Kienast voted on patch set 3 CR +1 V +1 04/01/26, 12:26

  16. Benjamin Franzke voted on patch set 3 CR +2 V +2 04/01/26, 12:26

  17. Benjamin Franzke merged patch set 4 04/01/26, 12:26