Skip to content

feat: Add nonce to <style type=module>#292

Merged
KurtCattiSchmidt merged 2 commits into
mainfrom
webui-module-nonce
May 10, 2026
Merged

feat: Add nonce to <style type=module>#292
KurtCattiSchmidt merged 2 commits into
mainfrom
webui-module-nonce

Conversation

@KurtCattiSchmidt
Copy link
Copy Markdown
Contributor

https://chromium-review.googlesource.com/c/chromium/src/+/7758302 added enforcement for the inline-src script CSP because <style type=module> impacts the module map, which is a script API. Due to this, users of <style type=module> need to either allow the inline script CSP or add a nonce to <style type=module>.

Currently, WebUI was not passing the nonce through to <style type=module>. This change fixes this behavior by passing the existing nonce to <style type=module> output.

The third <style type="module"> emission at crates/webui-handler/src/route_handler.rs:1033 (templateStyles JSON for SPA partial navigation) was intentionally left untouched. Adding nonce there would have changed the public render_partial / render_component_templates signatures and cascaded into FFI/C ABI, .NET, Node, WASM, CLI, the webui crate, and example bindings. This will be done as a follow-up.

Comment thread crates/webui-handler/src/lib.rs Dismissed
Comment thread crates/webui-handler/src/lib.rs Dismissed
@KurtCattiSchmidt KurtCattiSchmidt merged commit cc5d66e into main May 10, 2026
21 checks passed
@KurtCattiSchmidt KurtCattiSchmidt deleted the webui-module-nonce branch May 10, 2026 17:44
KurtCattiSchmidt added a commit that referenced this pull request Jun 6, 2026
…gation

Chromium 145+ enforces script-src for <style type="module"> elements because they affect the module map. PR #292 added the nonce on the initial SSR path but explicitly deferred the SPA partial-navigation case to avoid changing render_partial/render_component_templates signatures (which would cascade into FFI/Node/WASM/CLI bindings).

This completes the follow-up on the client side: when registerTemplatesAndStyles re-injects a <style type="module"> from the JSON partial, apply the page's existing nonce (window.__webui.nonce). No server signature change required — the page's CSP already allows this nonce.

Without this fix, every SPA navigation that pulls in new component CSS triggers `Executing inline script violates Content Security Policy directive 'script-src ...`'' and the styles never adopt, leaving newly-loaded components unstyled.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants