moebius#231: Consider blocking top level window data: URIs (tests)

https://github.com/MoonchildProductions/moebius/pull/231
This commit is contained in:
janekptacijarabaci 2018-05-06 14:31:20 +02:00 • committed by Roy Tam
commit 745e1809b0
63 changed files with 157 additions and 83 deletions

View file

@ -20,6 +20,14 @@ function f()
finish();
}
function init()
{
SpecialPowers.pushPrefEnv({"set": [
["security.data_uri.block_toplevel_data_uri_navigations", false],
]}, start);
}
function start()
{
var html = "<script>" + f + "<\/script><body onload=f()>";
@ -29,5 +37,5 @@ function start()
</script>
</head>
<body onload="start();"></body>
<body onload="init();"></body>
</html>

View file

@ -29,9 +29,15 @@ https://bugzilla.mozilla.org/show_bug.cgi?id=364461
/** Test for Bug 364461 **/
SimpleTest.waitForExplicitFinish();
window.open("bug364461_window.xul", "bug364461",
"chrome,width=600,height=600");
SpecialPowers.pushPrefEnv({
"set":[["security.data_uri.block_toplevel_data_uri_navigations", false]]
}, runTests);
function runTests() {
window.open("bug364461_window.xul", "bug364461",
"chrome,width=600,height=600");
}
]]>
</script>

View file

@ -0,0 +1 @@
<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body>Should show</body>

View file

@ -0,0 +1 @@
<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body></body>

View file

@ -0,0 +1 @@
<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body>Should show</body>

View file

@ -0,0 +1 @@
<script>window.onload = function() { opener.postMessage('loaded', '*'); }</script><body></body>

View file

@ -21,9 +21,13 @@ support-files =
file_bug540462.html
file_bug580069_1.html
file_bug580069_2.sjs
file_bug598895_1.html
file_bug598895_2.html
file_bug590573_1.html
file_bug590573_2.html
file_bug634834.html
file_bug637644_1.html
file_bug637644_2.html
file_bug640387.html
file_bug653741.html
file_bug660404

View file

@ -9,10 +9,10 @@
///////////////////////////////////////////////////////////////////////////
var body = "This frame was navigated.";
var target_url = "data:text/html,<html><body>" + body + "</body></html>";
var target_url = "navigation_target_url.html"
var popup_body = "This is a popup";
var target_popup_url = "data:text/html,<html><body>" + popup_body + "</body></html>";
var target_popup_url = "navigation_target_popup_url.html";
///////////////////////////////////////////////////////////////////////////
// Functions that navigate frames
@ -58,7 +58,7 @@ function navigateByHyperlink(name) {
function isNavigated(wnd, message) {
var result = null;
try {
result = SpecialPowers.wrap(wnd).document.body.innerHTML;
result = SpecialPowers.wrap(wnd).document.body.innerHTML.trim();
} catch(ex) {
result = ex;
}
@ -68,7 +68,7 @@ function isNavigated(wnd, message) {
function isBlank(wnd, message) {
var result = null;
try {
result = wnd.document.body.innerHTML;
result = wnd.document.body.innerHTML.trim();
} catch(ex) {
result = ex;
}
@ -146,7 +146,9 @@ function xpcGetFramesByName(name) {
function xpcCleanupWindows() {
xpcEnumerateContentWindows(function(win) {
if (win.location && win.location.protocol == "data:")
if (win.location &&
(win.location.href.endsWith(target_url) ||
win.location.href.endsWith(target_popup_url))) {
win.close();
});
}
@ -177,12 +179,12 @@ function xpcWaitForFinishedFrames(callback, numFrames) {
}
function searchForFinishedFrames(win) {
if ((escape(unescape(win.location)) == escape(target_url) ||
escape(unescape(win.location)) == escape(target_popup_url)) &&
if ((win.location.href.endsWith(target_url) ||
win.location.href.endsWith(target_popup_url)) &&
win.document &&
win.document.body &&
(win.document.body.textContent == body ||
win.document.body.textContent == popup_body) &&
(win.document.body.textContent.trim() == body ||
win.document.body.textContent.trim() == popup_body) &&
win.document.readyState == "complete") {
var util = win.QueryInterface(SpecialPowers.Ci.nsIInterfaceRequestor)

View file

@ -40,7 +40,7 @@
document.getElementById("bottom").scrollIntoView();
window.onunload = null; // Should get bfcache behavior.
opener.setTimeout("testWindow.history.back();", 250);
window.location.href = 'data:text/html,';
window.location.href = 'about:blank';
break;
}
case 4: {
@ -57,7 +57,7 @@
opener.is(history.scrollRestoration, "manual", "Should have the same scrollRestoration mode as before fragment navigation.");
window.onunload = function() {} // Disable bfcache.
opener.setTimeout("is(testWindow.history.scrollRestoration, 'auto'); testWindow.history.back();", 250);
window.location.href = 'data:text/html,';
window.location.href = 'about:blank';
break;
}
case 6: {

View file

@ -1,6 +1,8 @@
[DEFAULT]
support-files =
NavigationUtils.js
navigation_target_url.html
navigation_target_popup_url.html
blank.html
file_bug462076_1.html
file_bug462076_2.html

View file

@ -0,0 +1 @@
<html><body>This is a popup</body></html>

View file

@ -0,0 +1 @@
<html><body>This frame was navigated.</body></html>

View file

@ -3,7 +3,7 @@
<script>
var target = window.location.hash.substring(1);
document.write("target=" + target);
window.open("data:text/html,<html><body>This is a popup</body></html>", target, "width=10,height=10");
window.open("navigation_target_popup_url.html", target, "width=10,height=10");
</script>
</body>
</html>

View file

@ -13,8 +13,7 @@
/* We call window.open() using different URIs and make sure the triggeringPrincipal
* loadingPrincipal are correct.
* Test1: window.open(http:)
* Test2: window.open(data:)
* Test3: window.open(javascript:)
* Test2: window.open(javascript:)
*/
const TRIGGERING_PRINCIPAL_URI =
@ -22,7 +21,7 @@ const TRIGGERING_PRINCIPAL_URI =
SimpleTest.waitForExplicitFinish();
const NUM_TESTS = 3;
const NUM_TESTS = 2;
var test_counter = 0;
function checkFinish() {
@ -54,28 +53,7 @@ httpWin.onload = function() {
}
// ----------------------------------------------------------------------------
// Test 2: window.open(data:)
var dataWin = window.open("data:text/html,<html><body>data</body></html>", "_blank", "width=10,height=10");
dataWin.onload = function() {
var dataChannel = SpecialPowers.wrap(dataWin.document).docShell.currentDocumentChannel;
var dataTriggeringPrincipal = dataChannel.loadInfo.triggeringPrincipal.URI.asciiSpec;
var dataLoadingPrincipal = dataChannel.loadInfo.loadingPrincipal;
is(dataTriggeringPrincipal, TRIGGERING_PRINCIPAL_URI,
"TriggeringPrincipal for window.open(data:) should be the principal of the document");
is(dataWin.document.referrer, "",
"Referrer for window.open(data:) should be empty");
is(dataLoadingPrincipal, null,
"LoadingPrincipal for window.open(data:) should be null");
dataWin.close();
checkFinish();
}
// ----------------------------------------------------------------------------
// Test 3: window.open(javascript:)
// Test 2: window.open(javascript:)
var jsWin = window.open("javascript:'<html><body>js</body></html>';", "_blank", "width=10,height=10");
jsWin.onload = function() {
var jsChannel = SpecialPowers.wrap(jsWin.document).docShell.currentDocumentChannel;

View file

@ -43,9 +43,8 @@ window.onmessage = function (ev) {
}
}
var win2 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body>Should show</body>");
var win3 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body></body>");
var win2 = window.open("file_bug598895_1.html");
var win3 = window.open("file_bug598895_2.html");
});
</script>
</pre>

View file

@ -43,9 +43,8 @@ window.onmessage = function (ev) {
}
}
var win2 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body>Should show</body>", "", "height=500,width=500");
var win3 = window.open("data:text/html,<script>window.onload = function() { opener.postMessage('loaded', '*'); }</" + "script><body></body>", "", "height=500,width=500");
var win2 = window.open("file_bug637644_1.html", "", "height=500,width=500");
var win3 = window.open("file_bug637644_2.html", "", "height=500,width=500");
});
</script>
</pre>