Truly independent web browser
LibWeb: Cover Trusted Types eval source expressions
Andreas Kling429801f4b707
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex b942804e238..3720a4a3668 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -47,6 +47,9 @@ Text/input/wpt-import/html/semantics/scripting-1/the-script-element/module/dynamText/input/wpt-import/html/semantics/scripting-1/the-script-element/module/dynamic-import/propagate-nonce-inline-module.html; Resource loading tests use WPT Python handlers, substitutions, or .headers files.+Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.html+Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval.html+Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.htmlText/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-01.htmlText/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-quirks.htmlText/input/wpt-import/html/semantics/document-metadata/the-link-element/link-style-error-limited-quirks.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.txtnew file mode 100644index 00000000000..55e817d8059--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 5 tests++5 Pass+Pass Scripts injected via direct `eval` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.+Pass Scripts injected via indirect `eval` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.+Pass Scripts injected via `new Function` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.+Pass Scripts injected via `setTimeout` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.+Pass Scripts injected via `setInterval` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.txtnew file mode 100644index 00000000000..90c2ded3274--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 5 tests++5 Fail+Fail Script injected via direct `eval` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.+Fail Script injected via indirect `eval` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.+Fail Script injected via `new Function` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.+Fail Script injected via `setTimeout` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.+Fail Script injected via `setInterval` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@default.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@default.txtnew file mode 100644index 00000000000..36a9cdd6426--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@default.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 5 tests++5 Pass+Pass Scripts injected via direct `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via indirect `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `new Function` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setTimeout` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setInterval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@double-quoted.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@double-quoted.txtnew file mode 100644index 00000000000..36a9cdd6426--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@double-quoted.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 5 tests++5 Pass+Pass Scripts injected via direct `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via indirect `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `new Function` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setTimeout` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setInterval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@unquoted.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@unquoted.txtnew file mode 100644index 00000000000..36a9cdd6426--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@unquoted.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 5 tests++5 Pass+Pass Scripts injected via direct `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via indirect `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `new Function` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setTimeout` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setInterval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@uppercase.txt b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@uppercase.txtnew file mode 100644index 00000000000..36a9cdd6426--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval@uppercase.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 5 tests++5 Pass+Pass Scripts injected via direct `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via indirect `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `new Function` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setTimeout` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.+Pass Scripts injected via `setInterval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/eval-csp-tt-default-policy-mutate.txt b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]similarity index 100%rename from Tests/LibWeb/Text/expected/wpt-import/trusted-types/eval-csp-tt-default-policy-mutate.txtrename to Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]diff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]new file mode 100644index 00000000000..3fb7e2d3380--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]@@ -0,0 +1,11 @@+Harness status: OK++Found 6 tests++6 Pass+Pass eval of string where default policy mutates value throws.+Pass indirect eval of string where default policy mutates value throws.+Pass Function constructor with string where default policy mutates value throws.+Pass AsyncFunction constructor with string where default policy mutates value throws.+Pass GeneratorFunction constructor with string where default policy mutates value throws.+Pass AsyncGeneratorFunction constructor with string where default policy mutates value throws.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/eval-csp-tt-default-policy.txt b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]similarity index 100%rename from Tests/LibWeb/Text/expected/wpt-import/trusted-types/eval-csp-tt-default-policy.txtrename to Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]diff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]new file mode 100644index 00000000000..79d68b2558b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]@@ -0,0 +1,30 @@+Harness status: OK++Found 24 tests++1 Pass+23 Fail+Fail eval of TrustedScript works.+Fail indirect eval of TrustedScript works.+Fail eval of string works.+Pass eval of !TrustedScript and !string works.+Fail Function constructor of TrustedScript works.+Fail Function constructor of string works.+Fail Function constructor of all TrustedScripts works.+Fail Function constructor of all strings works.+Fail Function constructor of string and TrustedScript works.+Fail Async Function constructor of TrustedScript works.+Fail AsyncFunction constructor of string works.+Fail AsyncFunction constructor of all TrustedScripts works.+Fail AsyncFunction constructor of all strings works.+Fail AsyncFunction constructor of string and TrustedScript works.+Fail GeneratorFunction constructor of TrustedScript works.+Fail GeneratorFunction constructor of string works.+Fail GeneratorFunction constructor of all TrustedScripts works.+Fail GeneratorFunction constructor of all strings works.+Fail GeneratorFunction constructor of string and TrustedScript works.+Fail AsyncGeneratorFunction constructor of TrustedScript works.+Fail AsyncGeneratorFunction constructor of string works.+Fail AsyncGeneratorFunction constructor of all TrustedScripts works.+Fail AsyncGeneratorFunction constructor of all strings works.+Fail AsyncGeneratorFunction constructor of string and TrustedScript works.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/eval-csp-tt-no-default-policy.txt b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]similarity index 100%rename from Tests/LibWeb/Text/expected/wpt-import/trusted-types/eval-csp-tt-no-default-policy.txtrename to Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]diff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]new file mode 100644index 00000000000..9a603f7605e--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]@@ -0,0 +1,19 @@+Harness status: OK++Found 13 tests++9 Pass+4 Fail+Fail eval of TrustedScript works.+Fail indirect eval of TrustedScript works.+Pass eval of string fails.+Pass indirect eval of string fails.+Pass eval of !TrustedScript and !string works.+Fail Function constructor of TrustedScript works.+Pass Function constructor of string fails.+Fail Function constructor of all TrustedScripts works.+Pass Function constructor of all strings fails.+Pass Function constructor of string and TrustedScript fails.+Pass AsyncFunction constructor of string fails.+Pass GeneratorFunction constructor of string fails.+Pass AsyncGeneratorFunction constructor of string fails.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]new file mode 100644index 00000000000..d163620090a--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]@@ -0,0 +1,13 @@+Harness status: OK++Found 8 tests++8 Pass+Pass setTimeout of string accepted by the default policy runs.+Pass setInterval of string accepted by the default policy runs.+Pass setTimeout of string rejected by the default policy throws.+Pass setInterval of string rejected by the default policy throws.+Pass setTimeout of string where the default policy throws rethrows the exception.+Pass setInterval of string where the default policy throws rethrows the exception.+Pass setTimeout of string changed by the default policy runs the changed string.+Pass setInterval of string changed by the default policy runs the changed string.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-default-policy@trusted-types-eval.txt b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-default-policy@trusted-types-eval.txtnew file mode 100644index 00000000000..a457fb535ef--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-default-policy@trusted-types-eval.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 8 tests++4 Pass+4 Fail+Fail setTimeout of string accepted by the default policy runs.+Fail setInterval of string accepted by the default policy runs.+Pass setTimeout of string rejected by the default policy throws.+Pass setInterval of string rejected by the default policy throws.+Pass setTimeout of string where the default policy throws rethrows the exception.+Pass setInterval of string where the default policy throws rethrows the exception.+Fail setTimeout of string changed by the default policy runs the changed string.+Fail setInterval of string changed by the default policy runs the changed string.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected] b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]new file mode 100644index 00000000000..6e76f5e3a94--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/[email protected]@@ -0,0 +1,9 @@+Harness status: OK++Found 4 tests++4 Pass+Pass setTimeout of string throws.+Pass setInterval of string throws.+Pass setTimeout of TrustedScript runs.+Pass setInterval of TrustedScript runs.\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-no-default-policy@trusted-types-eval.txt b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-no-default-policy@trusted-types-eval.txtnew file mode 100644index 00000000000..9d38ed37c0b--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-no-default-policy@trusted-types-eval.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++2 Pass+2 Fail+Pass setTimeout of string throws.+Pass setInterval of string throws.+Fail setTimeout of TrustedScript runs.+Fail setInterval of TrustedScript runs.\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.htmlnew file mode 100644index 00000000000..b62ca483050--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.html@@ -0,0 +1,106 @@+<!DOCTYPE HTML>+<html>++<head>+ <title>Scripts injected via `eval` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.</title>+ <script src='../../resources/testharness.js' nonce='dummy'></script>+ <script src='../../resources/testharnessreport.js' nonce='dummy'></script>++ <!-- CSP served: script-src 'nonce-dummy' 'trusted-types-eval' -->+ <!-- Report Only CSP served: require-trusted-types-for 'script' -->+</head>++<body>+ <script nonce='dummy'>+ trustedTypes.createPolicy('default', { createScript: s => s });++ promise_test(t => {+ globalThis.evalScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ assert_false(globalThis.evalScriptRan);+ });+ assert_throws_js(Error, () => {+ try {+ eval("globalThis.evalScriptRan = true;");+ } catch (e) {+ throw new Error();+ }+ });+ return violation;+ }, "Scripts injected via direct `eval` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.");++ promise_test(t => {+ globalThis.indirectEvalScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ assert_false(globalThis.indirectEvalScriptRan);+ });+ assert_throws_js(Error, () => {+ try {+ eval?.("globalThis.indirectEvalScriptRan = true;");+ } catch (e) {+ throw new Error();+ }+ });+ return violation;+ }, "Scripts injected via indirect `eval` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.");++ promise_test(t => {+ globalThis.functionScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ assert_false(globalThis.functionScriptRan);+ });+ assert_throws_js(Error, () => {+ try {+ new Function("globalThis.functionScriptRan = true;")();+ } catch (e) {+ throw new Error();+ }+ });+ return violation;+ }, "Scripts injected via `new Function` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.");++ promise_test(t => {+ globalThis.setTimeoutScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ })+ .then(() => assert_false(globalThis.setTimeoutScriptRan));+ const id = setTimeout("globalThis.setTimeoutScriptRan = true;", 0);+ t.add_cleanup(() => clearTimeout(id));+ assert_equals(id, 0);+ return violation;+ }, "Scripts injected via `setTimeout` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.");++ promise_test(t => {+ globalThis.setIntervalScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ })+ .then(() => assert_false(globalThis.setIntervalScriptRan));+ const id = setInterval("globalThis.setIntervalScriptRan = true;", 0);+ t.add_cleanup(() => clearInterval(id));+ assert_equals(id, 0);+ return violation;+ }, "Scripts injected via `setInterval` are not allowed with `trusted-types-eval` when `require-trusted-types-for 'script'` is report only.");+ </script>+</body>++</html>\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.html.headers b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.html.headersnew file mode 100644index 00000000000..ae1e09e31ea--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_report_only_require_trusted_types_eval.html.headers@@ -0,0 +1,6 @@+Expires: Mon, 26 Jul 1997 05:00:00 GMT+Cache-Control: no-store, no-cache, must-revalidate+Cache-Control: post-check=0, pre-check=0, false+Pragma: no-cache+Content-Security-Policy: script-src 'nonce-dummy' 'trusted-types-eval'+Content-Security-Policy-Report-Only: require-trusted-types-for 'script';diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.htmlnew file mode 100644index 00000000000..c78e64dc906--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.html@@ -0,0 +1,61 @@+<!DOCTYPE HTML>+<html>++<head>+ <title>Scripts injected via `eval` are allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.</title>+ <script src='../../resources/testharness.js' nonce='dummy'></script>+ <script src='../../resources/testharnessreport.js' nonce='dummy'></script>++ <!-- CSP served: script-src 'nonce-dummy' 'trusted-types-eval'; require-trusted-types-for 'script'; -->+</head>++<body>+ <script nonce='dummy'>+ let finishTimerTest;+ trustedTypes.createPolicy('default', {createScript: s => s});++ test(t => {+ globalThis.evalScriptRan = false;+ eval("globalThis.evalScriptRan = true;");+ assert_true(globalThis.evalScriptRan);+ }, "Script injected via direct `eval` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.");++ test(t => {+ globalThis.indirectEvalScriptRan = false;+ eval?.("globalThis.indirectEvalScriptRan = true;");+ assert_true(globalThis.indirectEvalScriptRan);+ }, "Script injected via indirect `eval` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.");++ test(t => {+ globalThis.functionScriptRan = false;+ new Function("globalThis.functionScriptRan = true;")();+ assert_true(globalThis.functionScriptRan);+ }, "Script injected via `new Function` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.");++ promise_test(t => {+ globalThis.setTimeoutScriptRan = false;+ const executed = new Promise(resolve => { finishTimerTest = resolve; });+ const id = setTimeout("globalThis.setTimeoutScriptRan = true; finishTimerTest();", 0);+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearTimeout(id));+ return executed.then(() => assert_true(globalThis.setTimeoutScriptRan));+ }, "Script injected via `setTimeout` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.");++ promise_test(t => {+ globalThis.setIntervalScriptRan = false;+ let id;+ const executed = new Promise(resolve => {+ finishTimerTest = () => {+ clearInterval(id);+ resolve();+ };+ });+ id = setInterval("globalThis.setIntervalScriptRan = true; finishTimerTest();", 0);+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearInterval(id));+ return executed.then(() => assert_true(globalThis.setIntervalScriptRan));+ }, "Script injected via `setInterval` is allowed with `trusted-types-eval` and `require-trusted-types-for 'script'`.");+ </script>+</body>++</html>\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.html.headers b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.html.headersnew file mode 100644index 00000000000..3e51fcd4741--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_with_require_trusted_types_eval.html.headers@@ -0,0 +1,5 @@+Expires: Mon, 26 Jul 1997 05:00:00 GMT+Cache-Control: no-store, no-cache, must-revalidate+Cache-Control: post-check=0, pre-check=0, false+Pragma: no-cache+Content-Security-Policy: script-src 'nonce-dummy' 'trusted-types-eval'; require-trusted-types-for 'script';diff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval.html b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval.htmlnew file mode 100644index 00000000000..c7bf5e907c7--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval.html@@ -0,0 +1,121 @@+<!DOCTYPE HTML>+<html>++<head>+ <meta name="variant" content="?default">+ <meta name="variant" content="?unquoted">+ <meta name="variant" content="?double-quoted">+ <meta name="variant" content="?uppercase">+ <title>Scripts injected via `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.</title>+ <script src='../../resources/testharness.js' nonce='dummy'></script>+ <script src='../../resources/testharnessreport.js' nonce='dummy'></script>++ <!-- CSP served: script-src 'nonce-dummy' 'trusted-types-eval' -->+</head>++<body>+ <script nonce='dummy'>+ const invalidRequirements = {+ "?unquoted": "script",+ "?double-quoted": '"script"',+ "?uppercase": "'SCRIPT'",+ };+ const invalidRequirement = invalidRequirements[location.search];+ if (invalidRequirement !== undefined) {+ const meta = document.createElement("meta");+ meta.httpEquiv = "Content-Security-Policy";+ meta.content = `require-trusted-types-for ${invalidRequirement}`;+ document.head.appendChild(meta);+ }+ trustedTypes.createPolicy('default', {createScript: source => source});++ promise_test(t => {+ globalThis.evalScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ assert_false(globalThis.evalScriptRan);+ });+ assert_throws_js(Error, () => {+ try {+ eval("globalThis.evalScriptRan = true;");+ } catch (e) {+ throw new Error();+ }+ });+ return violation;+ }, "Scripts injected via direct `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.");++ promise_test(t => {+ globalThis.indirectEvalScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ assert_false(globalThis.indirectEvalScriptRan);+ });+ assert_throws_js(Error, () => {+ try {+ eval?.("globalThis.indirectEvalScriptRan = true;");+ } catch (e) {+ throw new Error();+ }+ });+ return violation;+ }, "Scripts injected via indirect `eval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.");++ promise_test(t => {+ globalThis.functionScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ assert_false(globalThis.functionScriptRan);+ });+ assert_throws_js(Error, () => {+ try {+ new Function("globalThis.functionScriptRan = true;")();+ } catch (e) {+ throw new Error();+ }+ });+ return violation;+ }, "Scripts injected via `new Function` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.");++ promise_test(t => {+ globalThis.setTimeoutScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ })+ .then(() => assert_false(globalThis.setTimeoutScriptRan));+ const id = setTimeout("globalThis.setTimeoutScriptRan = true;", 0);+ t.add_cleanup(() => clearTimeout(id));+ assert_equals(id, 0);+ return violation;+ }, "Scripts injected via `setTimeout` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.");++ promise_test(t => {+ globalThis.setIntervalScriptRan = false;+ const violation = new EventWatcher(t, self, 'securitypolicyviolation')+ .wait_for('securitypolicyviolation')+ .then(e => {+ assert_equals(e.effectiveDirective, 'script-src');+ assert_equals(e.blockedURI, 'eval');+ })+ .then(() => assert_false(globalThis.setIntervalScriptRan));+ const id = setInterval("globalThis.setIntervalScriptRan = true;", 0);+ t.add_cleanup(() => clearInterval(id));+ assert_equals(id, 0);+ return violation;+ }, "Scripts injected via `setInterval` are not allowed with `trusted-types-eval` without `require-trusted-types-for 'script'`.");+ </script>+</body>++</html>\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval.html.headers b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval.html.headersnew file mode 100644index 00000000000..5658b5ab2de--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/content-security-policy/script-src/script-src-trusted_types_eval_without_require_trusted_types_eval.html.headers@@ -0,0 +1,5 @@+Expires: Mon, 26 Jul 1997 05:00:00 GMT+Cache-Control: no-store, no-cache, must-revalidate+Cache-Control: post-check=0, pre-check=0, false+Pragma: no-cache+Content-Security-Policy: script-src 'nonce-dummy' 'trusted-types-eval'diff --git a/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy-mutate.html b/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy-mutate.htmlindex a8a0f686091..f05995c62b5 100644--- a/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy-mutate.html+++ b/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy-mutate.html@@ -1,13 +1,23 @@<!DOCTYPE html><html><head>+ <meta name="variant" content="?default">+ <meta name="variant" content="?trusted-types-eval"><script nonce="abc" src="../resources/testharness.js"></script><script nonce="abc" src="../resources/testharnessreport.js"></script><script nonce="abc" src="support/helper.sub.js"></script><meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'">+ <script nonce="abc">+ if (location.search === "?trusted-types-eval") {+ const meta = document.createElement("meta");+ meta.httpEquiv = "Content-Security-Policy";+ meta.content = "script-src 'nonce-abc' 'trusted-types-eval'";+ document.head.appendChild(meta);+ }+ </script></head><body>-<script>+<script nonce="abc">trustedTypes.createPolicy("default", {createScript: s => s.replace("1", "4")});test(t => {diff --git a/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy.html b/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy.htmlindex 9ee0fbb551a..e91850d3663 100644--- a/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy.html+++ b/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-default-policy.html@@ -1,13 +1,23 @@<!DOCTYPE html><html><head>+ <meta name="variant" content="?default">+ <meta name="variant" content="?trusted-types-eval"><script nonce="abc" src="../resources/testharness.js"></script><script nonce="abc" src="../resources/testharnessreport.js"></script><script nonce="abc" src="support/helper.sub.js"></script><meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'">+ <script nonce="abc">+ if (location.search === "?trusted-types-eval") {+ const meta = document.createElement("meta");+ meta.httpEquiv = "Content-Security-Policy";+ meta.content = "script-src 'nonce-abc' 'trusted-types-eval'";+ document.head.appendChild(meta);+ }+ </script></head><body>-<script>+<script nonce="abc">trustedTypes.createPolicy("default", {createScript: ((s, _, sink) => {// eval's source string is "1+1", the Function constructor's source string is "return 1+1"diff --git a/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-no-default-policy.html b/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-no-default-policy.htmlindex afcb5a33c67..cfceb367057 100644--- a/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-no-default-policy.html+++ b/Tests/LibWeb/Text/input/wpt-import/trusted-types/eval-csp-tt-no-default-policy.html@@ -1,13 +1,23 @@<!DOCTYPE html><html><head>+ <meta name="variant" content="?default">+ <meta name="variant" content="?trusted-types-eval"><script nonce="abc" src="../resources/testharness.js"></script><script nonce="abc" src="../resources/testharnessreport.js"></script><script nonce="abc" src="support/helper.sub.js"></script><meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';">+ <script nonce="abc">+ if (location.search === "?trusted-types-eval") {+ const meta = document.createElement("meta");+ meta.httpEquiv = "Content-Security-Policy";+ meta.content = "script-src 'nonce-abc' 'trusted-types-eval'";+ document.head.appendChild(meta);+ }+ </script></head><body>-<script>+<script nonce="abc">const p = trustedTypes.createPolicy("p", {createScript: s => s});test(t => {diff --git a/Tests/LibWeb/Text/input/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-default-policy.html b/Tests/LibWeb/Text/input/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-default-policy.htmlnew file mode 100644index 00000000000..4c54c5ff562--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-default-policy.html@@ -0,0 +1,119 @@+<!DOCTYPE html>+<html>+<head>+ <meta name="variant" content="?default">+ <meta name="variant" content="?trusted-types-eval">+ <script nonce="abc" src="../resources/testharness.js"></script>+ <script nonce="abc" src="../resources/testharnessreport.js"></script>+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'">+ <script nonce="abc">+ // With 'trusted-types-eval' and an enforced require-trusted-types-for+ // 'script', the results must be the same as without a script-src.+ if (location.search === "?trusted-types-eval") {+ const meta = document.createElement("meta");+ meta.httpEquiv = "Content-Security-Policy";+ meta.content = "script-src 'nonce-abc' 'trusted-types-eval'";+ document.head.appendChild(meta);+ }+ </script>+</head>+<body>+<script nonce="abc">+ let finishTimerTest;+ const policy_error = new Error("createScript exception");++ trustedTypes.createPolicy("default", {+ createScript: s => {+ if (s.includes("reject")) return null;+ if (s.includes("throw")) throw policy_error;+ if (s.includes("mutate")) return s.replace("mutate", "mutated");+ return s;+ }+ });++ // Strings accepted by the default policy run.+ promise_test(async t => {+ globalThis.timeoutAccepted = false;+ await new Promise(resolve => {+ finishTimerTest = resolve;+ const id = setTimeout('globalThis.timeoutAccepted = true; finishTimerTest()');+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearTimeout(id));+ });+ assert_true(globalThis.timeoutAccepted);+ }, "setTimeout of string accepted by the default policy runs.");++ promise_test(async t => {+ globalThis.intervalAccepted = false;+ await new Promise(resolve => {+ let id;+ finishTimerTest = () => {+ clearInterval(id);+ resolve();+ };+ id = setInterval('globalThis.intervalAccepted = true; finishTimerTest()');+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearInterval(id));+ });+ assert_true(globalThis.intervalAccepted);+ }, "setInterval of string accepted by the default policy runs.");++ // Strings rejected by the default policy are blocked.+ test(t => {+ globalThis.timeoutRejected = false;+ assert_throws_js(TypeError,+ () => setTimeout('globalThis.timeoutRejected = true; // reject'));+ assert_false(globalThis.timeoutRejected);+ }, "setTimeout of string rejected by the default policy throws.");++ test(t => {+ globalThis.intervalRejected = false;+ assert_throws_js(TypeError,+ () => setInterval('globalThis.intervalRejected = true; // reject'));+ assert_false(globalThis.intervalRejected);+ }, "setInterval of string rejected by the default policy throws.");++ // When the default policy throws, its exception is rethrown.+ test(t => {+ globalThis.timeoutThrown = false;+ assert_throws_exactly(policy_error,+ () => setTimeout('globalThis.timeoutThrown = true; // throw'));+ assert_false(globalThis.timeoutThrown);+ }, "setTimeout of string where the default policy throws rethrows the exception.");++ test(t => {+ globalThis.intervalThrown = false;+ assert_throws_exactly(policy_error,+ () => setInterval('globalThis.intervalThrown = true; // throw'));+ assert_false(globalThis.intervalThrown);+ }, "setInterval of string where the default policy throws rethrows the exception.");++ // When the default policy changes the string, the changed string runs.+ promise_test(async t => {+ globalThis.timeoutMutated = "";+ await new Promise(resolve => {+ finishTimerTest = resolve;+ const id = setTimeout('globalThis.timeoutMutated = "mutate"; finishTimerTest()');+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearTimeout(id));+ });+ assert_equals(globalThis.timeoutMutated, "mutated");+ }, "setTimeout of string changed by the default policy runs the changed string.");++ promise_test(async t => {+ globalThis.intervalMutated = "";+ await new Promise(resolve => {+ let id;+ finishTimerTest = () => {+ clearInterval(id);+ resolve();+ };+ id = setInterval('globalThis.intervalMutated = "mutate"; finishTimerTest()');+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearInterval(id));+ });+ assert_equals(globalThis.intervalMutated, "mutated");+ }, "setInterval of string changed by the default policy runs the changed string.");+</script>+</body>+</html>diff --git a/Tests/LibWeb/Text/input/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-no-default-policy.html b/Tests/LibWeb/Text/input/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-no-default-policy.htmlnew file mode 100644index 00000000000..3422578b97a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/trusted-types/setTimeout-setInterval-csp-tt-no-default-policy.html@@ -0,0 +1,68 @@+<!DOCTYPE html>+<html>+<head>+ <meta name="variant" content="?default">+ <meta name="variant" content="?trusted-types-eval">+ <script nonce="abc" src="../resources/testharness.js"></script>+ <script nonce="abc" src="../resources/testharnessreport.js"></script>+ <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script'">+ <script nonce="abc">+ // With 'trusted-types-eval' and an enforced require-trusted-types-for+ // 'script', the results must be the same as without a script-src.+ if (location.search === "?trusted-types-eval") {+ const meta = document.createElement("meta");+ meta.httpEquiv = "Content-Security-Policy";+ meta.content = "script-src 'nonce-abc' 'trusted-types-eval'";+ document.head.appendChild(meta);+ }+ </script>+</head>+<body>+<script nonce="abc">+ let finishTimerTest;+ const p = trustedTypes.createPolicy("p", {createScript: s => s});++ // Strings are rejected, since there is no default policy to convert them.+ test(t => {+ globalThis.timeoutString = false;+ assert_throws_js(TypeError,+ () => setTimeout('globalThis.timeoutString = true'));+ assert_false(globalThis.timeoutString);+ }, "setTimeout of string throws.");++ test(t => {+ globalThis.intervalString = false;+ assert_throws_js(TypeError,+ () => setInterval('globalThis.intervalString = true'));+ assert_false(globalThis.intervalString);+ }, "setInterval of string throws.");++ // TrustedScript values run.+ promise_test(async t => {+ globalThis.timeoutTrustedScript = false;+ await new Promise(resolve => {+ finishTimerTest = resolve;+ const id = setTimeout(p.createScript('globalThis.timeoutTrustedScript = true; finishTimerTest()'));+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearTimeout(id));+ });+ assert_true(globalThis.timeoutTrustedScript);+ }, "setTimeout of TrustedScript runs.");++ promise_test(async t => {+ globalThis.intervalTrustedScript = false;+ await new Promise(resolve => {+ let id;+ finishTimerTest = () => {+ clearInterval(id);+ resolve();+ };+ id = setInterval(p.createScript('globalThis.intervalTrustedScript = true; finishTimerTest()'));+ assert_greater_than(id, 0);+ t.add_cleanup(() => clearInterval(id));+ });+ assert_true(globalThis.intervalTrustedScript);+ }, "setInterval of TrustedScript runs.");+</script>+</body>+</html>