Issue Bug Under Review

#102690Script generated with "removeDefaultJS = external" has no nonce attribute

Simon Würstle 12/18/23, 12:11 updated 11/10/26, 12:27

Description

If you enable [SYS][features][security.frontend.enforceContentSecurityPolicy] and set “config.removeDefaultJS” to “external” (= default), the script tag has no “nonce” attribute and thus the script is blocked by the browser.

Reviews 2

Files 2

History 410

  1. Benjamin Franzke commented and changed attached csp-script-example.png status Under Review Needs Feedback <span data-processor="relativetime" data-value="2023-12-19T07:14:09+00:00" > 12/19/23, 07:14 </span>

    Can you share your CSP Policy and the exact CSP error you get?

    Questions:

    1. Which script is exactly failing – is it EXT:frontend/Resources/Public/JavaScript/default_frontend.js which is used for email links or another one? (I’m asking because the proposed fix accounts for the mentioned case)
    2. What is your CSP (inspect via browser tools and show the rendered header – it should contain `script-src ‘self’ – see an example below)
    3. Do you use some kind of CDN for assets/typo3temp?

    csp-script-example.png

  2. Simon Würstle commented and changed attached Screenshot 2023-12-19 104916.png <span data-processor="relativetime" data-value="2023-12-19T09:49:55+00:00" > 12/19/23, 09:49 </span>

    Of course, this is my csp.yaml:

    inheritDefault: true
    mutations:
      - mode: extend
        directive: 'script-src'
        sources:
          - "'strict-dynamic'"

    The error is:
    “Refused to load the script ‘https://foobar.ddev.site/typo3temp/assets/js/ba19e614c16923a947df5b199324c770.js?1694955793’ because it violates the following Content Security Policy directive: “script-src ‘self’ ‘nonce-e0E_2ThWz9pRG8NgCXsiWt59tHyzQ1pHKmPRbF9zEUtMVqV-O9uOyg’ ‘strict-dynamic’ ‘report-sample’”. Note that ‘strict-dynamic’ is present, so host-based allowlisting is disabled. Note that ‘script-src-elem’ was not explicitly set, so ‘script-src’ is used as a fallback.”

    Answers to your questions:
    1. it is the script you mentioned (EXT:frontend/Resources/Public/JavaScript/default_frontend.js)
    2. see attached screenshot
    3. no CDN
  3. Benjamin Franzke commented and changed status Needs Feedback Accepted <span data-processor="relativetime" data-value="2023-12-19T11:01:49+00:00" > 12/19/23, 11:01 </span>

    understood, thanks!

    So strict-dynamic again – we already have some implications for strict-dynamic in place, but obviously not enough:
    https://github.com/TYPO3/typo3/blob/main/typo3/sysext/core/Classes/Security/ContentSecurityPolicy/SourceKeyword.php#L60-L66

    Ideally would could apply the strict-dynamic implications also during rendering – like `@useNonceIfStrictDynamic@`
    CC @ohader

  4. Garvin Hicking commented and changed category assigned to Oliver Hader <span data-processor="relativetime" data-value="2024-07-31T10:05:35+00:00" > 07/31/24, 10:05 </span>

    (Set a category and moved the assignee to Oliver Hader, I hope that’s ok – please drop and let me know if I overstepped :) )

  5. Gerrit Code Review pushed patch set 3 for main to change 82204 status Accepted Under Review <span data-processor="relativetime" data-value="2024-10-18T14:07:43+00:00" > 10/18/24, 14:07 </span>