Truly independent web browser
LibWeb: Treat nonces set through the IDL attribute as nonceable
Andreas Kling8cec4dc179ca
diff --git a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cppindex 11c8c7e6823..08ab4f7b99e 100644--- a/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp+++ b/Libraries/LibWeb/ContentSecurityPolicy/Directives/DirectiveOperations.cpp@@ -943,7 +943,10 @@ enum class NonceableResult {if (!is<HTML::HTMLElement>(element.ptr()) && !is<SVG::SVGElement>(element.ptr()))return NonceableResult::NotNonceable;- if (!element->has_attribute(HTML::AttributeNames::nonce))+ // INTEROP: An element whose [[CryptographicNonce]] was set through the nonce IDL attribute, which intentionally+ // does not update the content attribute, is treated as if it had a nonce attribute.+ auto const& internal_nonce = is<HTML::HTMLElement>(element.ptr()) ? as<HTML::HTMLElement>(*element).nonce() : as<SVG::SVGElement>(*element).nonce();+ if (!element->has_attribute(HTML::AttributeNames::nonce) && internal_nonce.is_empty())return NonceableResult::NotNonceable;// 2. If element is a script element, then for each attribute of element’s attribute list:diff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.txtindex 0d2afc3cf0d..edb3ef157ca 100644--- a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.txt+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.txt@@ -2,8 +2,8 @@ Harness status: OKFound 12 tests-10 Pass-2 Fail+11 Pass+1 FailPass Reading 'nonce' content attribute and IDL attribute.Pass Cloned node retains nonce.Pass Cloned node retains nonce when inserted.@@ -11,7 +11,7 @@ Pass Writing 'nonce' content attribute.Pass Writing 'nonce' IDL attribute.Pass Document-written script executes.Pass Document-written script's nonce value.-Fail createElement.nonce.+Pass createElement.nonce.Pass setAttribute('nonce') overwrites '.nonce' upon insertion.Pass createElement.setAttribute.Fail Custom elements expose the correct events.