Review main Merged

93419[FEATURE] Prefer CSP hash values over nonce values

Oliver Hader CR +2 V +2 Expert +940 −102 updated 03/30/26, 16:32

Commit message

Introduces infrastructure for hash-based Content-Security-Policy
sources as an alternative to per-request nonces. Hash-based CSP
is deterministic and allows HTTP responses to be cached by reverse
proxies and static-file-cache extensions.

DirectiveHashCollection is a shared per-request service that
accumulates SHA-256 hash values during page rendering, separated
by type (inline, resource, uri, generic). Collected hashes survive
the frontend page-cache round-trip via MetaDataState.

Hash usage is an explicit opt-in configured per site in csp.yaml
via the top-level `behavior:` key:

  behavior:
    useHash: true
    useNonce: false

Behavior is parsed by CspConfigurationFactory::buildBehavior()
and forwarded to Policy::prepare() through PolicyBag. Setting
useHash=true adds the collected hashes as CSP source mutations.
Setting useNonce=false removes nonce-proxy sources, which is
required for cacheable responses.

New ViewHelper f:asset.styleAttr hashes inline style attribute
values for style-src-attr coverage. f:asset.css and f:asset.script
accept a new `csp` argument (replacing deprecated `useNonce`).

Review

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

Issues 1

Files 33

Show 13 more files

Review log 2533

Show 58 earlier messages
  1. Oliver Hader uploaded patch set 1 03/28/26, 15:19

  2. Oliver Hader uploaded patch set 2 03/28/26, 15:21

  3. core-ci voted on patch set 2 V -1 03/28/26, 15:36 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98960

  4. core-ci commented on patch set 2 03/28/26, 15:43 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98960

  5. Oliver Hader uploaded patch set 3 V -1 03/28/26, 16:00

  6. Oliver Hader wrote 03/28/26, 16:01

    Topic set to csp
  7. core-ci voted on patch set 3 V -1 03/28/26, 16:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98961

  8. Oliver Hader uploaded patch set 4 V -1 03/28/26, 16:14

  1. Oliver Hader commented on patch set 4 03/28/26, 16:18

    This change is ready for review.
  2. core-ci voted on patch set 4 V +1 03/28/26, 16:22 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98964

  3. Georg Ringer commented on patch set 4 CR +1 V +1 03/28/26, 16:39

    Feature-100887-PreferCSPHashValuesOverNonceValues.rst:117

    IMO either {true} oder 1
  4. Oliver Hader uploaded patch set 5 CR +1 V +1 03/28/26, 17:06

  5. Oliver Hader commented on patch set 5 03/28/26, 17:07

    Feature-100887-PreferCSPHashValuesOverNonceValues.rst:117 Reply

    Thx. I adjusted it...
  6. Oliver Hader commented on patch set 5 03/28/26, 17:09

    Side-note: To enforce hashes and avoid nonces the following should be in the `csp.yaml` of a particular site: ```yaml behavior: useNonce: false useHash: true ``` Automatic inference might come later - currently it's only via explicit opt-in.
  7. Oliver Hader commented on patch set 5 03/28/26, 17:10

    Reply

    (reopening)
  8. core-ci voted on patch set 5 V +1 03/28/26, 17:17 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98965

  9. Garvin Hicking commented on patch set 5 03/28/26, 17:37

    AssetRenderer.php:69

    This would not trigger for a useNonce: 0 or useNonce: false setting due to empty(), probably unwanted? (Same for following triggers; fine for the actual content checks ofc)

    PageRenderer.php:841

    Rename $useNonce too maybe?

    PageRenderer.php:1624

    (See note on empty above)

    StyleAttrViewHelper.php:53

    Multiple values "color: green; border: 500px solid red" are fine? The description might imply only a single value is allowed.

    MetaDataState.php:80

    I think we have a JSON Utility class that reduces this boilerplate code (can't look it up on mobile atm)
  10. Georg Ringer commented on patch set 5 CR +1 V +1 03/28/26, 19:19

    as followup, adminpanel and probbaly others should be changed to use hashes (See \TYPO3\CMS\Adminpanel\Utility\ResourceUtility::getResources)
  11. Oliver Hader uploaded patch set 6 CR +1 V +1 03/28/26, 20:47

  12. Oliver Hader commented on patch set 5 03/28/26, 20:47

    AssetRenderer.php:69 Reply

    `isset` should be fine here... I mixed that with the Fluid view-helper attribute.

    PageRenderer.php:841 Reply

    I kept it for people that (maybe) used names parameters. However, I'm totally fine with adjusting that as well.

    PageRenderer.php:1624 Reply

    Done

    StyleAttrViewHelper.php:53 Reply

    The value could be anything, it is not parsed into CSS - but the hash is calculate on the whole value. I'll adjust the comments here. Besides that, it seems I started to refactor the behavior from an old patch, but did not finish...

    MetaDataState.php:80 Reply

    I failed to find any other existing code...
  13. Oliver Hader commented on patch set 6 03/28/26, 20:48

    Reply

    Thanks for the hint. I had that in an older/outdated version as well (see https://review.typo3.org/c/Packages/TYPO3.CMS/+/80554)
  14. Oliver Hader uploaded patch set 7 03/28/26, 20:54

  15. Oliver Hader commented on patch set 6 03/28/26, 20:55

    MetaDataState.php:80 Reply

    At least I reduced the code in this very class a bit...
  16. core-ci voted on patch set 6 V +1 03/28/26, 20:56 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98970

  17. core-ci voted on patch set 7 V +1 03/28/26, 21:05 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/98971

  18. Garvin Hicking commented on patch set 7 CR +1 03/28/26, 21:38

    PageRenderer.php:841 Reply

    Oh, I understand now. That might actually be. I mean we have a policy on that, but now I'm torn. $csp would be clearer... so maybe we can use this as "testing the waters" how many people use named parameters and complain? ;-)

    MetaDataState.php:80 Reply

    Haha my bad. I mixed this up with my company's JSON Utility helper that I use all the time 🤪 Thanks for iterating here!
  19. Georg Ringer voted on patch set 7 CR +1 V +1 03/29/26, 09:14

  20. Oliver Hader uploaded patch set 8 CR +1 V +1 03/30/26, 06:44

  21. core-ci voted on patch set 8 V +1 03/30/26, 06:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/99006

  22. Georg Ringer voted on patch set 8 CR +1 V +1 03/30/26, 07:32

  23. Benni Mack voted on patch set 8 CR +1 V +1 03/30/26, 16:30

  24. Oliver Hader commented on patch set 8 CR +2 V +2 03/30/26, 16:32

    Reply

    Done
  25. Oliver Hader merged patch set 9 03/30/26, 16:32