Issue Bug Closed

#108897Nonce not added to configured directive

Torben Hansen 02/07/26, 14:27 updated 02/09/26, 18:06

Description

Using the directive argument in the f:security.nonce ViewHelper does not add the nonce to the configured directive.

Example from docs:

<style nonce="{f:security.nonce(directive: 'style-src')}">
    body {
        background-color: #f5f5f5;
    }
</style>

The nonce is generated for the nonce attribute of the style tag, but the generated nonce is added shown in the script-src CSP directive instead of the style-src.

Example outout:

    <style nonce="ehDpyDdsdUsHToBGBljOzQj1_IXu48U6qchvjWURF0xC911GfTpHBg">
        body {
            background-color: #f5f5f5;
        }
    </style>

Example CSP header for code above:

Content-Security-Policy default-src 'self'; script-src 'self' 'nonce-ehDpyDdsdUsHToBGBljOzQj1_IXu48U6qchvjWURF0xC911GfTpHBg' 'report-sample'; style-src-attr 'unsafe-inline' 'report-sample'; img-src 'self' data: *.ytimg.com *.vimeocdn.com; base-uri 'self'; frame-src 'self' *.youtube-nocookie.com *.youtube.com *.vimeo.com; report-uri https://typo3.local/@http-reporting?csp=report&requestTime=1770474372594502&requestHash=40149c1e6eee82179c50f08494b8c7c2a51f2e18

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 5

  1. Oliver Hader commented <span data-processor="relativetime" data-value="2026-02-07T16:38:25+00:00" > 02/07/26, 16:38 </span>

    The changelog for the change that introduced scope and directive at https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/13.4.x/Important-107062-AvoidApplyingContent-Security-PolicyNonceSourcesWhenNotRequired.html was about purging nonce, when not required (means, purging nonces where not actually required).

    The documentation at https://docs.typo3.org/other/typo3/view-helper-reference/main/en-us/Global/Security/Nonce.html is unfortunately incorrect here and was adjusted at https://github.com/TYPO3-Documentation/TYPO3CMS-Reference-ViewHelper/pull/194/changes:

    > The {f:security.nonce()} ViewHelper generates a CSP (Content Security Policy) nonce and registers it for inclusion in the CSP header.

    → that’s not the case – the intended usage of the nonce for a particular CSP directive is registered, but the nonceProxy is not added automatically to the policy

    —-

    It would be possible to extend the Policy->compile($nonce) processing, to add missing nonceProxy references (currently, they are only purged if not required).
    Thus, with the current implementation, the nonceProxy sill needs to be added manually via site-based csp.yaml or ContentSecurityPolicies.php configuration.

  2. Oliver Hader commented <span data-processor="relativetime" data-value="2026-02-07T16:48:06+00:00" > 02/07/26, 16:48 </span>

    A more desirable approach would be to use the f:asset.css view-helper:

    <f:asset.css identifier="identifier123" csp="1">
    body {
        background-color: #f5f5f5;
    }
    </f:asset.css>

    The code above does not work, and was part of the aims of issue #100887

  3. Torben Hansen commented and changed status New Closed <span data-processor="relativetime" data-value="2026-02-09T18:06:51+00:00" > 02/09/26, 18:06 </span>

    As discussed with Olly, this is no bug in TYPO3 core, but expected behavior.