Review main Merged

84824[FEATURE] Make parseFunc allowTags and denyTags optional

Benni Mack CR +2 V +2 Normal +100 −20 updated 06/27/24, 15:59

Commit message

Since HTML Sanitizer was introduced, lib.parseFunc does
"transformations", instead of ensuring that HTML is
"safe", which wasn't possible anyways (that was one
of the reasons why htmlSanitize is introduced).

A quick explanation to the existing functionality
of allowTags and denyTags:

* If parseFunc stumbles across a tag, which is NOT
  a typotag (tags.a for example), and NOT an external
  block, it will be checked if it is in "allowTags"
  or NOT in "denyTags", then it gets rendered, otherwise
  the tag including its contents is htmlspecialchar'ed.

The tags are thus NOT removed, but instead hsced.

In order to simplify the process, allowTags and denyTags
can now be omitted, with the following result:

If allowTags = a,b,em... ONLY these tags are allowed,
and denyTags does not matter anymore already.

allowTags can now be set to "*", thus denyTags can be
used to mark explicitly use "denyTags".

It now makes little sense to define allowTags AND
denyTags at the same time.

Review

  • Code review CR +2 Done
    • Benni Mack +2
    • Christian Kuhn +1
    • Oliver Hader +1
  • Verified V +2 Done
    • Benni Mack +2
    • Christian Kuhn +1
    • Oliver Hader +1
    • core-ci +1 CI

Issues 1

Files 7

Review log 1622

  1. Benni Mack uploaded patch set 1 06/21/24, 11:59

  2. core-ci voted on patch set 1 V -1 06/21/24, 12:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60004

  3. Oliver Hader commented on patch set 1 06/24/24, 14:58

    The failing functional tests in `\TYPO3\CMS\FluidStyledContent\Tests\Functional\Rendering\SecureHtmlRenderingTest::customParseFuncAvoidCrossSiteScripting` are based on the custom `parseFunc` configuration (provided in the test, not taken from fluid-styled-content). And in that scenario `denyTags` is empty - that's why it was passed before. From a security point of view, this was one of the reasons why we introduced `typo3/html-sanitizer` back then. From a backward compatibility view, I'd consider this a bug in the previous implementation - the tag `img/src` and `strong` were not explicitly allowed - but they were also not denied, that's why it worked.

    ContentObjectRendererTest.php:2085

    In addition having `allowTags=*` and `denyTags=*` would be great
  4. Benni Mack commented on patch set 1 06/25/24, 06:08

    ContentObjectRendererTest.php:2085 Reply

    what would be your expected result?
  5. Oliver Hader uploaded patch set 2 V -1 06/25/24, 09:28

  6. Oliver Hader commented on patch set 1 06/25/24, 09:32

    Reply

    I've adjusted the tests now - the case for `<img/src="img"/onerror="alert(1)">` was correctly handled and sanitized by `typo3/html-sanitizer` (Masterminds parser split by attributes by `/`, and our sanitizer removed the disallowed attribute `onerror`). With this change, `ContentObjectRenderer` is encoding the markup and `typo3/html-sanitizer` does not have to take any action. That's fine.

    ContentObjectRendererTest.php:2085 Reply

    I adjusted the tests to reflect the current behavior. From my point of view `denyTags=*` should take precedence.
  7. core-ci voted on patch set 2 V +1 06/25/24, 09:33 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60280

  8. Oliver Hader uploaded patch set 3 V +1 06/26/24, 14:02

  9. core-ci voted on patch set 3 V +1 06/26/24, 14:08 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60392

  10. Oliver Hader commented on patch set 3 06/26/24, 15:13

    ContentObjectRendererTest.php:2085 Reply

    Done
  11. Benni Mack uploaded patch set 4 V +1 06/26/24, 15:25

  12. core-ci voted on patch set 4 V -1 06/26/24, 15:32 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60399

  13. Oliver Hader commented on patch set 4 06/26/24, 17:27

    The now failing functional tests in `TypoLinkGeneratorTest` are the result of the Masterminds parser, expanding `<good>` to `<good></good>` (this was directly encoded before removing the `allowTags` and `denyTags` from `ext_localconf.php`)
  14. Oliver Hader uploaded patch set 5 V -1 06/26/24, 17:55

  15. Oliver Hader commented on patch set 5 06/26/24, 17:56

    Reply

    Done
  16. core-ci voted on patch set 5 V -1 06/26/24, 18:03 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60407

  17. Oliver Hader uploaded patch set 6 V -1 06/27/24, 07:07

  18. core-ci voted on patch set 6 V +1 06/27/24, 07:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/60438

  19. Oliver Hader voted on patch set 6 CR +1 V +1 06/27/24, 15:53

  20. Christian Kuhn voted on patch set 6 CR +1 V +1 06/27/24, 15:58

  21. Benni Mack voted on patch set 6 CR +2 V +2 06/27/24, 15:59

  22. Benni Mack merged patch set 7 06/27/24, 15:59