tor-browser

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

noreferrer-window-name.html (3660B)


      1 <!doctype html>
      2 <title>rel=noreferrer and reuse of names</title>
      3 <meta name="timeout" content="long">
      4 <script src="/resources/testharness.js"></script>
      5 <script src="/resources/testharnessreport.js"></script>
      6 <div id="log"></div>
      7 <script>
      8  async_test(function(t) {
      9    localStorage.clear()
     10 
     11    function makeHyperlink(n) {
     12      var hyperlink = document.body.appendChild(document.createElement("a"))
     13      hyperlink.rel = "noreferrer"
     14      hyperlink.target = "sufficientlyrandomwindownameamiright"
     15      hyperlink.href = "resources/noreferrer-window-name.html#" + n
     16      return hyperlink
     17    }
     18 
     19    var hyperlink1 = makeHyperlink(1),
     20        hyperlink2 = makeHyperlink(2)
     21 
     22    t.add_cleanup(function() {
     23      localStorage.setItem("x", "close")
     24      localStorage.clear()
     25      document.body.removeChild(hyperlink1)
     26      document.body.removeChild(hyperlink2)
     27    })
     28 
     29    addEventListener("storage", function(e) {
     30      t.step(function() {
     31        if(localStorage.getItem("window1") && localStorage.getItem("window2")) {
     32          localStorage.setItem("x", "close")
     33          t.done()
     34        }
     35      })
     36    })
     37 
     38    hyperlink1.click()
     39    hyperlink2.click()
     40  }, "Following a noreferrer link with a named target should not cause creation of a window that can be targeted by another noreferrer link with the same named target");
     41 
     42  async_test(function(t) {
     43    var ifr = document.createElement("iframe");
     44    ifr.name = "sufficientlyrandomwindownameamiright2";
     45    ifr.onload = t.step_func(function() {
     46      var hyperlink = document.body.appendChild(document.createElement("a"));
     47      t.add_cleanup(function() {
     48        hyperlink.remove();
     49      });
     50      hyperlink.rel = "noreferrer";
     51      hyperlink.href = URL.createObjectURL(new Blob(["hello subframe"],
     52                                                    { type: "text/html"}));
     53      hyperlink.target = "sufficientlyrandomwindownameamiright2";
     54      ifr.onload = t.step_func_done(function() {
     55        assert_equals(ifr.contentDocument.documentElement.textContent,
     56                      "hello subframe");
     57      });
     58      hyperlink.click();
     59    });
     60    document.body.appendChild(ifr);
     61    t.add_cleanup(function() {
     62      ifr.remove();
     63    });
     64  }, "Targeting a rel=noreferrer link at an existing named subframe should work");
     65 
     66  async_test(function(t) {
     67    var win = window.open("", "sufficientlyrandomwindownameamiright3");
     68    t.add_cleanup(() => win.close());
     69 
     70    const channel = new BroadcastChannel('sufficientlyrandomchannelnameamiright3');
     71    t.add_cleanup(() => channel.close());
     72 
     73    const targetHtml = `
     74      <script>
     75        const channel = new BroadcastChannel('sufficientlyrandomchannelnameamiright3');
     76        channel.postMessage({ name: window.name, hasOpener: window.opener === null });
     77      </scr`+`ipt>
     78    `;
     79 
     80    var hyperlink = document.body.appendChild(document.createElement("a"));
     81    t.add_cleanup(() => hyperlink.remove());
     82    hyperlink.rel = "noreferrer";
     83    hyperlink.href = URL.createObjectURL(new Blob([targetHtml],
     84                                                  { type: "text/html"}));
     85    hyperlink.target = "sufficientlyrandomwindownameamiright3";
     86 
     87    // win already loaded about:blank, the next load won't reuse the window. So we cannot
     88    // add a load listener and rather need to use a channel.
     89    channel.onmessage = t.step_func_done(function({ data }) {
     90      assert_equals(data.name, 'sufficientlyrandomwindownameamiright3');
     91      assert_equals(data.hasOpener, false);
     92      assert_equals(win.location.href, hyperlink.href);
     93    });
     94 
     95    hyperlink.click();
     96  }, "Targeting a rel=noreferrer link at an existing named window should work");
     97 </script>