Review main Abandoned

84433[BUGFIX] Allow using CSPs without nonce

Patrick Schriner CR 0 V 0 Easy +42 −3 updated 06/03/24, 09:44

Commit message

At a lower level the global nonce is optional. Making it optional at a
higher stage in the CSP processing allows writing a middleware that does
not use nonces (e.g. to allow fully cached requests).

Review

  • Code review CR 0
  • Verified V 0

Issues 1

Files 4

Review log 1318

  1. Patrick Schriner uploaded patch set 1 05/28/24, 07:49

  2. 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

  3. Patrick Schriner uploaded patch set 2 V -1 05/28/24, 08:09

  4. 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

  5. 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.
  6. 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.
  7. Oliver Klee commented on patch set 2 05/28/24, 08:47

    ModelService.php:126

    We 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:128

    Can we cover the null case with a test?
  8. 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
  9. 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?
  10. 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
  11. Patrick Schriner uploaded patch set 3 V +1 05/29/24, 15:20

  12. Patrick Schriner commented on patch set 3 05/29/24, 15:22

    ModelService.php:126 Reply

    Done

    ModelService.php:128 Reply Unresolved

    this is going to be hard... there are almost no tests for this code part. I'll take a look
  13. 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

  14. Patrick Schriner uploaded patch set 4 V +1 06/01/24, 15:52

  15. Patrick Schriner uploaded patch set 5 06/01/24, 15:56

  16. 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

  17. 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

  18. Benjamin Franzke abandoned the change 06/03/24, 09:44