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

    Imported before Forger kept the single votes, the next import adds them.

  • Verified V +2

    Imported before Forger kept the single votes, the next import adds them.

Issues 1

Files 8