From c1315412cc21a85fb779bef0d87dadde751cfe71 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Thu, 21 Jun 2018 20:57:09 +0200 Subject: Bug 1469150 - CSP: Scripts with valid nonce get blocked if URL redirects https://bugzilla.mozilla.org/show_bug.cgi?id=1469150 --- dom/security/nsCSPService.cpp | 3 +- ...dom_security_test_csp_file_nonce_redirector.sjs | 25 ++++++++++++ ...dom_security_test_csp_file_nonce_redirects.html | 23 +++++++++++ ...dom_security_test_csp_test_nonce_redirects.html | 47 ++++++++++++++++++++++ dom/security/test/csp/mochitest.ini | 3 ++ 5 files changed, 100 insertions(+), 1 deletion(-) create mode 100644 dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs create mode 100644 dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html create mode 100644 dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html (limited to 'dom') diff --git a/dom/security/nsCSPService.cpp b/dom/security/nsCSPService.cpp index 7344e19fa..f9186b309 100644 --- a/dom/security/nsCSPService.cpp +++ b/dom/security/nsCSPService.cpp @@ -317,11 +317,12 @@ CSPService::AsyncOnChannelRedirect(nsIChannel *oldChannel, loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp)); if (csp) { + nsCOMPtr requestContext = loadInfo->GetLoadingContext(); // Pass originalURI as aExtra to indicate the redirect csp->ShouldLoad(policyType, // load type per nsIContentPolicy (uint32_t) newUri, // nsIURI nullptr, // nsIURI - nullptr, // nsISupports + requestContext, // nsISupports EmptyCString(), // ACString - MIME guess originalUri, // aExtra &aDecision); diff --git a/dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs b/dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs new file mode 100644 index 000000000..21a8f4e9c --- /dev/null +++ b/dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs @@ -0,0 +1,25 @@ +// custom *.sjs file for +// Bug 1469150:Scripts with valid nonce get blocked if URL redirects. + +const URL_PATH = "example.com/tests/dom/security/test/csp/"; + +function handleRequest(request, response) { + response.setHeader("Cache-Control", "no-cache", false); + let queryStr = request.queryString; + + if (queryStr === "redirect") { + response.setStatusLine("1.1", 302, "Found"); + response.setHeader("Location", + "https://" + URL_PATH + "file_nonce_redirector.sjs?load", false); + return; + } + + if (queryStr === "load") { + response.setHeader("Content-Type", "application/javascript", false); + response.write("console.log('script loaded');"); + return; + } + + // we should never get here - return something unexpected + response.write("d'oh"); +} diff --git a/dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html b/dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html new file mode 100644 index 000000000..e29116490 --- /dev/null +++ b/dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html @@ -0,0 +1,23 @@ + + + + + + Bug 1469150:Scripts with valid nonce get blocked if URL redirects + + + + + + + + diff --git a/dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html b/dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html new file mode 100644 index 000000000..f84fdcc7b --- /dev/null +++ b/dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html @@ -0,0 +1,47 @@ + + + + + Bug 1469150:Scripts with valid nonce get blocked if URL redirects + + + + + + + + + + diff --git a/dom/security/test/csp/mochitest.ini b/dom/security/test/csp/mochitest.ini index 33b112020..86b7fd0cd 100644 --- a/dom/security/test/csp/mochitest.ini +++ b/dom/security/test/csp/mochitest.ini @@ -88,6 +88,8 @@ support-files = file_shouldprocess.html file_nonce_source.html file_nonce_source.html^headers^ + file_nonce_redirects.html + file_nonce_redirector.sjs file_bug941404.html file_bug941404_xhr.html file_bug941404_xhr.html^headers^ @@ -245,6 +247,7 @@ skip-if = toolkit == 'android' # Times out, not sure why (bug 1008445) [test_frame_ancestors_ro.html] [test_policyuri_regression_from_multipolicy.html] [test_nonce_source.html] +[test_nonce_redirects.html] [test_bug941404.html] [test_form-action.html] [test_hash_source.html] -- cgit v1.2.3 From d413e1fb87779a0c3f474f8e773e01ad0878beea Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 23 Jun 2018 04:29:34 +0200 Subject: Bug 1469150 - Tests added to check scripts with valid nonce is allowed if URL redirects (follow up) --- ...dom_security_test_csp_file_nonce_redirector.sjs | 25 ------------ ...dom_security_test_csp_file_nonce_redirects.html | 23 ----------- ...dom_security_test_csp_test_nonce_redirects.html | 47 ---------------------- dom/security/test/csp/file_nonce_redirector.sjs | 25 ++++++++++++ dom/security/test/csp/file_nonce_redirects.html | 23 +++++++++++ dom/security/test/csp/test_nonce_redirects.html | 47 ++++++++++++++++++++++ 6 files changed, 95 insertions(+), 95 deletions(-) delete mode 100644 dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs delete mode 100644 dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html delete mode 100644 dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html create mode 100644 dom/security/test/csp/file_nonce_redirector.sjs create mode 100644 dom/security/test/csp/file_nonce_redirects.html create mode 100644 dom/security/test/csp/test_nonce_redirects.html (limited to 'dom') diff --git a/dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs b/dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs deleted file mode 100644 index 21a8f4e9c..000000000 --- a/dom/security/test/csp/dom_security_test_csp_file_nonce_redirector.sjs +++ /dev/null @@ -1,25 +0,0 @@ -// custom *.sjs file for -// Bug 1469150:Scripts with valid nonce get blocked if URL redirects. - -const URL_PATH = "example.com/tests/dom/security/test/csp/"; - -function handleRequest(request, response) { - response.setHeader("Cache-Control", "no-cache", false); - let queryStr = request.queryString; - - if (queryStr === "redirect") { - response.setStatusLine("1.1", 302, "Found"); - response.setHeader("Location", - "https://" + URL_PATH + "file_nonce_redirector.sjs?load", false); - return; - } - - if (queryStr === "load") { - response.setHeader("Content-Type", "application/javascript", false); - response.write("console.log('script loaded');"); - return; - } - - // we should never get here - return something unexpected - response.write("d'oh"); -} diff --git a/dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html b/dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html deleted file mode 100644 index e29116490..000000000 --- a/dom/security/test/csp/dom_security_test_csp_file_nonce_redirects.html +++ /dev/null @@ -1,23 +0,0 @@ - - - - - - Bug 1469150:Scripts with valid nonce get blocked if URL redirects - - - - - - - - diff --git a/dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html b/dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html deleted file mode 100644 index f84fdcc7b..000000000 --- a/dom/security/test/csp/dom_security_test_csp_test_nonce_redirects.html +++ /dev/null @@ -1,47 +0,0 @@ - - - - - Bug 1469150:Scripts with valid nonce get blocked if URL redirects - - - - - - - - - - diff --git a/dom/security/test/csp/file_nonce_redirector.sjs b/dom/security/test/csp/file_nonce_redirector.sjs new file mode 100644 index 000000000..21a8f4e9c --- /dev/null +++ b/dom/security/test/csp/file_nonce_redirector.sjs @@ -0,0 +1,25 @@ +// custom *.sjs file for +// Bug 1469150:Scripts with valid nonce get blocked if URL redirects. + +const URL_PATH = "example.com/tests/dom/security/test/csp/"; + +function handleRequest(request, response) { + response.setHeader("Cache-Control", "no-cache", false); + let queryStr = request.queryString; + + if (queryStr === "redirect") { + response.setStatusLine("1.1", 302, "Found"); + response.setHeader("Location", + "https://" + URL_PATH + "file_nonce_redirector.sjs?load", false); + return; + } + + if (queryStr === "load") { + response.setHeader("Content-Type", "application/javascript", false); + response.write("console.log('script loaded');"); + return; + } + + // we should never get here - return something unexpected + response.write("d'oh"); +} diff --git a/dom/security/test/csp/file_nonce_redirects.html b/dom/security/test/csp/file_nonce_redirects.html new file mode 100644 index 000000000..e29116490 --- /dev/null +++ b/dom/security/test/csp/file_nonce_redirects.html @@ -0,0 +1,23 @@ + + + + + + Bug 1469150:Scripts with valid nonce get blocked if URL redirects + + + + + + + + diff --git a/dom/security/test/csp/test_nonce_redirects.html b/dom/security/test/csp/test_nonce_redirects.html new file mode 100644 index 000000000..f84fdcc7b --- /dev/null +++ b/dom/security/test/csp/test_nonce_redirects.html @@ -0,0 +1,47 @@ + + + + + Bug 1469150:Scripts with valid nonce get blocked if URL redirects + + + + + + + + + + -- cgit v1.2.3 From 0097345ad9aa859dcf02cb0ba80685d51bc7ec16 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sat, 23 Jun 2018 04:30:08 +0200 Subject: Bug 1469150 - CSP: Scripts with valid nonce get blocked if URL redirects is fixed (follow up) --- dom/security/nsCSPService.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'dom') diff --git a/dom/security/nsCSPService.cpp b/dom/security/nsCSPService.cpp index f9186b309..4807c9aa4 100644 --- a/dom/security/nsCSPService.cpp +++ b/dom/security/nsCSPService.cpp @@ -288,6 +288,7 @@ CSPService::AsyncOnChannelRedirect(nsIChannel *oldChannel, nsContentUtils::InternalContentPolicyTypeToExternalOrWorker(policyType); int16_t aDecision = nsIContentPolicy::ACCEPT; + nsCOMPtr requestContext = loadInfo->GetLoadingContext(); // 1) Apply speculative CSP for preloads if (isPreload) { nsCOMPtr preloadCsp; @@ -298,7 +299,7 @@ CSPService::AsyncOnChannelRedirect(nsIChannel *oldChannel, preloadCsp->ShouldLoad(policyType, // load type per nsIContentPolicy (uint32_t) newUri, // nsIURI nullptr, // nsIURI - nullptr, // nsISupports + requestContext, // nsISupports EmptyCString(), // ACString - MIME guess originalUri, // aExtra &aDecision); @@ -317,7 +318,6 @@ CSPService::AsyncOnChannelRedirect(nsIChannel *oldChannel, loadInfo->LoadingPrincipal()->GetCsp(getter_AddRefs(csp)); if (csp) { - nsCOMPtr requestContext = loadInfo->GetLoadingContext(); // Pass originalURI as aExtra to indicate the redirect csp->ShouldLoad(policyType, // load type per nsIContentPolicy (uint32_t) newUri, // nsIURI -- cgit v1.2.3