Review main Merged

78002[BUGFIX] Properly escalate if a form HMAC fails to decode

Thomas Hohn CR +2 V +2 Normal +52 −0 updated 11/10/23, 12:56

Commit message

If a HMAC cannot be `json_decode`d (possibly due to old
saved pages or other outdated content), now a proper exception
is thrown instead of issuing a PHP warning.

Review

  • Code review CR +2 Done
    • Benjamin Franzke +2
    • Oliver Klee +1
    • Garvin Hicking +1
    • Torben Hansen +1
  • Verified V +2 Done
    • Benjamin Franzke +2
    • Oliver Klee +1
    • Garvin Hicking +1
    • Torben Hansen +1
    • core-ci +1 CI

Issues 1

Files 3

Review log 4654

Show 2329 earlier messages
  1. Thomas Hohn uploaded patch set 1 03/02/23, 09:15

  2. core-ci voted on patch set 1 V +1 03/02/23, 09:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38295

  3. Oliver Klee voted on patch set 1 CR +1 03/02/23, 09:38

  4. Christian Kuhn commented on patch set 1 03/02/23, 17:13

    MvcPropertyMappingConfigurationService.php:142

    how can the hmac validate and then have invalid payload? valid hmac should (hopefully!) mean this is created server-side, so why can't this be decoded? we really need to be sure fixing a php warning here does not introduce a sec-issue (with warning it crashes, without warning it would say "valid"). so it would at least be good to understand how this scenario can happen at all, to then eventually fix at the generating side? i'm currently a bit reluctant to just +1 this without deeper insight ...
  5. Christian Kuhn commented on patch set 1 CR -1 03/02/23, 17:17

    MvcPropertyMappingConfigurationService.php:142 Reply

    actually, i'll -1 this for now - we need a satisfying answer on who/why a valid hmac'ed payload does not decode as expected.
  6. Nikita Hovratov uploaded patch set 2 CR +1 V +1 03/02/23, 17:33

  7. Nikita Hovratov commented on patch set 2 03/02/23, 17:36

    MvcPropertyMappingConfigurationService.php:142 Reply

    Hey, I just added another patchset with a test. You are right, finding the origin of the issue is important to understand better what is going on. The issue speaks of "attacks", so it looks like "__trustedProperties" are altered with.
  8. core-ci voted on patch set 2 V +1 03/02/23, 17:39 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38316

  9. Thomas Hohn commented on patch set 2 03/02/23, 17:53

    MvcPropertyMappingConfigurationService.php:142 Reply

    Maybe the correct behaviour would indeed be to throw an exception instead. If the encryptionKey has been exposed or reused for several sites I guess you would be able to come by the first checks and decoding the data could fail if the payload isn't correct?
  10. Thomas Hohn commented on patch set 2 03/02/23, 18:26

    MvcPropertyMappingConfigurationService.php:142 Reply

    I has asked for more information..
  11. Christian Kuhn voted on patch set 2 CR -1 03/02/23, 19:21

  12. Thomas Hohn rebased onto patch set 3 CR -1 V +1 03/06/23, 05:41

  13. core-ci voted on patch set 3 V +1 03/06/23, 05:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/38510

  14. Benni Mack updated the commit message in patch set 4 V +1 05/03/23, 09:33

  15. core-ci voted on patch set 4 V +1 05/03/23, 10:47 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/41429

  16. Oliver Klee commented on patch set 4 07/16/23, 08:34

    How should we continue here?
  17. Thomas Hohn commented on patch set 4 07/16/23, 16:32

    Reply

    We never received any feedback on the case. Based on the comment from @lolli - I suggest we abandon the patch and close the ticket
  18. Oliver Klee commented on patch set 4 07/17/23, 07:17

    Reply

    Yeah, makes sense. I'd still like to keep the new test, maybe in a separate change. What do you think, @Nikita?
  19. Benjamin Franzke commented on patch set 4 07/17/23, 08:51

    MvcPropertyMappingConfigurationService.php:142 Reply

    The issue was reported against TYPO3 v10, which uses json encoded trusted properties. TYPO3 v9 used (un)serialized content for extbase trusted properrties. In combination with stuff like config.sendCacheHeaders it is likely that warning occured after the update, when a (user)cached page has been visited that contained serialized trusted properties. json_decoding the output of unseralize leads to NULL, so I guess this is the most likely case how an "invalid" payload got signed. And yes, throwing an exception would be appropriate.
  20. Oliver Klee commented on patch set 4 07/17/23, 10:57

    MvcPropertyMappingConfigurationService.php:142 Reply

    I agree. Throwing an exception looks like the cleanest solution to me.
  21. Oliver Klee uploaded patch set 5 V +1 08/05/23, 20:32

  22. Oliver Klee commented on patch set 5 V +1 CR +1 08/05/23, 20:32

    MvcPropertyMappingConfigurationService.php:142 Reply

    Done
  23. Oliver Klee commented on patch set 5 08/05/23, 20:33

    Reply

    (Resolving as we now at least have a proper exception if the decoding fails.)
  24. core-ci voted on patch set 5 V +1 08/05/23, 20:44 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45127

  25. Torben Hansen uploaded patch set 6 CR +1 V +1 08/06/23, 17:26

  26. Torben Hansen commented on patch set 6 08/06/23, 17:29

    I updated the patch, so the new exception code is in IGNORED_EXCEPTION_CODES, since we do not want the sys_log to be filled with exceptions caused by scenarios, which are caused due to external modification or other behavior, a TYPO3 administrator has no influence on.
  27. Oliver Klee commented on patch set 6 V +1 CR +1 08/06/23, 17:29

    Thanks, Torben!
  28. core-ci voted on patch set 6 V +1 08/06/23, 17:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/45155

  29. Markus Klein voted on patch set 6 V +1 CR +1 09/22/23, 08:44

  1. Guido Schmechel voted on patch set 6 CR +1 09/28/23, 19:27

  2. Garvin Hicking commented on patch set 6 10/11/23, 13:56

    My personal gut feeling is to better gate/harden such a check, even if superflous, than to let it stand and follow function flow, if/when json_decode could fail. However, I'm not sure if there's a way to have a valid hmac with an empty trustedProperties string, which would be json_decoded to an empty response, and not an empty array, and thus halt the function flow. Other than that I added a note about whether the exception should be unique, or not (currently it's a bit of both).

    MvcPropertyMappingConfigurationService.php:147

    I'd suggest to either use the same Exception code AND description at this point (if it's about security, to not reveal to an attacker, that they have progressed on step further). OR to actually rename the content of the Exception, if it shall be unique, to something like "The HMAC of the form could not be utilized.", so that it can be better distinguished.
  3. Torben Hansen commented on patch set 6 10/11/23, 14:09

    MvcPropertyMappingConfigurationService.php:147 Reply

    Attacker will only see the exception code/message, if website runs in debug mode (which it should not). We should use different codes here, so it is clear from the log files, which error occurred.
  4. Garvin Hicking commented on patch set 6 10/11/23, 14:41

    MvcPropertyMappingConfigurationService.php:147 Reply

    Of course, you're right. I usually work in development so I forget that "normal people" don't see this ;-) However, if there's any chance that a developer will see this exception without malicious intent, it would help to make the error message unique, not only the exception code. To make it easier to google. Hey, maybe those people end up reading this review, Hi!
  5. Thomas Hohn uploaded patch set 7 CR +1 V +1 10/12/23, 04:03

  6. Thomas Hohn commented on patch set 7 10/12/23, 04:05

    MvcPropertyMappingConfigurationService.php:147 Reply

    Done
  7. core-ci voted on patch set 7 V +1 10/12/23, 04:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/47698

  8. Garvin Hicking voted on patch set 7 V +1 CR +1 10/12/23, 05:21

  9. Torben Hansen voted on patch set 7 V +1 CR +1 10/12/23, 06:05

  10. Oliver Klee voted on patch set 7 V +1 CR +1 10/12/23, 08:11

  11. Markus Klein voted on patch set 7 V +1 CR +1 10/12/23, 12:48

  12. Benjamin Franzke uploaded patch set 8 CR +1 V +1 11/10/23, 09:14

  13. Benjamin Franzke commented on patch set 8 11/10/23, 09:14

    MvcPropertyMappingConfigurationService.php:147 Reply

    Thanks Torben, but we only want the error to be log-skipped if it is actually old-data, not new-invalid-structure. I've added a heuristic to detect old serialized input.
  14. Benjamin Franzke voted on patch set 8 V +1 CR +1 11/10/23, 09:15

  15. core-ci voted on patch set 8 V +1 11/10/23, 09:21 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/48783

  16. Oliver Klee voted on patch set 8 V +1 CR +1 11/10/23, 09:33

  17. Torben Hansen voted on patch set 8 V +1 CR +1 11/10/23, 09:38

  18. Garvin Hicking voted on patch set 8 V +1 CR +1 11/10/23, 10:31

  19. Oliver Klee voted on patch set 8 V 0 CR 0 11/10/23, 12:04

  20. Oliver Klee commented on patch set 8 11/10/23, 12:05

    MvcPropertyMappingConfigurationService.php:147

    I think we also need to have an `is_string` check to avoid type errors if e.g., the trusted properties JSON fails to decode for some reason (which would result in `null`).
  21. Benjamin Franzke commented on patch set 8 11/10/23, 12:20

    MvcPropertyMappingConfigurationService.php:147 Reply

    `str_starts_with` is performed on `$encodedTrustedProperties`, not on the json result. That means it is guaranteed to be a `string` (that's the return type of `validateAndStripHmac()`)
  22. Benjamin Franzke voted on patch set 8 V +2 CR +2 11/10/23, 12:48

  23. Benjamin Franzke merged patch set 9 11/10/23, 12:48

  24. Oliver Klee commented on patch set 9 11/10/23, 12:56

    MvcPropertyMappingConfigurationService.php:147 Reply

    Ah, I see. Thanks!
  25. Oliver Klee commented on patch set 9 V +1 CR +1 11/10/23, 12:56

    (Post +1s)