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.setStatusLine("1.1", 302, "Found");
if (query === "script") {
response.setHeader("Location", "data:text/html," + escape(SCRIPT_DATA), false);
if (query === "script" || query === "modulescript") {
response.setHeader("Location", "data:text/javascript," + escape(SCRIPT_DATA), false);
return;
}
if (query === "worker") {
response.setHeader("Location", "data:text/html," + escape(WORKER_DATA), false);
response.setHeader("Location", "data:text/javascript," + escape(WORKER_DATA), false);
return;
}

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

@ -8,11 +8,12 @@
<body>
<script id="testScriptRedirectToData"></script>
<script id="testModuleScriptRedirectToData" type="module"></script>
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
const NUM_TESTS = 2;
const NUM_TESTS = 3;
var testCounter = 0;
function checkFinish() {
@ -48,6 +49,20 @@ worker.onmessage = function() {
};
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>
</body>
</html>