tor-browser

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

idn_child.html (2002B)


      1 <!DOCTYPE html>
      2 <html>
      3 <head>
      4  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
      5  <title>Child window on a site whose "base" domain contains IDN</title>
      6  <script type="application/javascript">
      7 function run()
      8 {
      9  var target = document.getElementById("location");
     10  target.textContent = location.hostname + ":" + (location.port || 80);
     11 }
     12 
     13 function receiveMessage(evt)
     14 {
     15  if (evt.origin !== "http://mochi.test:8888")
     16    return;
     17 
     18  var message = evt.data + "-response";
     19 
     20  var domain = document.domain;
     21  if (/test$/.test(domain))
     22  {
     23    if (domain !== "sub1.xn--exaple-kqf.test")
     24      message += " wrong-initial-domain(" + domain + ")";
     25  }
     26  else
     27  {
     28    if (domain !== "sub1.xn--hxajbheg2az3al.xn--jxalpdlp")
     29      message += " wrong-initial-domain(" + domain + ")";
     30  }
     31 
     32  switch (location.search)
     33  {
     34    case "?idn-whitelist":
     35      message += idnTest("παράδειγμα.δοκιμή");
     36      break;
     37 
     38    case "?punycode-whitelist":
     39      message  += punycodeTest("xn--hxajbheg2az3al.xn--jxalpdlp");
     40      break;
     41 
     42    case "?idn-nowhitelist":
     43      message += idnTest("exaмple.test");
     44      break;
     45 
     46    case "?punycode-nowhitelist":
     47      message  += punycodeTest("xn--exaple-kqf.test");
     48      break;
     49 
     50    default:
     51      message += " unexpected-query(" + location.search + ")";
     52      break;
     53  }
     54 
     55  evt.source.postMessage(message, evt.origin);
     56 }
     57 
     58 function idnTest(newDomain)
     59 {
     60  var errors = "";
     61 
     62  try
     63  {
     64    document.domain = newDomain;
     65  }
     66  catch (e)
     67  {
     68    errors += " error-thrown-setting-to-idn(" + String(e).split("").join(",") + ")";
     69  }
     70 
     71  return errors;
     72 }
     73 
     74 function punycodeTest(newDomain)
     75 {
     76  var errors = "";
     77 
     78  try
     79  {
     80    document.domain = newDomain;
     81  }
     82  catch (e)
     83  {
     84    errors += " error-thrown-setting-to-punycode(" + String(e).split("").join(",") + ")";
     85  }
     86 
     87  return errors;
     88 }
     89 
     90 window.addEventListener("message", receiveMessage);
     91 window.addEventListener("load", run);
     92  </script>
     93 </head>
     94 <body>
     95 <h1 id="location">Somewhere!</h1>
     96 </body>
     97 </html>