Review main Ready for review Quiet

95569[BUGFIX] Allow CSP directive "strict-dynamic" in conjunction w/ hashes

Garvin Hicking CR -1 V +1 Normal +54 −4 updated 10/01/26, 11:00

Commit message

MDN docs epxlicitly state [1] that StrictDynamic is fine to use
in either nonce or hashed context.

This patch alters the compilation evalution to only remove a
possibly set StrictDynamic source keywords in non-nonce-non-hash
scenarios.

This resolves the "@todo" note left in there.

[1] https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/script-src#strict-dynamic

Test this change

Run a command in your clone of the TYPO3 Core. Then try what the change does and vote on Verified in Gerrit. How to review a patch

Check out patch set 3
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/69/95569/3 && git checkout FETCH_HEAD
Cherry-pick onto main
git fetch https://review.typo3.org/Packages/TYPO3.CMS refs/changes/69/95569/3 && git cherry-pick FETCH_HEAD

Review

  • Code review CR -1 Needs a vote
    • Garvin Hicking -1
    • Josua Vogel +1
    • Benni Mack +1
  • Verified V +1 Needs a vote
    • Benni Mack +1
    • core-ci +1 CI

Merge conflicts 2

Issues 1

Files 2

Review log 1013

  1. Garvin Hicking uploaded patch set 1 09/02/26, 15:33

  2. core-ci voted on patch set 1 V +1 09/02/26, 15:40 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/107647

  3. Garvin Hicking updated the commit message in patch set 2 V +1 09/03/26, 11:12

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

  5. Benni Mack voted on patch set 2 CR +1 V +1 09/04/26, 13:13

  6. Garvin Hicking rebased onto patch set 3 CR +1 V +1 10/01/26, 07:55

  7. Benni Mack voted on patch set 3 CR +1 V +1 10/01/26, 07:55

  8. core-ci voted on patch set 3 V +1 10/01/26, 08:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/109761

  9. Josua Vogel voted on patch set 3 CR +1 10/01/26, 10:18

  10. Benjamin Franzke commented on patch set 3 10/01/26, 10:41

    Policy.php:246

    Hm, this condition looks awkwards, since one would usually just write `if ($useNonce)`, but this explicit `!== false` also handles `null` …which is an allowed value and probably the reason which this condition is written as is. (reminder `null` refers to systemd-decides per `Behavior` annoation) In other words: The condition evaluates to true if `$useNonce` is `true` *or* `null`. My question basically is: Does this patch only "work" if both values are set in csp.yaml, e.g.: ``` behavior: useNonce: false useHash: true ``` Or would it also work with: ``` behavior: useHash: true ``` (where `useNonce` is null, if I understand things correctly)

    Policy.php:247

    Hm, `applySourceImplications()` actually contains logic for `strictDynamic` in the `SourceKeyword` enum, where it ensures that the nonce proxy is added to the sources. See https://github.com/TYPO3/typo3/blob/bbaf7003b636be0a48aa447afe080908208facd1/typo3/sysext/core/Classes/Security/ContentSecurityPolicy/SourceKeyword.php#L64-L66 I wonder if that part should be adapted within that method (instead of avoiding to call that method). E.g. instead of unconditionally adding the nonce proxy in there, it could be changed to check for the hash value type in there instead of below.

    Policy.php:250

    I wonder where the `nonceProxy` actually comes from, that is about to be removed here? From my understanding it would have been added by `applySourceImplications` (previously), when *needed* for strict dynamic. If it was added by other parts of the system (that really need the nonce), we should not "just" remove it here, because there is some hash value defined. Reason: There needs to be a reason why nonce proxy is added, which is: it seems to be *used*. What I mean: We can not assume that a policy contains nonces and hashes, can just remove the hashes, because there can be components that do not use hashes and actually activated nonce usage. TL;DR (of all 3 comments): Would any of your tests fail if the `elseif ($collection->containsTypes(HashValue::class)) {` branch did nothing (that means it does not remove the nonce proxy)?
  11. Benjamin Franzke commented on patch set 3 10/01/26, 10:51

    Policy.php:247 Reply Unresolved

    Or maybe better: Remove `applySourceImplications` alltogether. It seems it would be better to handle all logic in one place. What do you think?
  12. Garvin Hicking commented on patch set 3 CR -1 10/01/26, 10:51

    Policy.php:250 Reply Unresolved

    You're right, tests currently don't fail when disabling this branch, so we have missing coverage here. I'll go back to the drawing board here. Thanks!
  13. Benni Mack commented on patch set 3 10/01/26, 11:00

    Policy.php:246 Reply Unresolved

    I had it running with: ``` behavior: useNonce: false useHash: true ``` which we often use in our projects.