From 4b7a2c677a8bda717cbc21f8e06ee43c0d9f0005 Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Sun, 6 May 2018 14:31:20 +0200 Subject: moebius#231: Consider blocking top level window data: URIs (tests) https://github.com/MoonchildProductions/moebius/pull/231 --- docshell/base/crashtests/914521.html | 10 +++++++- docshell/test/chrome/test_bug364461.xul | 10 ++++++-- docshell/test/file_bug598895_1.html | 1 + docshell/test/file_bug598895_2.html | 1 + docshell/test/file_bug637644_1.html | 1 + docshell/test/file_bug637644_2.html | 1 + docshell/test/mochitest.ini | 4 ++++ docshell/test/navigation/NavigationUtils.js | 20 +++++++++------- .../test/navigation/file_scrollRestoration.html | 4 ++-- docshell/test/navigation/mochitest.ini | 2 ++ .../navigation/navigation_target_popup_url.html | 1 + .../test/navigation/navigation_target_url.html | 1 + docshell/test/navigation/open.html | 2 +- .../test_triggeringprincipal_window_open.html | 28 +++------------------- docshell/test/test_bug598895.html | 5 ++-- docshell/test/test_bug637644.html | 5 ++-- 16 files changed, 50 insertions(+), 46 deletions(-) create mode 100644 docshell/test/file_bug598895_1.html create mode 100644 docshell/test/file_bug598895_2.html create mode 100644 docshell/test/file_bug637644_1.html create mode 100644 docshell/test/file_bug637644_2.html create mode 100644 docshell/test/navigation/navigation_target_popup_url.html create mode 100644 docshell/test/navigation/navigation_target_url.html (limited to 'docshell') diff --git a/docshell/base/crashtests/914521.html b/docshell/base/crashtests/914521.html index 9ae18b860..eb0a43749 100644 --- a/docshell/base/crashtests/914521.html +++ b/docshell/base/crashtests/914521.html @@ -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 = " - + diff --git a/docshell/test/chrome/test_bug364461.xul b/docshell/test/chrome/test_bug364461.xul index 85154f9d7..9e45ce971 100644 --- a/docshell/test/chrome/test_bug364461.xul +++ b/docshell/test/chrome/test_bug364461.xul @@ -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"); +} ]]> diff --git a/docshell/test/file_bug598895_1.html b/docshell/test/file_bug598895_1.html new file mode 100644 index 000000000..6fbb13a02 --- /dev/null +++ b/docshell/test/file_bug598895_1.html @@ -0,0 +1 @@ +Should show diff --git a/docshell/test/file_bug598895_2.html b/docshell/test/file_bug598895_2.html new file mode 100644 index 000000000..0822c566b --- /dev/null +++ b/docshell/test/file_bug598895_2.html @@ -0,0 +1 @@ + diff --git a/docshell/test/file_bug637644_1.html b/docshell/test/file_bug637644_1.html new file mode 100644 index 000000000..6fbb13a02 --- /dev/null +++ b/docshell/test/file_bug637644_1.html @@ -0,0 +1 @@ +Should show diff --git a/docshell/test/file_bug637644_2.html b/docshell/test/file_bug637644_2.html new file mode 100644 index 000000000..0822c566b --- /dev/null +++ b/docshell/test/file_bug637644_2.html @@ -0,0 +1 @@ + diff --git a/docshell/test/mochitest.ini b/docshell/test/mochitest.ini index 2298bed74..d2e378928 100644 --- a/docshell/test/mochitest.ini +++ b/docshell/test/mochitest.ini @@ -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 diff --git a/docshell/test/navigation/NavigationUtils.js b/docshell/test/navigation/NavigationUtils.js index c90ea74d5..72bea7dde 100644 --- a/docshell/test/navigation/NavigationUtils.js +++ b/docshell/test/navigation/NavigationUtils.js @@ -9,10 +9,10 @@ /////////////////////////////////////////////////////////////////////////// var body = "This frame was navigated."; -var target_url = "data:text/html," + body + ""; +var target_url = "navigation_target_url.html" var popup_body = "This is a popup"; -var target_popup_url = "data:text/html," + popup_body + ""; +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) diff --git a/docshell/test/navigation/file_scrollRestoration.html b/docshell/test/navigation/file_scrollRestoration.html index 92e43d7fb..766949d13 100644 --- a/docshell/test/navigation/file_scrollRestoration.html +++ b/docshell/test/navigation/file_scrollRestoration.html @@ -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: { diff --git a/docshell/test/navigation/mochitest.ini b/docshell/test/navigation/mochitest.ini index 764e400a8..1b5f33c7f 100644 --- a/docshell/test/navigation/mochitest.ini +++ b/docshell/test/navigation/mochitest.ini @@ -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 diff --git a/docshell/test/navigation/navigation_target_popup_url.html b/docshell/test/navigation/navigation_target_popup_url.html new file mode 100644 index 000000000..cfe6de009 --- /dev/null +++ b/docshell/test/navigation/navigation_target_popup_url.html @@ -0,0 +1 @@ +This is a popup diff --git a/docshell/test/navigation/navigation_target_url.html b/docshell/test/navigation/navigation_target_url.html new file mode 100644 index 000000000..a485e8133 --- /dev/null +++ b/docshell/test/navigation/navigation_target_url.html @@ -0,0 +1 @@ +This frame was navigated. diff --git a/docshell/test/navigation/open.html b/docshell/test/navigation/open.html index 1bb70f865..97eb9b76e 100644 --- a/docshell/test/navigation/open.html +++ b/docshell/test/navigation/open.html @@ -3,7 +3,7 @@ diff --git a/docshell/test/navigation/test_triggeringprincipal_window_open.html b/docshell/test/navigation/test_triggeringprincipal_window_open.html index d5d7f210b..dbee21777 100644 --- a/docshell/test/navigation/test_triggeringprincipal_window_open.html +++ b/docshell/test/navigation/test_triggeringprincipal_window_open.html @@ -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,data", "_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:'js';", "_blank", "width=10,height=10"); jsWin.onload = function() { var jsChannel = SpecialPowers.wrap(jsWin.document).docShell.currentDocumentChannel; diff --git a/docshell/test/test_bug598895.html b/docshell/test/test_bug598895.html index 52b9537be..5cc74e42c 100644 --- a/docshell/test/test_bug598895.html +++ b/docshell/test/test_bug598895.html @@ -43,9 +43,8 @@ window.onmessage = function (ev) { } } -var win2 = window.open("data:text/html, diff --git a/docshell/test/test_bug637644.html b/docshell/test/test_bug637644.html index d172ada4a..4192fae22 100644 --- a/docshell/test/test_bug637644.html +++ b/docshell/test/test_bug637644.html @@ -43,9 +43,8 @@ window.onmessage = function (ev) { } } -var win2 = window.open("data:text/html, -- cgit v1.2.3