Issue Bug Closed

#107062CSP handling disables Caching

Sven Proffe 07/09/25, 09:37 updated 12/02/25, 13:57

Description

As soon as any kind of Content Security Policy handling is configured, TSFE adds the http header ‘Cache-Control: private, no-store’ (line 2426, as of v. 12.4.33) to the rendered page. https://docs.typo3.org/m/typo3/reference-coreapi/main/en-us/ApiOverview/ContentSecurityPolicy/Index.html#notes-about-nonces-and-caching mentions this behaviour. This leads (at least in one of my projects) to a situation where no pages are cached within our CDN.

From my point of view, the basic problem is that \TYPO3\CMS\Frontend\Middleware\ContentSecurityPolicyHeaders.php adds the attribute ‘nonce’ to the request, even if there is no CSP mutation requiring nonces. I would like to propose a change in that class, so that the ‘nonce’ attribute is only added to the request, if any of the CSP mutations make use of such features.

I’ve written a (sketchy) patch that solves the problem within my project (see the attached file) and would like to suggest an equivalent change in the core.

Thanks & cheers
Sven

Reviews 3

Files 1

History 742

Show 417 earlier messages
  1. Oliver Hader commented <span data-processor="relativetime" data-value="2025-07-09T12:27:20+00:00" > 07/09/25, 12:27 </span>

    Thanks for providing the patch. Unfortunately the scenario is a bit more complicated.

    The request object is used to populate the nonce value to all potential consumers and should not be omitted (otherwise components the need to assign a nonce value, cannot continue).
    The decision, whether to put nonce to the CSP header would happen in the PolicyProvider (since nonce values could have been requested dynamically, in site configs, in extension configs or via mutations persisted in the database).

    The patch for issue #100887 (pending since August 2023) does it like this:

    The decision whether to omit nonce values shall be explicit, by introducing a new behavior section for csp.yaml in the frontend:

    behavior:
      useNonce: drop
      useHash: allow
      enforceUnsafeInlineFor:
        - style-src
        - style-src-attr
        - style-str-elem

    In the YAML example above basically only useNonce: drop is relevant to actually drop nonce values for the particular frontend site.

  2. Oliver Hader commented <span data-processor="relativetime" data-value="2025-07-09T12:30:24+00:00" > 07/09/25, 12:30 </span>

    I guess it’s possible to extract “nonce dropping” from https://review.typo3.org/c/Packages/TYPO3.CMS/+/80554 into a separate patch.

  3. Gerrit Code Review pushed patch set 1 for main to change 90814 status Accepted Under Review <span data-processor="relativetime" data-value="2025-09-26T15:44:57+00:00" > 09/26/25, 15:44 </span>

  1. Oliver Hader commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2025-10-30T16:25:08+00:00" > 10/30/25, 16:25 </span>

    Applied in changeset commit:80f74700c14c4f40a083127a39c2e536a83a6de8.