Review main Merged

70404[BUGFIX] Adjust default behavior of HTML sanitization in parseFunc

Kevin Appelt CR +2 V +2 Expert +889 −533 updated 08/16/21, 11:21

Commit message

As a result of TYPO3-CORE-SA-2021-013, new `htmlSanitize` behavior -
when invoking `ContentObjectRenderer::parseFunc` - is enabled per
default, in case it was not declared otherwise. That also happened
when no processing configuration was given (or could be resolved).
Without having any configuration, it was obviously not possible to
disable `htmlSanitize`.

Fluid's `HtmlViewHelper` can be used with an empty `parseFuncTSPath`
(e.g. `<f:format.html parseFuncTSPath="">`) - due to missing (empty)
configuration, sanitization was enabled per default in `parseFunc`.

With this change, property `htmlSanitize` either needs to be enabled
or disabled explicitly - otherwise deprecation logs will be generated,
if not given, the fall-back behavior is inferred from new feature flag
`security.frontend.htmlSanitizeParseFuncDefault`.

Invoking `ContentObjectRenderer::parseFunc` without any configuration
behaves like before TYPO3-CORE-SA-2021-013 was applied - it just does
not process anything.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Helmut Hummel +1
  • Verified V +2 Done
    • Benni Mack +2
    • Helmut Hummel +1
    • core-ci +1 CI

Issues 1

Files 12

Review log 2028

Show 23 earlier messages
  1. Kevin Appelt uploaded patch set 1 08/10/21, 16:33

  2. core-ci voted on patch set 1 V +1 08/10/21, 16:46 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/14497

  3. Kevin Appelt marked it work in progress 08/10/21, 17:07

  1. Kevin Appelt marked it ready for review 08/10/21, 17:09

  2. Kevin Appelt uploaded patch set 2 08/10/21, 17:13

  3. core-ci voted on patch set 2 V -1 08/10/21, 17:15 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/14501

  4. Tomas Norre Mikkelsen commented on patch set 2 08/11/21, 12:12

    I know it's still work in progress, but I have tried it out on a TYPO3 8.7.42 ELTS version and that is giving me the same errors as before. I'll dig more into this. Let me know if you need feedback on testing. I have 7 ELTS, 8 ELTS and TYPO3 10 installations with problems that might be solved by this.
  5. Oliver Hader uploaded patch set 3 08/12/21, 20:38

  6. core-ci voted on patch set 3 V -1 08/12/21, 20:42 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/14852

  7. Oliver Hader commented on patch set 3 08/12/21, 20:43

    Reply

    The previous patch-set (PS 2) and the current one (PS 3) just relaxed the default behavior with using `stdWrap.parseFunc` directly via TypoScript. When wrapping content in `<f:format.html>` the default behavior is still the same. However, sanitization can now be disabled using ``<f:format.html htmlSanitize="0">` - which was not possible before via that Fluid view-helper - even `parseFuncTSPath=""` (empty value) again triggered the default behavior in `parseFunc`.
  8. Oliver Hader uploaded patch set 4 08/12/21, 20:46

  9. Markus Klein updated the commit message in patch set 5 08/12/21, 20:50

  10. core-ci voted on patch set 4 V -1 08/12/21, 21:08 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/14854

  11. core-ci voted on patch set 5 V -1 08/12/21, 21:22 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/14855

  12. Oliver Hader uploaded patch set 6 08/13/21, 05:55

  13. core-ci voted on patch set 6 V -1 08/13/21, 06:23 Core CI is not happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/14878

  14. Oliver Hader uploaded patch set 7 08/13/21, 07:23

  15. core-ci voted on patch set 7 V +1 08/13/21, 07:41 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/14886

  16. Helmut Hummel commented on patch set 7 CR +1 08/14/21, 08:55

    From what I understand, this change does what it advertises to do

    HtmlViewHelper.php:115

    Fluid populates the arguments with default values if not provided, so the null check here is obsolete

    SecureHtmlRenderingTest.php:183

    I must be missing something here, but this expectation does not seem to avoid XSS
  17. Oliver Hader commented on patch set 7 08/14/21, 09:00

    HtmlViewHelper.php:115 Reply

    Ack

    SecureHtmlRenderingTest.php:183 Reply Unresolved

    Correctly, due to `htmlSanitize` not being enabled per default anymore. This test case is just here, to explicitly "document" the behavior. The reason is, that `$this->createTextContentObjectWithCustomParseFunc` (see below) does not set `htmlSanitize = 1`, therefore the new default is to disable HTML sanitization and trigger a deprecation log in `ContentObjectRenderer::parseFunc`.
  18. Helmut Hummel commented on patch set 7 CR 0 08/14/21, 13:55

    Unresolved

    Thought about it a bit more. What do you think about my suggestions?

    HtmlViewHelper.php:102 Unresolved

    Re-thought this argument. What exactly is the use case? Which scenarios should be mitigated? If it is to not encode some HTML tags when an empty parseFuncTSPath is provided, this should rather be changed in ContentObjectRenderer::parseFunc directly by early returning when no configuration is provided. As the intention isn't to change the global default (invocation with no arguments should intentionally still calls the sanitizer), users would still need to adapt configuration, e.g. by disabling it in lib.parseFunc_RTE) So with or without the option, users who have special use cases need adapt something anyway, so it does not matter, whether they adapt the VH invocation, TypoScript or both. Additionally, if the VH invocation is touched anyway, it isn't a big deal to also provide a custom parseFuncTSPath with the required configuration. My conclusion is to not introduce a VH argument at all

    ContentObjectRenderer.php:3353 Unresolved

    I'd add an additional (or maybe alternative) check here (with according deprecation message) and return early, when $conf is completely empty, because the result is the same as going through the function with no config.
  19. Oliver Hader commented on patch set 7 08/15/21, 14:25

    Thanks Helmut for the feedback. I love the idea of returning early in `parseFunc` as this allows to provide the previous (intended?) behavior. It also would allow to keep `htmlSanitize` enabled per default - as it can be disabled via `stdWrap.parseFunc` or individual `parseFuncTSPath`. I've created a matrix showing the changes per version: https://docs.google.com/document/d/1mlw5gDOcFQERvMEdnJCPsFnq4E-3xDjqcIO8z5bip2A/edit?usp=sharing
  20. Oliver Hader uploaded patch set 8 08/16/21, 09:47

  21. core-ci voted on patch set 8 V +1 08/16/21, 10:04 Core CI is happy: https://gitlab.typo3.org/typo3/CI/cms/-/pipelines/15151

  22. Benni Mack commented on patch set 8 V +1 CR +1 08/16/21, 10:21

    Works properly in various backend and frontend rendering scenarios
  23. Helmut Hummel commented on patch set 8 V +1 CR +1 08/16/21, 11:18

    Makes sense. Thanks for the updates!
  24. Benni Mack voted on patch set 8 V +2 CR +2 08/16/21, 11:21

  25. Benni Mack merged patch set 9 08/16/21, 11:21