Skip to content

Commit 6f85fa4

Browse files
fred-wangmoz-wptsync-bot
authored andcommitted
Add tests for location of sink mismatch violation in workers.
Differential Revision: https://phabricator.services.mozilla.com/D243067 bugzilla-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1956424 gecko-commit: 62e51640e81489440a4c6caafe5ec7fe97005987 gecko-reviewers: smaug
1 parent 07e7c98 commit 6f85fa4

9 files changed

+61
-7
lines changed

lint.ignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ SET TIMEOUT: shadow-dom/scroll-to-the-fragment-in-shadow-tree.html
287287
SET TIMEOUT: shadow-dom/slotchange-event.html
288288
SET TIMEOUT: trusted-types/support/block-string-assignment-to-DOMWindowTimers-setTimeout-setInterval.js
289289
SET TIMEOUT: trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js
290-
SET TIMEOUT: trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker.js
290+
SET TIMEOUT: trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker-multiple-violations.js
291+
SET TIMEOUT: trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-location.js
291292
SET TIMEOUT: trusted-types/support/trusted-types-reporting-check-report-sink-mismatch.js
292293
SET TIMEOUT: trusted-types/support/trusted-types-reporting-for-DOMWindowTimers-setTimeout-setInterval.js
293294
SET TIMEOUT: user-timing/*

trusted-types/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@
44
<script src="/resources/testharness.js"></script>
55
<script src="/resources/testharnessreport.js"></script>
66
<script>
7-
fetch_tests_from_worker(new Worker(
8-
"support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker.js"
9-
));
7+
// WebKit test runner assumes the tests always run in the same order, so make
8+
// sure fetch_tests_from_worker tests run sequentially.
9+
setup({explicit_done: true});
10+
(async function() {
11+
await fetch_tests_from_worker(new Worker(
12+
"support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker-multiple-violations.js"
13+
));
14+
await fetch_tests_from_worker(new Worker(
15+
"support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker-location.js"
16+
));
17+
done();
18+
})();
1019
</script>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!DOCTYPE html>
2+
<meta charset="UTF-8">
3+
<meta name="timeout" content="long">
4+
<script src="/resources/testharness.js"></script>
5+
<script src="/resources/testharnessreport.js"></script>
6+
<script src="./support/csp-violations.js"></script>
7+
<script src="./support/should-sink-type-mismatch-violation-be-blocked-by-csp-location.js"></script>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Content-Security-Policy: connect-src 'none'
2+
Content-Security-Policy: require-trusted-types-for 'script'
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const testSetupPolicy = trustedTypes.createPolicy("testSetupPolicy", {
2+
createScriptURL: s => s });
3+
4+
importScripts(testSetupPolicy.createScriptURL("/resources/testharness.js"));
5+
importScripts(testSetupPolicy.createScriptURL("csp-violations.js"));
6+
7+
// For CSP applying to this file, please refer to
8+
// should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker-location.js.headers
9+
10+
importScripts(testSetupPolicy.createScriptURL("should-sink-type-mismatch-violation-be-blocked-by-csp-location.js"));
11+
12+
done();
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Content-Security-Policy: connect-src 'none'
2+
Content-Security-Policy: require-trusted-types-for 'script'

trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker.js renamed to trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker-multiple-violations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ importScripts(testSetupPolicy.createScriptURL("/resources/testharness.js"));
55
importScripts(testSetupPolicy.createScriptURL("csp-violations.js"));
66

77
// For CSP applying to this file, please refer to
8-
// should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker.js.headers
8+
// should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker-multiple-violations.js.headers
99

1010
promise_test(async () => {
11-
let {violations, exception} = await trusted_type_violations_and_exception_for(_ => setTimeout("unsafe"));
11+
let {violations, exception} = await trusted_type_violations_and_exception_for(_ => setTimeout(";;;;;"));
1212

1313
// An exception is thrown for the violated enforced policies.
1414
assert_true(exception instanceof TypeError, "TypeError is thrown");
@@ -30,6 +30,6 @@ promise_test(async () => {
3030
assert_equals(sorted_violations[4].disposition, "report");
3131
assert_equals(sorted_violations[5].policy, "require-trusted-types-for 'invalid' 'script'");
3232
assert_equals(sorted_violations[5].disposition, "report");
33-
}, "Checking reported violations for setTimeout('unsafe') from DedicatedWorker");
33+
}, "Checking reported violations for setTimeout(';;;;;') from DedicatedWorker");
3434

3535
done();

trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker.js.headers renamed to trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-002-worker-multiple-violations.js.headers

File renamed without changes.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function passPlainStringToTrustedTypeSink() { // 1
2+
return trusted_type_violation_for(TypeError, _ => // 2
3+
setTimeout (";;;;;;;;;;;;;;;;;;;;;;;;;;;;;") //_3
4+
/* |
5+
12345678901234567890
6+
*/
7+
);
8+
}
9+
10+
promise_test(async () => {
11+
let violation = await passPlainStringToTrustedTypeSink();
12+
let baseURL = (new URL(location.href)).origin;
13+
let sourceFile = new URL("/trusted-types/support/should-sink-type-mismatch-violation-be-blocked-by-csp-location.js", baseURL).toString();
14+
assert_equals(violation.sourceFile, sourceFile, "source file");
15+
assert_equals(violation.lineNumber, 3, "line number");
16+
// https://w3c.github.io/webappsec-csp/#create-violation-for-global does not
17+
// say how to determine the location and browsers provide inconsistent values
18+
// for column number, so just check it's at least the offset of the 's'
19+
// character of setTimeout.
20+
assert_greater_than_equal(violation.columnNumber, 5, "column number");
21+
} , `Location of required-trusted-types-for violations.`);

0 commit comments

Comments
 (0)