Review 13.4 Merged

91063[BUGFIX] Avoid applying CSP nonce sources when not required

Oliver Hader CR +2 V +2 Hard +796 −80 updated 10/30/25, 16:21

Commit message

This change aims to avoid applying Content-Security-Policy nonce
source when they are not actually required.

The `ConsumableNonce` class was refactored and does not extend
`ConsumableString` anymore. As a result the invocation counters
are now split into `consumeInline` (required usage of the nonce)
and `consumeStatic` (optional usage of the nonce) and are tracking
the different usage aspects, like their directives.

$nonce = new ConsumableNonce();
$nonce->consumeInline(Directive::ScriptSrcElem); // required usage
$nonce->consumeStatic(Directive::StyleSrcElem); // optional usage

Nonce sources are removed from the CSP policy in case
- the response content is readable and is empty (0 bytes); or
- the nonce consumption counter (all usages) is zero; or
- the consumed nonce sources for a particular directive can be
  avoided due to the existence of a source keyword exception
  (like using `'unsafe-inline'`); or
- the new `PolicyPreparedEvent` is used to programatically adjust
  the corresponding behavior to deny or allow  nonce sources

In case the nonce sources are supposed to be denied, both
`ContentSecurityPolicyHeaders` middlewares in the frontend
and backend scope are removing the corresponding nonce-related
literals from the generated HTML content of the response object.

Review

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

Issues 1

Files 24

Show 4 more files

Review log 1015

  1. Oliver Hader uploaded patch set 1 10/14/25, 11:59

  2. core-ci voted on patch set 1 V +1 10/14/25, 12:06 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/86623

  3. Oliver Hader uploaded patch set 2 V +1 10/20/25, 10:07

  4. core-ci voted on patch set 2 V +1 10/20/25, 10:30 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/87067

  5. Oliver Hader uploaded patch set 3 V +1 10/27/25, 16:43

  6. core-ci voted on patch set 3 V +1 10/27/25, 16:53 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/87685

  7. Oliver Hader commented on patch set 3 CR -1 10/28/25, 19:57

    Needs to be adjusted - [ ] rebase on migrated functional `RequestHandlerTest` - [ ] re-add `final` in `PolicyProvider`
  8. Oliver Hader uploaded patch set 4 CR -1 V +1 10/28/25, 21:00

  9. Oliver Hader commented on patch set 4 10/28/25, 21:01

    Reply

    Done
  10. core-ci voted on patch set 4 V +1 10/28/25, 21:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/87888

  11. Oliver Hader commented on patch set 5 V +1 10/30/25, 16:00

    Published edit on patch set 4.
  12. Oliver Hader commented on patch set 5 10/30/25, 16:01

    This change is ready for review.
  13. core-ci voted on patch set 5 V +1 10/30/25, 16:10 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/88162

  14. Oliver Hader voted on patch set 5 CR +2 V +2 10/30/25, 16:21

  15. Oliver Hader merged patch set 6 10/30/25, 16:21