#108897Nonce not added to configured directive
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.
Related issues 2
History 5
-
Torben Hansen changed Related to #108422 <span data-processor="relativetime" data-value="2026-02-07T14:28:29+00:00" > 02/07/26, 14:28 </span>
-
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.cssview-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
-
Oliver Hader changed Related to #100887 <span data-processor="relativetime" data-value="2026-02-07T16:48:12+00:00" > 02/07/26, 16:48 </span>
-
Torben Hansen commented and changed status
NewClosed <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.
The changelog for the change that introduced
scopeanddirectiveat 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
nonceProxyis not added automatically to the policy—-
It would be possible to extend the
Policy->compile($nonce)processing, to add missingnonceProxyreferences (currently, they are only purged if not required).Thus, with the current implementation, the
nonceProxysill needs to be added manually via site-basedcsp.yamlorContentSecurityPolicies.phpconfiguration.