Review main Merged

78231[TASK] Add CSP nonce helper for inline styles in lit-element templates

Oliver Hader CR +2 V +2 Normal +94 −23 updated 03/24/23, 14:26

Commit message

When using Content-Security-Policy for `style-src` with a `nonce-...`
value, it requires that inline styles (those using a `<style>` element)
have to be granted with a corresponding `nonce="..."` attribute.

Note: 'unsafe-inline' is ignored when using a nonce or hashes.
This behavior is decribed in CSP L3 in section 6.7.3.2.:2.1
(https://w3c.github.io/webappsec-csp/#allow-all-inline)
> If expression matches the nonce-source or hash-source grammar,
> return "Does Not Allow".

Even if `<style>` usages in lit-element templates are static in most
cases, it is considered a "inline style" in the scope of CSP.

This change introduces a work-around, exposing `window.litNonce`
in the global JavaScript context. In case a malicous script manages
to retrieve this information, it does not really matter, since the
malicious script was already executed with a valid nonce before...

Review

  • Code review CR +2 Done
    • Andreas Kienast +2
    • Benni Mack +1
  • Verified V +2 Done
    • Andreas Kienast +2
    • Benni Mack +1
    • core-ci +1 CI

Issues 1

Files 8

Review log 912

  1. Oliver Hader uploaded patch set 1 03/23/23, 12:46

  2. Oliver Hader updated the commit message in patch set 2 03/23/23, 12:48

  3. core-ci voted on patch set 1 V +1 03/23/23, 12:55 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39467

  4. core-ci voted on patch set 2 V +1 03/23/23, 13:12 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39468

  5. Markus Klein commented on patch set 2 03/23/23, 14:20

    missing word I guess. "loaded"?
  6. Markus Klein commented on patch set 2 03/23/23, 14:21

    ckeditor5.rollup.functions.js:22

    can be reduced to ```JavaScript if (insertAt === 'top' && head.firstChild) { head.insertBefore(style, head.firstChild) } else { head.appendChild(style) } ```
  7. Oliver Hader uploaded patch set 3 V +1 03/23/23, 14:59

  8. Oliver Hader commented on patch set 2 03/23/23, 14:59

    Reply

    Ack

    ckeditor5.rollup.functions.js:22 Reply

  9. core-ci voted on patch set 3 V +1 03/23/23, 15:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/39478

  10. Benni Mack voted on patch set 3 V +1 CR +1 03/23/23, 22:44

  11. Andreas Kienast voted on patch set 3 V +2 CR +2 03/24/23, 14:26

  12. Andreas Kienast merged patch set 4 03/24/23, 14:26