Propagate CSP nonce to StyleInjector elements - #10393
Conversation
Mirror ScriptInjector nonce propagation for inline style elements and cover nonce-present and nonce-absent behavior.\n\nPartial gwtproject#9990
|
I think this looks right - if some other script can read the nonce and assign to its own scripts/stylesheets then by definition that other script can already run and is unsafe to begin with. This doesn't guarantee the safety of the stylesheet being injected though - StyleInjector will happily take a string from the URL (query params etc) even if entirely unsafe. That's the only thing I would feel nervous about here, that we could be implying that the script is known to be safe. Off the top of my head, we could make this configurable (e.g. |
|
Agreed. The nonce only lets the generated style pass nonce-based CSP; it does not make an untrusted CSS string safe, and the default behavior should not imply otherwise. I summarized |
StyleInjector creates inline
<style>elements for CssResource and GssResource output. Under a nonce-basedstyle-srcContent Security Policy, those elements need the page's nonce to be accepted.This change mirrors the existing ScriptInjector behavior: when the current document contains a
script[nonce], StyleInjector copies that nonce to each newly created style element. If no nonce source exists, the injected style element is left unchanged.The focused HtmlUnit coverage verifies both paths:
Local verification:
StyleInjectorTest: 6 tests, 0 failures, 0 errors;ant buildonly: successful;git diff --check: successful.This addresses the nonce option only; the hash-based option discussed in the issue remains separate.
Partial #9990