Truly independent web browser
Tests/LibWeb: Import Content Security Policy tests
Andreas Klingef26b84e8d51
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.txtnew file mode 100644index 00000000000..0d2afc3cf0d--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.txt@@ -0,0 +1,18 @@+Harness status: OK++Found 12 tests++10 Pass+2 Fail+Pass Reading 'nonce' content attribute and IDL attribute.+Pass Cloned node retains nonce.+Pass Cloned node retains nonce when inserted.+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 setAttribute('nonce') overwrites '.nonce' upon insertion.+Pass createElement.setAttribute.+Fail Custom elements expose the correct events.+Pass Nonces don't leak via CSS side-channels.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/javascript-window-open-blocked.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/javascript-window-open-blocked.txtnew file mode 100644index 00000000000..4b0ad92cca3--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/javascript-window-open-blocked.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail Check that a securitypolicyviolation event is fired\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/non-nonceable-elements.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/non-nonceable-elements.txtnew file mode 100644index 00000000000..a16b4fde0d8--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/non-nonceable-elements.txt@@ -0,0 +1,16 @@+Harness status: OK++Found 10 tests++7 Pass+3 Fail+Pass Nonceable script element 0+Pass Non-nonceable script element 1+Pass Non-nonceable script element 2+Pass Non-nonceable script element 3+Pass Non-nonceable script element 4+Fail Non-nonceable script element 5+Fail Non-nonceable script element 6+Pass Non-nonceable script element 7+Pass Non-nonceable script element 8+Fail Non-nonceable script element 9\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-connected-after-set.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-connected-after-set.txtnew file mode 100644index 00000000000..df96375dde8--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-connected-after-set.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail targeting-for-inline-handler-connected-after-set\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-markup-disconnected-after-set.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-markup-disconnected-after-set.txtnew file mode 100644index 00000000000..091fd87da2b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-markup-disconnected-after-set.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail targeting-for-inline-handler-in-markup-disconnected-after-set\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-shadow-dom.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-shadow-dom.txtnew file mode 100644index 00000000000..340422ecda5--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-shadow-dom.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail targeting-for-inline-handler-in-shadow-dom\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-disconnected-element.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-disconnected-element.txtnew file mode 100644index 00000000000..6e3e0abd92a--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-disconnected-element.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail targeting-for-inline-handler-on-disconnected-element\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-element-in-disconnected-document-fragment.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-element-in-disconnected-document-fragment.txtnew file mode 100644index 00000000000..d3f226d5c0e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-element-in-disconnected-document-fragment.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail targeting-for-inline-handler-on-element-in-disconnected-document-fragment\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-main-frame-element-moved-to-subframe.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-main-frame-element-moved-to-subframe.txtnew file mode 100644index 00000000000..d1b8436ae3f--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-main-frame-element-moved-to-subframe.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail targeting-for-inline-handler-on-main-frame-element-moved-to-subframe\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href.txtnew file mode 100644index 00000000000..796ac584969--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail javascript: navigation using <a href> should be refused due to missing unsafe-hashes\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank-script-src-elem.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank-script-src-elem.txtnew file mode 100644index 00000000000..525bd096c91--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank-script-src-elem.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail javascript: navigation using <a href target=_blank> should be refused due to missing unsafe-hashes\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank.txtnew file mode 100644index 00000000000..525bd096c91--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail javascript: navigation using <a href target=_blank> should be refused due to missing unsafe-hashes\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-window_open.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-window_open.txtnew file mode 100644index 00000000000..ccbeef93241--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-window_open.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail Test that the javascript: src is not allowed to run\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href.txtnew file mode 100644index 00000000000..7b406b8f6cd--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail javascript: navigation using <a href> should be refused due to wrong hash\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank-script-src-elem.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank-script-src-elem.txtnew file mode 100644index 00000000000..1b8952d1403--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank-script-src-elem.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail javascript: navigation using <a href target=_blank> should be refused due to wrong hash\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank.txtnew file mode 100644index 00000000000..1b8952d1403--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail javascript: navigation using <a href target=_blank> should be refused due to wrong hash\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-window_open.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-window_open.txtnew file mode 100644index 00000000000..ccbeef93241--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-window_open.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail Test that the javascript: src is not allowed to run\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.htmlnew file mode 100644index 00000000000..a64ccd2ee41--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.html@@ -0,0 +1,172 @@+<!DOCTYPE html>+<script src="../../resources/testharness.js" nonce="abc"></script>+<script src="../../resources/testharnessreport.js" nonce="abc"></script>++<!-- `Content-Security-Policy: script-src 'nonce-abc'; img-src 'none'` delivered via headers -->++<body>+<!-- Basics -->+<script nonce="abc" id="testScript">+ document.currentScript.setAttribute('executed', 'yay');+</script>++<script nonce="abc">+ var script = document.querySelector('#testScript');++ test(t => {+ // Query Selector+ assert_equals(document.querySelector('body [nonce]'), script);+ assert_equals(document.querySelector('body [nonce=""]'), script);+ assert_equals(document.querySelector('body [nonce=abc]'), null);++ assert_equals(script.getAttribute('nonce'), '');+ assert_equals(script.nonce, 'abc');+ }, "Reading 'nonce' content attribute and IDL attribute.");++ // Clone node.+ test(t => {+ script.setAttribute('executed', 'boo');+ var s2 = script.cloneNode();+ assert_equals(s2.nonce, 'abc', 'IDL attribute');+ assert_equals(s2.getAttribute('nonce'), '');+ }, "Cloned node retains nonce.");++ async_test(t => {+ var s2 = script.cloneNode();+ document.head.appendChild(s2);+ assert_equals(s2.nonce, 'abc');+ assert_equals(s2.getAttribute('nonce'), '');++ window.addEventListener('load', t.step_func_done(_ => {+ // The cloned script won't execute, as its 'already started' flag is set.+ assert_equals(s2.getAttribute('executed'), 'boo');+ }));+ }, "Cloned node retains nonce when inserted.");++ // Set the content attribute to 'foo'+ test(t => {+ script.setAttribute('nonce', 'foo');+ assert_equals(script.getAttribute('nonce'), 'foo');+ assert_equals(script.nonce, 'foo');+ }, "Writing 'nonce' content attribute.");++ // Set the IDL attribute to 'bar'+ test(t => {+ script.nonce = 'bar';+ assert_equals(script.nonce, 'bar');+ assert_equals(script.getAttribute('nonce'), 'foo');+ }, "Writing 'nonce' IDL attribute.");++ // Fragment parser.+ var documentWriteTest = async_test("Document-written script executes.");+ document.write(`<script nonce='abc'>+ documentWriteTest.done();+ test(t => {+ var script = document.currentScript;+ assert_equals(script.getAttribute('nonce'), '');+ assert_equals(script.nonce, 'abc');+ }, "Document-written script's nonce value.");+ </scr` + `ipt>`);++ // Create node.+ async_test(t => {+ var s = document.createElement('script');+ s.innerText = script.innerText;+ s.nonce = 'abc';+ assert_equals(s.nonce, 'abc');+ assert_equals(s.getAttribute('nonce'), null);+ document.head.appendChild(s);+ assert_equals(s.nonce, 'abc');+ assert_equals(s.getAttribute('nonce'), null);++ window.addEventListener('load', t.step_func_done(_ => {+ assert_equals(s.getAttribute('executed'), 'yay');+ }));+ }, "createElement.nonce.");++ async_test(t => {+ var s = document.createElement('script');+ s.innerText = script.innerText;+ s.nonce = 'zyx';+ s.setAttribute('nonce', 'abc');+ assert_equals(s.nonce, 'abc');+ document.head.appendChild(s);+ assert_equals(s.nonce, 'abc');+ assert_equals(s.getAttribute('nonce'), '');++ window.addEventListener('load', t.step_func_done(_ => {+ assert_equals(s.getAttribute('executed'), 'yay');+ }));+ }, "setAttribute('nonce') overwrites '.nonce' upon insertion.");++ // Create node.+ async_test(t => {+ var s = document.createElement('script');+ s.innerText = script.innerText;+ s.setAttribute('nonce', 'abc');+ assert_equals(s.getAttribute('nonce'), 'abc', "Pre-insertion content");+ assert_equals(s.nonce, 'abc', "Pre-insertion IDL");+ document.head.appendChild(s);+ assert_equals(s.nonce, 'abc', "Post-insertion IDL");+ assert_equals(s.getAttribute('nonce'), '', "Post-insertion content");++ window.addEventListener('load', t.step_func_done(_ => {+ assert_equals(s.getAttribute('executed'), 'yay');+ }));+ }, "createElement.setAttribute.");+</script>++<!-- Custom Element -->+<script nonce="abc">+ var eventList = [];+ class NonceElement extends HTMLElement {+ static get observedAttributes() {+ return ['nonce'];+ }++ constructor() {+ super();+ }++ attributeChangedCallback(name, oldValue, newValue) {+ eventList.push({+ type: "AttributeChanged",+ name: name,+ oldValue: oldValue,+ newValue: newValue+ });+ }++ connectedCallback() {+ eventList.push({+ type: "Connected",+ });+ }+ }++ customElements.define("nonce-element", NonceElement);+</script>+<nonce-element nonce="abc"></nonce-element>+<script nonce="abc">+ test(t => {+ assert_object_equals(eventList[0], { type: "AttributeChanged", name: "nonce", oldValue: null, newValue: "abc" }, "AttributeChanged 1");+ assert_object_equals(eventList[1], { type: "Connected" }, "Connected");+ assert_object_equals(eventList[2], { type: "AttributeChanged", name: "nonce", oldValue: "abc", newValue: "" }, "AttributeChanged 2");+ assert_equals(eventList.length, 3);+ }, "Custom elements expose the correct events.");+</script>++<!-- CSS Leakage -->+<style>+ #cssTest { display: block; }+ #cssTest[nonce=abc] { background: url(../../security/resources/abe.png); }+</style>+<script nonce="abc" id="cssTest">+ test(t => {+ const script = document.querySelector('#cssTest');+ t.add_cleanup(() => script.remove());+ var style = getComputedStyle(script);+ assert_equals(style['display'], 'block');+ assert_equals(style['background-image'], 'none');+ }, "Nonces don't leak via CSS side-channels.");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.html.headers b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.html.headersnew file mode 100644index 00000000000..ad8d0b54f31--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/nonce-hiding/script-nonces-hidden.html.headers@@ -0,0 +1 @@+Content-Security-Policy: script-src 'nonce-abc'; img-src 'none'diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/javascript-window-open-blocked.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/javascript-window-open-blocked.htmlnew file mode 100644index 00000000000..a3e75d0c7d8--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/javascript-window-open-blocked.html@@ -0,0 +1,20 @@+<!DOCTYPE HTML>+<html>+<head>+ <title>Window.open should not open javascript url if not allowed.</title>+ <meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc';">+ <script nonce='abc' src='../../resources/testharness.js'></script>+ <script nonce='abc' src='../../resources/testharnessreport.js'></script>+</head>+<body>+ <script nonce='abc'>+ var t = async_test("Check that a securitypolicyviolation event is fired");+ window.addEventListener('securitypolicyviolation', t.step_func_done(function(e) {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.violatedDirective, "script-src-elem");+ }));++ window.open('javascript:test(function() { assert_unreached("FAIL")});', 'new');+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/non-nonceable-elements.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/non-nonceable-elements.htmlnew file mode 100644index 00000000000..d01f92c5df8--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/non-nonceable-elements.html@@ -0,0 +1,105 @@+<!DOCTYPE html>+<head>+ <meta http-equiv="Content-Security-Policy"+ content="script-src 'nonce-secret-script'; style-src 'nonce-secret-style'">+ <script nonce="secret-script" src="../../resources/testharness.js"></script>+ <script nonce="secret-script" src="../../resources/testharnessreport.js"></script>+</head>+<body>+ <script nonce="secret-script">+ var scriptTest0 = false;+ var scriptTest1 = false;+ var scriptTest2 = false;+ var scriptTest3 = false;+ var scriptTest4 = false;+ var scriptTest5 = false;+ var scriptTest6 = false;+ var scriptTest7 = false;+ var scriptTest8 = false;+ var scriptTest9 = false;+ </script>++ <script nonce="secret-script">+ scriptTest0 = true;+ </script>+ <script nonce="secret-script" data="<script">+ scriptTest1 = true;+ </script>+ <script nonce="secret-script" data="<sCRIpt">+ scriptTest2 = true;+ </script>+ <script nonce="secret-script" data="<style">+ scriptTest3 = true;+ </script>+ <script nonce="secret-script" data="<stYlE">+ scriptTest4 = true;+ </script>+ <script nonce="secret-script" data="<link">+ scriptTest5 = true;+ </script>+ <script nonce="secret-script" data="<LinK">+ scriptTest6 = true;+ </script>+ <script nonce="secret-script" data="aaa<sCripTbb">+ scriptTest7 = true;+ </script>+ <script nonce="secret-script" data="aa<sTylEbbb">+ scriptTest8 = true;+ </script>+ <script nonce="secret-script" data="cc<lInKddd">+ scriptTest9 = true;+ </script>++ <script nonce="secret-script">+ test(t =>+ assert_true(+ scriptTest0,+ "<script> element with no special attributes should execute"),+ "Nonceable script element 0");+ test(t =>+ assert_false(+ scriptTest1,+ "<script> element with attribute '<script' should not execute"),+ "Non-nonceable script element 1");+ test(t =>+ assert_false(+ scriptTest2,+ "<script> element with attribute '<sCRIpt' should not execute"),+ "Non-nonceable script element 2");+ test(t =>+ assert_false(+ scriptTest3,+ "<script> element with attribute '<style' should not execute"),+ "Non-nonceable script element 3");+ test(t =>+ assert_false(+ scriptTest4,+ "<script> element with attribute '<stYlE' should not execute"),+ "Non-nonceable script element 4");+ test(t =>+ assert_false(+ scriptTest5,+ "<script> element with attribute '<link' should not execute"),+ "Non-nonceable script element 5");+ test(t =>+ assert_false(+ scriptTest6,+ "<script> element with attribute '<LinK' should not execute"),+ "Non-nonceable script element 6");+ test(t =>+ assert_false(+ scriptTest7,+ "<script> element with attribute 'aaa<sCripTbb' should not execute"),+ "Non-nonceable script element 7");+ test(t =>+ assert_false(+ scriptTest8,+ "<script> element with attribute 'aa<sTylEbbb' should not execute"),+ "Non-nonceable script element 8");+ test(t =>+ assert_false(+ scriptTest9,+ "<script> element with attribute 'cc<lInKddd' should not execute"),+ "Non-nonceable script element 9");+ </script>+</body>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-connected-after-set.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-connected-after-set.htmlnew file mode 100644index 00000000000..f7de1f704be--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-connected-after-set.html@@ -0,0 +1,39 @@+<!doctype html>+<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'; style-src 'self'">+<script nonce="abc" src="../../resources/testharness.js"></script>+<script nonce="abc" src="../../resources/testharnessreport.js"></script>++<div id="parent"></div>+<script nonce="abc">+ promise_test(async t => {+ var d = document.createElement("div");+ d.setAttribute("onclick", "void(0);");+ document.getElementById('parent').appendChild(d);++ const timeout_promise = () => new Promise((_, reject) => t.step_timeout(+ () => reject(new Error('Timed out waiting for securitypolicyviolation')), 1000));+ const get_failed_watchers = (results) => results.flatMap(+ (r, i) => r.status !== "fulfilled" ? [ `#${i}: ${r.reason}` ] : []);++ await Promise.allSettled([+ Promise.race([new EventWatcher(t, document, ["securitypolicyviolation"])+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 10);+ assert_in_array(e.columnNumber, [7, 19]);+ assert_equals(e.target, d);+ })),+ timeout_promise()]),+ Promise.race([new EventWatcher(t, d, ["securitypolicyviolation"])+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 10);+ assert_in_array(e.columnNumber, [7, 19]);+ assert_equals(e.target, d);+ })),+ timeout_promise()]),+ ]).then(t.step_func(results => {+ assert_array_equals(get_failed_watchers(results), []);+ }));+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-markup-disconnected-after-set.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-markup-disconnected-after-set.htmlnew file mode 100644index 00000000000..a9355f7be4a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-markup-disconnected-after-set.html@@ -0,0 +1,25 @@+<!doctype html>+<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'; style-src 'self'">+<script nonce="abc" src="../../resources/testharness.js"></script>+<script nonce="abc" src="../../resources/testharnessreport.js"></script>++<a id="target">Click me</a>+<script nonce="abc">+ promise_test(async t => {+ var a = document.getElementById("target");+ a.onsecuritypolicyviolation =+ t.unreached_func("Should not be dispatched on the disconnected target");+ a.setAttribute("onclick", "void(0);");+ a.parentNode.removeChild(a);++ const timeout_promise = () => new Promise(resolve => t.step_timeout(resolve, 1000));++ return new EventWatcher(t, document, ["securitypolicyviolation"], timeout_promise)+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 12);+ assert_in_array(e.columnNumber, [7, 19]);+ assert_equals(e.target, document);+ }));+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-shadow-dom.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-shadow-dom.htmlnew file mode 100644index 00000000000..57633726f17--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-in-shadow-dom.html@@ -0,0 +1,40 @@+<!doctype html>+<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'; style-src 'self'">+<script nonce="abc" src="../../resources/testharness.js"></script>+<script nonce="abc" src="../../resources/testharnessreport.js"></script>++<div id="target"></div>+<script nonce="abc">+ promise_test(async t => {+ var shadow = document.getElementById('target').attachShadow({"mode":"closed"});+ shadow.innerHTML = "<a id='shadow_target' onclick='void(0)'>Click!</a>";+ var a = shadow.getElementById('shadow_target');+ a.click();++ const timeout_promise = () => new Promise((_, reject) => t.step_timeout(+ () => reject(new Error('Timed out waiting for securitypolicyviolation')), 1000));+ const get_failed_watchers = (results) => results.flatMap(+ (r, i) => r.status !== "fulfilled" ? [ `#${i}: ${r.reason}` ] : []);++ await Promise.allSettled([+ Promise.race([new EventWatcher(t, document, ["securitypolicyviolation"])+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 10);+ assert_in_array(e.columnNumber, [5, 22]);+ assert_equals(e.target, document.getElementById('target'));+ })),+ timeout_promise()]),+ Promise.race([new EventWatcher(t, a, ["securitypolicyviolation"])+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 10);+ assert_in_array(e.columnNumber, [5, 22]);+ assert_equals(e.target, a);+ })),+ timeout_promise()]),+ ]).then(results => {+ assert_array_equals(get_failed_watchers(results), []);+ });+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-disconnected-element.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-disconnected-element.htmlnew file mode 100644index 00000000000..f43a55cabcc--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-disconnected-element.html@@ -0,0 +1,24 @@+<!doctype html>+<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'; style-src 'self'">+<script nonce="abc" src="../../resources/testharness.js"></script>+<script nonce="abc" src="../../resources/testharnessreport.js"></script>++<script nonce="abc">+ promise_test(async t => {+ var d = document.createElement("div");+ d.onsecuritypolicyviolation =+ t.unreached_func("Should not be dispatched on the disconnected element");+ d.setAttribute("onclick", "void(0);");+ d.click();++ const timeout_promise = () => new Promise(resolve => t.step_timeout(resolve, 1000));++ return new EventWatcher(t, document, ["securitypolicyviolation"], timeout_promise)+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 11);+ assert_in_array(e.columnNumber, [7, 19]);+ assert_equals(e.target, document);+ }));+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-element-in-disconnected-document-fragment.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-element-in-disconnected-document-fragment.htmlnew file mode 100644index 00000000000..1168b695474--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-element-in-disconnected-document-fragment.html@@ -0,0 +1,26 @@+<!doctype html>+<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'; style-src 'self'">+<script nonce="abc" src="../../resources/testharness.js"></script>+<script nonce="abc" src="../../resources/testharnessreport.js"></script>++<script nonce="abc">+ promise_test(async t => {+ var f = new DocumentFragment();+ var d = document.createElement("div");+ f.appendChild(d);+ d.onsecuritypolicyviolation =+ t.unreached_func("Should not be dispatched on the element in the disconnected DocumentFrame");+ d.setAttribute("onclick", "void(0);");+ d.click();++ const timeout_promise = () => new Promise(resolve => t.step_timeout(resolve, 1000));++ return new EventWatcher(t, document, ["securitypolicyviolation"], timeout_promise)+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 13);+ assert_in_array(e.columnNumber, [7, 19]);+ assert_equals(e.target, document);+ }));+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-main-frame-element-moved-to-subframe.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-main-frame-element-moved-to-subframe.htmlnew file mode 100644index 00000000000..aaa4fc5f702--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/securitypolicyviolation/targeting-for-inline-handler-on-main-frame-element-moved-to-subframe.html@@ -0,0 +1,28 @@+<!doctype html>+<meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'; style-src 'self'">+<script nonce="abc" src="../../resources/testharness.js"></script>+<script nonce="abc" src="../../resources/testharnessreport.js"></script>++<iframe id="subframe"></iframe>+<script nonce="abc">+ promise_test(async t => {+ var d = document.createElement("div");+ d.setAttribute("onclick", "void(0);");+ d.onsecuritypolicyviolation =+ t.unreached_func("Should not be dispatched on the target in the subframe");+ var subframe = document.getElementById('subframe');+ subframe.contentDocument.onsecuritypolicyviolation =+ t.unreached_func("Should not be dispatched on the subframe document");+ subframe.contentDocument.body.appendChild(d);++ const timeout_promise = () => new Promise(resolve => t.step_timeout(resolve, 1000));++ return new EventWatcher(t, document, ["securitypolicyviolation"], timeout_promise)+ .wait_for("securitypolicyviolation").then(t.step_func(e => {+ assert_equals(e.blockedURI, "inline");+ assert_equals(e.lineNumber, 10);+ assert_in_array(e.columnNumber, [7, 19]);+ assert_equals(e.target, document);+ }));+ });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href.htmlnew file mode 100644index 00000000000..2989afc7a1a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href.html@@ -0,0 +1,15 @@+<!DOCTYPE HTML>+<html>+<head>+ <meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'+ 'sha256-l0Wxf12cHMZT6UQ2zsQ7AcFSb6Y198d37Ki8zWITecM=';">+ <script src="../../resources/testharness.js" nonce="abc"></script>+ <script src="../../resources/testharnessreport.js" nonce="abc"></script>+ <script src="support/helper.js" nonce="abc"></script>+</head>+<body>+ <script nonce="abc">+ runTest(false, '<a href>', ' due to missing unsafe-hashes');+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank-script-src-elem.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank-script-src-elem.htmlnew file mode 100644index 00000000000..3d2526cb6f7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank-script-src-elem.html@@ -0,0 +1,15 @@+<!DOCTYPE HTML>+<html>+<head>+ <meta http-equiv="Content-Security-Policy" content="script-src-elem 'nonce-abc'+ 'sha256-N5bidCKdNO1nSPa1G7MdL6S7Y7MKZ7UMIS/40JBMSe4=';">+ <script src="../../resources/testharness.js" nonce="abc"></script>+ <script src="../../resources/testharnessreport.js" nonce="abc"></script>+ <script src="support/helper.js" nonce="abc"></script>+</head>+<body>+ <script nonce="abc">+ runTest(false, '<a href target=_blank>', ' due to missing unsafe-hashes');+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank.htmlnew file mode 100644index 00000000000..abe1299b64d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-href_blank.html@@ -0,0 +1,15 @@+<!DOCTYPE HTML>+<html>+<head>+ <meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'+ 'sha256-N5bidCKdNO1nSPa1G7MdL6S7Y7MKZ7UMIS/40JBMSe4=';">+ <script src="../../resources/testharness.js" nonce="abc"></script>+ <script src="../../resources/testharnessreport.js" nonce="abc"></script>+ <script src="support/helper.js" nonce="abc"></script>+</head>+<body>+ <script nonce="abc">+ runTest(false, '<a href target=_blank>', ' due to missing unsafe-hashes');+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-window_open.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-window_open.htmlnew file mode 100644index 00000000000..efaa7a6c884--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_missing_unsafe_hashes-window_open.html@@ -0,0 +1,30 @@+<!DOCTYPE HTML>+<html>++<head>+ <meta http-equiv="Content-Security-Policy" content="script-src 'nonce-abc'+ 'sha256-IIiAJ8UuliU8o1qAv6CV4P3R8DeTf/v3MrsCwXW171Y=';">+ <!--+ 'sha256-IIiAJ8UuliU8o1qAv6CV4P3R8DeTf/v3MrsCwXW171Y=' ==> 'javascript:opener.postMessage('pass', '*')'+ -->+ <script src='../../resources/testharness.js' nonce='abc'></script>+ <script src='../../resources/testharnessreport.js' nonce='abc'></script>+</head>++<body>+ <div id='log'></div>+ <script nonce='abc'>+ var t1 = async_test("Test that the javascript: src is not allowed to run");++ window.onmessage = t1.unreached_func("Should have not received any message");++ window.addEventListener('securitypolicyviolation', t1.step_func_done(function(e) {+ assert_equals(e.violatedDirective, 'script-src-elem');+ assert_equals(e.blockedURI, 'inline');+ }));++ window.open("javascript:opener.postMessage('pass', '*')");+ </script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href.htmlnew file mode 100644index 00000000000..996b67e465f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href.html@@ -0,0 +1,15 @@+<!DOCTYPE HTML>+<html>+<head>+ <meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-hashes' 'nonce-abc'+ 'sha256-wrongwrongwrongwrongwrongwrongwrongwrongwro=';">+ <script src="../../resources/testharness.js" nonce="abc"></script>+ <script src="../../resources/testharnessreport.js" nonce="abc"></script>+ <script src="support/helper.js" nonce="abc"></script>+</head>+<body>+ <script nonce="abc">+ runTest(false, '<a href>', ' due to wrong hash');+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank-script-src-elem.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank-script-src-elem.htmlnew file mode 100644index 00000000000..5cd6aa9269b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank-script-src-elem.html@@ -0,0 +1,15 @@+<!DOCTYPE HTML>+<html>+<head>+ <meta http-equiv="Content-Security-Policy" content="script-src-elem 'unsafe-hashes' 'nonce-abc'+ 'sha256-wrongwrongwrongwrongwrongwrongwrongwrongwro=';">+ <script src="../../resources/testharness.js" nonce="abc"></script>+ <script src="../../resources/testharnessreport.js" nonce="abc"></script>+ <script src="support/helper.js" nonce="abc"></script>+</head>+<body>+ <script nonce="abc">+ runTest(false, '<a href target=_blank>', ' due to wrong hash');+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank.htmlnew file mode 100644index 00000000000..8c9c29d7c31--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-href_blank.html@@ -0,0 +1,15 @@+<!DOCTYPE HTML>+<html>+<head>+ <meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-hashes' 'nonce-abc'+ 'sha256-wrongwrongwrongwrongwrongwrongwrongwrongwro=';">+ <script src="../../resources/testharness.js" nonce="abc"></script>+ <script src="../../resources/testharnessreport.js" nonce="abc"></script>+ <script src="support/helper.js" nonce="abc"></script>+</head>+<body>+ <script nonce="abc">+ runTest(false, '<a href target=_blank>', ' due to wrong hash');+ </script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-window_open.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-window_open.htmlnew file mode 100644index 00000000000..d36a06028c5--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/javascript_src_denied_wrong_hash-window_open.html@@ -0,0 +1,30 @@+<!DOCTYPE HTML>+<html>++<head>+ <meta http-equiv="Content-Security-Policy" content="script-src 'unsafe-hashes' 'nonce-abc'+ 'sha256-VjH6k67F4kobUnNDOBE85QiJ9cuZMiYT6desKXvezVg=';">+ <!--+ 'sha256-IIiAJ8UuliU8o1qAv6CV4P3R8DeTf/v3MrsCwXW171Y=' ==> 'javascript:opener.postMessage('pass', '*')'+ -->+ <script src='../../resources/testharness.js' nonce='abc'></script>+ <script src='../../resources/testharnessreport.js' nonce='abc'></script>+</head>++<body>+ <div id='log'></div>+ <script nonce='abc'>+ var t1 = async_test("Test that the javascript: src is not allowed to run");++ window.onmessage = t1.unreached_func("Should have not received any message");++ window.addEventListener('securitypolicyviolation', t1.step_func_done(function(e) {+ assert_equals(e.violatedDirective, 'script-src-elem');+ assert_equals(e.blockedURI, 'inline');+ }));++ window.open("javascript:opener.postMessage('pass', '*')");+ </script>+</body>++</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/support/helper.js b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/support/helper.jsnew file mode 100644index 00000000000..26db3289ea3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/unsafe-hashes/support/helper.js@@ -0,0 +1,40 @@+// Typical CSP hashes are:+// 'sha256-N5bidCKdNO1nSPa1G7MdL6S7Y7MKZ7UMIS/40JBMSe4=' ==> javascript:opener.navigated();+// 'sha256-l0Wxf12cHMZT6UQ2zsQ7AcFSb6Y198d37Ki8zWITecM=' ==> javascript:navigated();++function runTest(navigationShouldAllowed, navigationMethod, description) {+ const t1 = async_test(+ 'javascript: navigation using ' + navigationMethod + ' should be ' ++ (navigationShouldAllowed ? 'allowed' : 'refused') + description);++ if (navigationShouldAllowed) {+ window.navigated = () => t1.done();+ window.addEventListener('securitypolicyviolation',+ t1.unreached_func('Should have not raised any event'));+ } else {+ window.navigated =+ t1.unreached_func('Should not have run javascript: URL');+ window.addEventListener('securitypolicyviolation',+ t1.step_func_done(function(e) {+ assert_equals(e.violatedDirective, 'script-src-elem');+ assert_equals(e.blockedURI, 'inline');+ }));+ }++ if (navigationMethod === '<a href target=_blank>') {+ const a = document.createElement('a');+ a.setAttribute('target', '_blank');+ a.setAttribute('rel', 'opener');+ a.setAttribute('href', 'javascript:opener.navigated();');+ document.body.appendChild(a);+ a.click();+ }+ else if (navigationMethod === '<a href>') {+ const a = document.createElement('a');+ a.setAttribute('href', 'javascript:navigated();');+ document.body.appendChild(a);+ a.click();+ } else {+ t1.unreached_func('Invalid navigationMethod: ' + navigationMethod)();+ }+}