tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_parent_navigation_by_location.html (2408B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <!--
      4 https://bugzilla.mozilla.org/show_bug.cgi?id=785310
      5 html5 sandboxed iframe should not be able to perform top navigation with scripts allowed
      6 -->
      7 <head>
      8 <meta charset="utf-8">
      9 <title>Test for Bug 785310 - iframe sandbox parent navigation by location tests</title>
     10 <script src="/tests/SimpleTest/SimpleTest.js"></script>
     11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     12 
     13 <script>
     14  SimpleTest.waitForExplicitFinish();
     15 
     16  function runScriptNavigationTest(testCase) {
     17    window.onmessage = function(event) {
     18      if (event.data != "parentIframe") {
     19        ok(false, "event.data: got '" + event.data + "', expected 'parentIframe'");
     20      }
     21      ok(false, testCase.desc + " - parent navigation was NOT blocked");
     22      runNextTest();
     23    };
     24    try {
     25      window.parentIframe.childIframe.eval(testCase.script);
     26    } catch (e) {
     27      ok(true, testCase.desc + " - " + e.message);
     28      runNextTest();
     29    }
     30  }
     31 
     32  var testCaseIndex = -1;
     33  var testCases = [
     34    {
     35      desc: "Test 1: parent.location.replace should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
     36      script: "parent.location.replace('file_parent_navigation_by_location.html')",
     37    },
     38    {
     39      desc: "Test 2: parent.location.assign should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
     40      script: "parent.location.assign('file_parent_navigation_by_location.html')",
     41    },
     42    {
     43      desc: "Test 3: parent.location.href should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
     44      script: "parent.location.href = 'file_parent_navigation_by_location.html'",
     45    },
     46    {
     47      desc: "Test 4: parent.location.hash should be blocked even when sandboxed with allow-same-origin allow-top-navigation",
     48      script: "parent.location.hash = 'wibble'",
     49    },
     50  ];
     51 
     52  function runNextTest() {
     53    ++testCaseIndex;
     54    if (testCaseIndex == testCases.length) {
     55      SimpleTest.finish();
     56      return;
     57    }
     58 
     59    runScriptNavigationTest(testCases[testCaseIndex]);
     60  }
     61 
     62  window.onmessage = runNextTest;
     63 </script>
     64 </head>
     65 <body>
     66 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=785310">Mozilla Bug 785310</a>
     67 <p id="display"></p>
     68 <div id="content">
     69 Tests for Bug 785310
     70 </div>
     71 
     72 <iframe name="parentIframe" src="file_parent_navigation_by_location.html"></iframe>
     73 
     74 </body>
     75 </html>