diff --git a/dom/base/nsXMLHttpRequest.cpp b/dom/base/nsXMLHttpRequest.cpp index 969652703132..1bc30c752ac5 100644 --- a/dom/base/nsXMLHttpRequest.cpp +++ b/dom/base/nsXMLHttpRequest.cpp @@ -1690,10 +1690,8 @@ nsXMLHttpRequest::Open(const nsACString& inMethod, const nsACString& url, nsILoadInfo::SEC_FORCE_INHERIT_PRINCIPAL; } - // If we have the document, use it. Unfortunately, for dedicated workers - // 'doc' ends up being the parent document, which is not the document - // that we want to use. So make sure to avoid using 'doc' in that situation. - if (doc && doc->NodePrincipal() == mPrincipal) { + // If we have the document, use it + if (doc) { rv = NS_NewChannel(getter_AddRefs(mChannel), uri, doc, diff --git a/dom/security/test/csp/file_main.html^headers^ b/dom/security/test/csp/file_main.html^headers^ index 3338de389b31..c7fdbae20471 100644 --- a/dom/security/test/csp/file_main.html^headers^ +++ b/dom/security/test/csp/file_main.html^headers^ @@ -1 +1 @@ -Content-Security-Policy: default-src 'self' blob: ; style-src 'unsafe-inline' 'self' +Content-Security-Policy: default-src 'self' ; style-src 'unsafe-inline' 'self' diff --git a/dom/security/test/csp/file_main.js b/dom/security/test/csp/file_main.js index 0bc15b6827a4..864a5d230b95 100644 --- a/dom/security/test/csp/file_main.js +++ b/dom/security/test/csp/file_main.js @@ -1,28 +1,16 @@ -function doXHR(uri) { - try { - var xhr = new XMLHttpRequest(); - xhr.open("GET", uri); - xhr.send(); - } catch(ex) {} -} +// some javascript for the CSP XHR tests +// -doXHR("http://mochi.test:8888/tests/dom/security/test/csp/file_CSP.sjs?testid=xhr_good"); -doXHR("http://example.com/tests/dom/security/test/csp/file_CSP.sjs?testid=xhr_bad"); -fetch("http://mochi.test:8888/tests/dom/security/test/csp/file_CSP.sjs?testid=fetch_good"); -fetch("http://example.com/tests/dom/security/test/csp/file_CSP.sjs?testid=fetch_bad"); -navigator.sendBeacon("http://mochi.test:8888/tests/dom/security/test/csp/file_CSP.sjs?testid=beacon_good"); try { - navigator.sendBeacon("http://example.com/tests/dom/security/test/csp/file_CSP.sjs?testid=beacon_bad"); -} catch(ex) {} + var xhr_good = new XMLHttpRequest(); + var xhr_good_uri ="http://mochi.test:8888/tests/dom/security/test/csp/file_CSP.sjs?testid=xhr_good"; + xhr_good.open("GET", xhr_good_uri, true); + xhr_good.send(null); +} catch(e) {} - -new Worker("file_main_worker.js").postMessage({inherited : false}); - - -var blobxhr = new XMLHttpRequest(); -blobxhr.open("GET", "file_main_worker.js") -blobxhr.responseType = "blob"; -blobxhr.send(); -blobxhr.onload = () => { - new Worker(URL.createObjectURL(blobxhr.response)).postMessage({inherited : true}); -} +try { + var xhr_bad = new XMLHttpRequest(); + var xhr_bad_uri ="http://example.com/tests/dom/security/test/csp/file_CSP.sjs?testid=xhr_bad"; + xhr_bad.open("GET", xhr_bad_uri, true); + xhr_bad.send(null); +} catch(e) {} diff --git a/dom/security/test/csp/file_main_worker.js b/dom/security/test/csp/file_main_worker.js deleted file mode 100644 index d8953eec7489..000000000000 --- a/dom/security/test/csp/file_main_worker.js +++ /dev/null @@ -1,28 +0,0 @@ -function doXHR(uri) { - try { - var xhr = new XMLHttpRequest(); - xhr.open("GET", uri); - xhr.send(); - } catch(ex) {} -} - -var sameBase = "http://mochi.test:8888/tests/dom/security/test/csp/file_CSP.sjs?testid="; -var crossBase = "http://example.com/tests/dom/security/test/csp/file_CSP.sjs?testid="; - -onmessage = (e) => { - for (base of [sameBase, crossBase]) { - var prefix; - var suffix; - if (e.data.inherited) { - prefix = base + "worker_inherited_" - suffix = base == sameBase ? "_good" : "_bad"; - } - else { - prefix = base + "worker_" - suffix = base == sameBase ? "_same_good" : "_cross_good"; - } - doXHR(prefix + "xhr" + suffix); - fetch(prefix + "fetch" + suffix); - try { importScripts(prefix + "script" + suffix); } catch(ex) {} - } -} diff --git a/dom/security/test/csp/file_redirects_main.html b/dom/security/test/csp/file_redirects_main.html index 5c9affea04ba..651f44d38495 100644 --- a/dom/security/test/csp/file_redirects_main.html +++ b/dom/security/test/csp/file_redirects_main.html @@ -11,18 +11,17 @@ var thisSite = "http://mochi.test:8888"; var otherSite = "http://example.com"; var page = "/tests/dom/security/test/csp/file_redirects_page.sjs"; -var tests = { "font-src": thisSite+page+"?testid=font-src", - "frame-src": thisSite+page+"?testid=frame-src", - "img-src": thisSite+page+"?testid=img-src", - "media-src": thisSite+page+"?testid=media-src", - "object-src": thisSite+page+"?testid=object-src", - "script-src": thisSite+page+"?testid=script-src", - "style-src": thisSite+page+"?testid=style-src", - "worker": thisSite+page+"?testid=worker", - "xhr-src": thisSite+page+"?testid=xhr-src", - "from-worker": thisSite+page+"?testid=from-worker", - "from-blob-worker": thisSite+page+"?testid=from-blob-worker", - "img-src-from-css": thisSite+page+"?testid=img-src-from-css", +var tests = { "font-src": thisSite+page+"?testid=font-src&csp=1", + "frame-src": thisSite+page+"?testid=frame-src&csp=1", + "img-src": thisSite+page+"?testid=img-src&csp=1", + "media-src": thisSite+page+"?testid=media-src&csp=1", + "object-src": thisSite+page+"?testid=object-src&csp=1", + "script-src": thisSite+page+"?testid=script-src&csp=1", + "style-src": thisSite+page+"?testid=style-src&csp=1", + "worker": thisSite+page+"?testid=worker&csp=1", + "xhr-src": thisSite+page+"?testid=xhr-src&csp=1", + "script-src-from-worker": thisSite+page+"?testid=script-src-from-worker&csp=1", + "img-src-from-css": thisSite+page+"?testid=img-src-from-css&csp=1", }; var container = document.getElementById("container"); diff --git a/dom/security/test/csp/file_redirects_page.sjs b/dom/security/test/csp/file_redirects_page.sjs index 9e3c0d0350d4..a849185d5c7f 100644 --- a/dom/security/test/csp/file_redirects_page.sjs +++ b/dom/security/test/csp/file_redirects_page.sjs @@ -14,13 +14,15 @@ function handleRequest(request, response) var resource = "/tests/dom/security/test/csp/file_redirects_resource.sjs"; // CSP header value - var additional = "" - if (query['testid'] == "worker") { - additional = "; script-src 'self' 'unsafe-inline'"; + if (query["csp"] == 1) { + var additional = "" + if (query['testid'] == "worker") { + additional = "; script-src 'self' 'unsafe-inline'"; + } + response.setHeader("Content-Security-Policy", + "default-src 'self' ; style-src 'self' 'unsafe-inline'" + additional, + false); } - response.setHeader("Content-Security-Policy", - "default-src 'self' blob: ; style-src 'self' 'unsafe-inline'" + additional, - false); // downloadable font that redirects to another site if (query["testid"] == "font-src") { @@ -88,27 +90,13 @@ function handleRequest(request, response) return; } - if (query["testid"] == "from-worker") { + if (query["testid"] == "script-src-from-worker") { // loads a script; launches a worker; that worker uses importscript; which then gets redirected // So it's: - // '); - return; - } - - if (query["testid"] == "from-blob-worker") { - // loads a script; launches a worker; that worker uses importscript; which then gets redirected - // So it's: - // '); + response.write(''); return; } } diff --git a/dom/security/test/csp/file_redirects_resource.sjs b/dom/security/test/csp/file_redirects_resource.sjs index d281f19d8ba5..b23be2f512dd 100644 --- a/dom/security/test/csp/file_redirects_resource.sjs +++ b/dom/security/test/csp/file_redirects_resource.sjs @@ -102,45 +102,29 @@ function handleRequest(request, response) // script that loads an internal worker that uses importScripts on a redirect // to an external script. - if (query["res"] == "loadWorkerThatMakesRequests") { + if (query["res"] == "loadWorkerThatImports") { // this creates a worker (same origin) that imports a redirecting script. - let workerURL = thisSite + resource + '?res=makeRequestsWorker&id=' + query["id"]; + let workerURL = thisSite + resource + '?res=importScriptWorker&id=' + query["id"]; response.setHeader("Content-Type", "application/javascript", false); - response.write("new Worker('" + workerURL + "');"); - return; - } - - // script that loads an internal worker that uses importScripts on a redirect - // to an external script. - if (query["res"] == "loadBlobWorkerThatMakesRequests") { - // this creates a worker (same origin) that imports a redirecting script. - let workerURL = thisSite + resource + '?res=makeRequestsWorker&id=' + query["id"]; - response.setHeader("Content-Type", "application/javascript", false); - response.write("var x = new XMLHttpRequest(); x.open('GET', '" + workerURL + "'); "); - response.write("x.responseType = 'blob'; x.send(); "); - response.write("x.onload = () => { new Worker(URL.createObjectURL(x.response)); };"); + response.write("var w=new Worker('" + workerURL + "'); w.onmessage=function(event){ alert(event.data); }"); return; } // source for a worker that simply calls importScripts on a script that // redirects. - if (query["res"] == "makeRequestsWorker") { + if (query["res"] == "importScriptWorker") { // this is code for a worker that imports a redirected script. - let scriptURL = thisSite + resource + "?redir=other&res=script&id=script-src-redir-" + query["id"]; - let xhrURL = thisSite + resource + "?redir=other&res=xhr-resp&id=xhr-src-redir-" + query["id"]; - let fetchURL = thisSite + resource + "?redir=other&res=xhr-resp&id=fetch-src-redir-" + query["id"]; + let scriptURL = thisSite + resource + "?redir=other&res=script&id=" + query["id"]; response.setHeader("Content-Type", "application/javascript", false); - response.write("try { importScripts('" + scriptURL + "'); } catch(ex) {} "); - response.write("var x = new XMLHttpRequest(); x.open('GET', '" + xhrURL + "'); x.send();"); - response.write("fetch('" + fetchURL + "');"); + response.write("importScripts('" + scriptURL + "');"); return; } // script that invokes XHR if (query["res"] == "xhr") { response.setHeader("Content-Type", "application/javascript", false); - var resp = 'var x = new XMLHttpRequest();x.open("GET", "' + thisSite + - resource+'?redir=other&res=xhr-resp&id=xhr-src-redir", false);\n' + + var resp = 'var x = new XMLHttpRequest();x.open("GET", "' + otherSite + + resource+'?res=xhr-resp&testid=xhr-src-redir", false);\n' + 'x.send(null);'; response.write(resp); return; diff --git a/dom/security/test/csp/file_worker_redirect.html b/dom/security/test/csp/file_worker_redirect.html new file mode 100644 index 000000000000..be80f5795f8c --- /dev/null +++ b/dom/security/test/csp/file_worker_redirect.html @@ -0,0 +1,9 @@ + + +
+