From a7a59cdd3db332550e46052627117e3ff542256e Mon Sep 17 00:00:00 2001 From: Christoph Kerschbaumer Date: Fri, 21 Nov 2014 12:54:51 -0800 Subject: [PATCH] Bug 949706 - CSP: Correct handling of web workers importing scripts that get redirected (r=sstamm) --- dom/base/test/csp/file_worker_redirect.html | 9 +++ dom/base/test/csp/file_worker_redirect.sjs | 37 ++++++++++ dom/base/test/csp/mochitest.ini | 3 + dom/base/test/csp/test_worker_redirect.html | 76 +++++++++++++++++++++ 4 files changed, 125 insertions(+) create mode 100644 dom/base/test/csp/file_worker_redirect.html create mode 100644 dom/base/test/csp/file_worker_redirect.sjs create mode 100644 dom/base/test/csp/test_worker_redirect.html diff --git a/dom/base/test/csp/file_worker_redirect.html b/dom/base/test/csp/file_worker_redirect.html new file mode 100644 index 000000000000..be80f5795f8c --- /dev/null +++ b/dom/base/test/csp/file_worker_redirect.html @@ -0,0 +1,9 @@ + + + + Bug 949706 - CSP: Correct handling of web workers importing scripts that get redirected + + + + + diff --git a/dom/base/test/csp/file_worker_redirect.sjs b/dom/base/test/csp/file_worker_redirect.sjs new file mode 100644 index 000000000000..52453136784e --- /dev/null +++ b/dom/base/test/csp/file_worker_redirect.sjs @@ -0,0 +1,37 @@ +// testserver customized for the needs of: +// Bug 949706 - CSP: Correct handling of web workers importing scripts that get redirected + +function handleRequest(request, response) +{ + response.setHeader("Cache-Control", "no-cache", false); + response.setHeader("Content-Type", "text/html", false); + + var query = request.queryString; + + if (query === "stage_0_script_loads_worker") { + var newWorker = + "var myWorker = new Worker(\"file_worker_redirect.sjs?stage_1_worker_import_scripts\");" + + "myWorker.onmessage = function (event) { parent.checkResult(\"allowed\"); };" + + "myWorker.onerror = function (event) { parent.checkResult(\"blocked\"); };"; + response.write(newWorker); + return; + } + + if (query === "stage_1_worker_import_scripts") { + response.write("importScripts(\"file_worker_redirect.sjs?stage_2_redirect_imported_script\");"); + return; + } + + if (query === "stage_2_redirect_imported_script") { + var newLocation = + "http://test1.example.com/tests/dom/base/test/csp/file_worker_redirect.sjs?stage_3_target_script"; + response.setStatusLine("1.1", 302, "Found"); + response.setHeader("Location", newLocation, false); + return; + } + + if (query === "stage_3_target_script") { + response.write("postMessage(\"imported script loaded\");"); + return; + } +} diff --git a/dom/base/test/csp/mochitest.ini b/dom/base/test/csp/mochitest.ini index 29a79a0f82bb..4026bbaaa5df 100644 --- a/dom/base/test/csp/mochitest.ini +++ b/dom/base/test/csp/mochitest.ini @@ -101,6 +101,8 @@ support-files = file_multi_policy_injection_bypass_2.html file_multi_policy_injection_bypass_2.html^headers^ file_form-action.html + file_worker_redirect.html + file_worker_redirect.sjs [test_base-uri.html] [test_connect-src.html] @@ -147,3 +149,4 @@ skip-if = buildapp == 'b2g' # intermittent orange (bug 1028490) [test_subframe_run_js_if_allowed.html] [test_leading_wildcard.html] [test_multi_policy_injection_bypass.html] +[test_worker_redirect.html] diff --git a/dom/base/test/csp/test_worker_redirect.html b/dom/base/test/csp/test_worker_redirect.html new file mode 100644 index 000000000000..a2dde2ebc325 --- /dev/null +++ b/dom/base/test/csp/test_worker_redirect.html @@ -0,0 +1,76 @@ + + + + Bug 949706 - CSP: Correct handling of web workers importing scripts that get redirected + + + + + + + + + +