Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross origin workers should fail to fetch #13671

Merged
merged 4 commits into from
Oct 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions workers/Worker_cross_origin_security_err.htm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html>
<title> Worker cross-origin URL </title>
<title>Worker cross-origin URL</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id=log></div>
Expand All @@ -11,7 +11,20 @@
assert_true(e instanceof Event);
});
} catch (e) {
domfarolino marked this conversation as resolved.
Show resolved Hide resolved
t.step_func_done(function(e) { assert_true(true); });
assert_throws("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin Worker construction must be SecurityErrors");
t.done();
domfarolino marked this conversation as resolved.
Show resolved Hide resolved
}
});
}, "Cross-origin classic workers should fail to fetch");

async_test(function(t) {
try {
var w = new Worker("ftp://example.org/support/WorkerBasic.js", {type: "module"});
w.onerror = t.step_func_done(function(e) {
assert_true(e instanceof Event);
});
} catch (e) {
assert_throws("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin module Worker construction must be SecurityErrors");
t.done();
}
}, "Cross-origin module workers should fail to fetch");
</script>
5 changes: 3 additions & 2 deletions workers/constructors/SharedWorker/same-origin.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
-->
<!doctype html>
<title>same-origin checks</title>
<link rel=help href="http://www.whatwg.org/html/#dom-sharedworker">
<link rel=help href="https://html.spec.whatwg.org/multipage/workers.html#dom-sharedworker">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
Expand All @@ -19,7 +19,8 @@
assert_true(e instanceof Event);
});
} catch (e) {
t.step_func_done(function(e) { assert_true(true); });
assert_throws("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin SharedWorker construction must be SecurityErrors");
t.done();
domfarolino marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
23 changes: 12 additions & 11 deletions workers/constructors/Worker/same-origin.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!doctype html>
<meta charset=utf-8>
<title>same-origin checks; the script is in a script element</title>
<link rel=help href="http://www.whatwg.org/html/#dom-worker">
<link rel=help href="https://html.spec.whatwg.org/multipage/workers.html#dom-worker">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<div id="log"></div>
Expand All @@ -10,14 +10,15 @@
// not propogate to the window before the tests finish
setup({allow_uncaught_exception: true});

function testSharedWorkerHelper(t, script) {
function testWorkerHelper(t, script) {
try {
var worker = new SharedWorker(script, '');
var worker = new Worker(script);
Copy link
Member Author

@domfarolino domfarolino Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also noticed that the Worker constructor test was still testing the SharedWorker constructor, probably as a result of copy paste. This meant all of these tests failed in Safari, a UA that doesn't support SharedWorkers. I've tested these updates and they look good in Chrome, Firefox, and Safari.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yikes. Good catch!

worker.onerror = t.step_func_done(function(e) {
assert_true(e instanceof Event);
});
} catch (e) {
t.step_func_done(function(e) { assert_true(true); });
assert_throws("SecurityError", () => {throw e}, "DOMExceptions thrown on cross-origin Worker construction must be SecurityErrors");
t.done();
}
}

Expand All @@ -33,31 +34,31 @@
}, "data_url");

async_test(function(t) {
testSharedWorkerHelper(t, 'about:blank');
testWorkerHelper(t, 'about:blank');
}, "about_blank");

async_test(function(t) {
testSharedWorkerHelper(t, 'http://www.example.invalid/');
testWorkerHelper(t, 'http://www.example.invalid/');
}, "example_invalid");

async_test(function(t) {
testSharedWorkerHelper(t, location.protocol+'//'+location.hostname+':81/');
testWorkerHelper(t, location.protocol+'//'+location.hostname+':81/');
}, "port_81");

async_test(function(t) {
testSharedWorkerHelper(t, 'https://'+location.hostname+':80/');
testWorkerHelper(t, 'https://'+location.hostname+':80/');
}, "https_port_80");

async_test(function(t) {
testSharedWorkerHelper(t, 'https://'+location.hostname+':8000/');
testWorkerHelper(t, 'https://'+location.hostname+':8000/');
}, "https_port_8000");

async_test(function(t) {
testSharedWorkerHelper(t, 'http://'+location.hostname+':8012/');
testWorkerHelper(t, 'http://'+location.hostname+':8012/');
}, "http_post_8012");

async_test(function(t) {
testSharedWorkerHelper(t,'javascript:""');
testWorkerHelper(t,'javascript:""');
}, "javascript_url");

</script>