84433[BUGFIX] Allow using CSPs without nonce
Commit message
Review
-
Code review CR 0
-
Verified V 0
Issues 1
Files 4
- typo3/sysext/core/Classes/Security/ContentSecurityPolicy/ModelService.php4+4 −1
- typo3/sysext/core/Classes/Security/ContentSecurityPolicy/Policy.php+2 −2
- typo3/sysext/core/Tests/Functional/Security/ContentSecurityPolicy/ModelServiceTest.php+29 −0
- typo3/sysext/core/Tests/Functional/Security/ContentSecurityPolicy/PolicyTest.php+7 −0
Review log 1318
-
Patrick Schriner uploaded patch set 1 05/28/24, 07:49
-
core-ci voted on patch set 1 V -1 05/28/24, 07:55 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58380
-
Patrick Schriner uploaded patch set 2
V -105/28/24, 08:09 -
core-ci voted on patch set 2 V +1 05/28/24, 08:16 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58382
-
Benjamin Franzke commented on patch set 2 05/28/24, 08:24
Hey, The page will be uncached if the `nonce` is actually consumed – that means one content element/page-typoscript rendered a HTML tag with a `nonce` attribute, see: https://github.com/TYPO3/typo3/blob/9cc84da046d2ef4dc27fad8aec57a3b2b01eca87/typo3/sysext/frontend/Classes/Http/RequestHandler.php#L142-L156 If the nonce is not consumed, you should see a fully cached page (right?). I do not understand how you'd (with a custom middleware) create a CSP without nonces, while there is content that actually used (and therefore requires?) nonces. You'd need to use hashes then, do you? In that case nonces should not be consumed, if it is done nonetheless, we should actually try to fix that. BTW, we'd like to get rid of nonces for frontend rendering as well, olly has a patch pending: https://review.typo3.org/c/Packages/TYPO3.CMS/+/80554 Also I did some experiments last year for cached-frontend-importmap: https://github.com/bnf/typo3/commits/frontend-importmap-v5/ (https://github.com/bnf/typo3/commit/8eefa79b6380f13) But yea, this is just FYI and unfortunately not ready: we ideally want the frontend to use hashes by default/if-possible as well. -
Benjamin Franzke commented on patch set 2 05/28/24, 08:27
Reply
Maybe you assumed the page is uncached because a nonce is rendered into the CSP header in any case? AH, or probably you mean fully-cacheable by a proxy? In that case something like https://github.com/bnf/typo3/commit/85bde8055bf should help. -
Oliver Klee commented on patch set 2 05/28/24, 08:47
ModelService.php:126We only need PHPDoc annotations if they add anything over the native type declarations (e.g., comments, or types that cannot be modeled natively). So in this case, I think we can drop the PHPDoc annotations (and hence the complete comment).ModelService.php:128Can we cover the null case with a test? -
Patrick Schriner commented on patch set 2 05/28/24, 09:18
Reply
Hi Benjamin, I didn't see the other patch yet - thanks for the hint. Yeah the idea was to enforce using hashes for all ("own") sources. Currently (targeting TYPO3 12) I use (BeforeJavaScriptsRenderingEvent, BeforeStylesheetsRenderingEvent and the render-postTransform hook) to calculate the hashes. My csp middleware (replacement for the frontend-ContentSecurityPolicyHeaders middleware) will of course not work as expected if anyone used useNonce explicitly (though not breaking); Basically by not forcing an nonce on the request object and the policy the nonce will never be consumed; I just have to remove the nonce-proxy from the ContentSecurityPolicies https://github.com/TYPO3-CMS/core/blob/main/Classes/Page/PageRenderer.php#L1712 https://github.com/TYPO3-CMS/core/blob/main/Classes/Page/PageRenderer.php#L1575 unfortunetly there are some places in PageRenderer that will pretty much always consume the nonce* *not the worst of ideas - if I get rid of any typoscript-included css/js that might work as well -
Benjamin Franzke commented on patch set 2 05/28/24, 09:37
Reply
can you test if https://review.typo3.org/c/Packages/TYPO3.CMS/+/84435 solves your issue as well and would allow to use the core middleware and drop the custom one? -
Benjamin Franzke commented on patch set 2 05/28/24, 09:39
Reply Unresolved
> unfortunetly there are some places in PageRenderer that will pretty much always consume the nonce ugh, that looks odd, will need to check that. thanks for the hints -
Patrick Schriner uploaded patch set 3
V +105/29/24, 15:20 -
Patrick Schriner commented on patch set 3 05/29/24, 15:22
ModelService.php:126ReplyDoneModelService.php:128Reply Unresolvedthis is going to be hard... there are almost no tests for this code part. I'll take a look -
core-ci voted on patch set 3 V +1 05/29/24, 15:24 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58451
-
Patrick Schriner uploaded patch set 4
V +106/01/24, 15:52 -
Patrick Schriner uploaded patch set 5 06/01/24, 15:56
-
core-ci voted on patch set 4 V +1 06/01/24, 15:58 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58569
-
core-ci voted on patch set 5 V +1 06/01/24, 16:01 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/58570
-
Benjamin Franzke abandoned the change 06/03/24, 09:44