Bug 1432137 - Add test to verify insecure redirects to data: URIs are blocked for script modules. r=jonco

This commit is contained in:
Christoph Kerschbaumer 2018-01-23 14:04:21 +01:00
Родитель f0075796d0
Коммит 16dba8baf1
2 изменённых файлов: 19 добавлений и 4 удалений

Просмотреть файл

@ -10,13 +10,13 @@ function handleRequest(request, response)
response.setHeader("Cache-Control", "no-cache", false); response.setHeader("Cache-Control", "no-cache", false);
response.setStatusLine("1.1", 302, "Found"); response.setStatusLine("1.1", 302, "Found");
if (query === "script") { if (query === "script" || query === "modulescript") {
response.setHeader("Location", "data:text/html," + escape(SCRIPT_DATA), false); response.setHeader("Location", "data:text/javascript," + escape(SCRIPT_DATA), false);
return; return;
} }
if (query === "worker") { if (query === "worker") {
response.setHeader("Location", "data:text/html," + escape(WORKER_DATA), false); response.setHeader("Location", "data:text/javascript," + escape(WORKER_DATA), false);
return; return;
} }

Просмотреть файл

@ -8,11 +8,12 @@
<body> <body>
<script id="testScriptRedirectToData"></script> <script id="testScriptRedirectToData"></script>
<script id="testModuleScriptRedirectToData" type="module"></script>
<script class="testbody" type="text/javascript"> <script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish(); SimpleTest.waitForExplicitFinish();
const NUM_TESTS = 2; const NUM_TESTS = 3;
var testCounter = 0; var testCounter = 0;
function checkFinish() { function checkFinish() {
@ -48,6 +49,20 @@ worker.onmessage = function() {
}; };
worker.postMessage("dummy"); worker.postMessage("dummy");
// --- test script modules
SpecialPowers.pushPrefEnv({set: [["dom.moduleScripts.enabled", true]]}, function() {
let testModuleScriptRedirectToData = document.getElementById("testModuleScriptRedirectToData");
testModuleScriptRedirectToData.onerror = function() {
ok(true, "module script that redirects to data: URI should not load");
checkFinish();
}
testModuleScriptRedirectToData.onload = function() {
ok(false, "module script that redirects to data: URI should not load");
checkFinish();
}
testModuleScriptRedirectToData.src = "file_block_subresource_redir_to_data.sjs?modulescript";
});
</script> </script>
</body> </body>
</html> </html>