From 70521d20596580cb0a0b3a6c48db2245bcf47455 Mon Sep 17 00:00:00 2001 From: Johan Winther Date: Wed, 22 Jun 2022 16:48:02 +0200 Subject: [PATCH 1/3] Add nonce to styled span CSP nonces need to be added to any elements with a style attribute --- src/VirtualDom/Styled.elm | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/VirtualDom/Styled.elm b/src/VirtualDom/Styled.elm index 780a7159..3fa35be3 100644 --- a/src/VirtualDom/Styled.elm +++ b/src/VirtualDom/Styled.elm @@ -479,23 +479,27 @@ toKeyedStyleNode maybeNonce allStyles keyedChildNodes = toStyleNode : Maybe Nonce -> Dict CssTemplate Classname -> VirtualDom.Node msg toStyleNode maybeNonce styles = + let + nonceAttribute = + case maybeNonce of + Just (Nonce nonce) -> + [ VirtualDom.attribute "nonce" nonce ] + + Nothing -> + [] + in -- wrap the style node in a div to prevent `Dark Reader` from blowin up the dom. VirtualDom.node "span" - [ VirtualDom.attribute "style" "display: none;" - , VirtualDom.attribute "class" "elm-css-style-wrapper" - ] + ([ VirtualDom.attribute "style" "display: none;" + , VirtualDom.attribute "class" "elm-css-style-wrapper" + ] + ++ nonceAttribute + ) [ -- this