From 22ce31c8282972dd1ceb8b1747658f67086dc80c Mon Sep 17 00:00:00 2001 From: vinoth Date: Fri, 22 Jun 2018 20:38:05 +0300 Subject: [PATCH] Bug 1469150 - Tests added to check scripts with valid nonce is allowed if URL redirects. r=ckerschb Reviewers: ckerschb Reviewed By: ckerschb Subscribers: ckerschb Bug #: 1469150 Differential Revision: https://phabricator.services.mozilla.com/D1721 --HG-- extra : rebase_source : f600e601123f90ad3ab08b4fef6a791183419cd4 extra : amend_source : 854510827f78b43bf40cdbf7d782c25981190cf1 --- .../test/csp/file_nonce_redirector.sjs | 25 ++++++++++ .../test/csp/file_nonce_redirects.html | 23 +++++++++ dom/security/test/csp/mochitest.ini | 3 ++ .../test/csp/test_nonce_redirects.html | 47 +++++++++++++++++++ 4 files changed, 98 insertions(+) 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 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 000000000000..21a8f4e9c10d --- /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 000000000000..e29116490079 --- /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/mochitest.ini b/dom/security/test/csp/mochitest.ini index 2a2098696d64..09e072120208 100644 --- a/dom/security/test/csp/mochitest.ini +++ b/dom/security/test/csp/mochitest.ini @@ -94,6 +94,8 @@ support-files = file_policyuri_regression_from_multipolicy_policy 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^ @@ -265,6 +267,7 @@ skip-if = verify [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] 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 000000000000..f84fdcc7bdca --- /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 + + + + + + + + + +