tor-browser

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

test_iframe_sandbox_srcdoc.html (1908B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <meta charset="utf-8">
      5  <title>Bug 1073952 - CSP should restrict scripts in srcdoc iframe even if sandboxed</title>
      6  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <p id="display">Bug 1073952</p>
     11 <iframe style="width:200px;height:200px;" id='cspframe'></iframe>
     12 <script class="testbody" type="text/javascript">
     13 
     14 // This is used to watch the blocked data bounce off CSP and allowed data
     15 // get sent out to the wire.
     16 function examiner() {
     17  SpecialPowers.addObserver(this, "csp-on-violate-policy");
     18 }
     19 
     20 examiner.prototype  = {
     21  observe(subject, topic, data) {
     22 
     23    if(topic === "csp-on-violate-policy") {
     24      var violationString = SpecialPowers.getPrivilegedProps(SpecialPowers.
     25                             do_QueryInterface(subject, "nsISupportsCString"), "data");
     26      // the violation subject for inline script violations is unfortunately vague,
     27      // all we can do is match the string.
     28      if (!violationString.includes("Inline Script")) {
     29        return
     30      }
     31      ok(true, "CSP inherited into sandboxed srcdoc iframe, script blocked.");
     32      window.testFinished();
     33    }
     34  },
     35 
     36  // must eventually call this to remove the listener,
     37  // or mochitests might get borked.
     38  remove() {
     39    SpecialPowers.removeObserver(this, "csp-on-violate-policy");
     40  }
     41 }
     42 
     43 window.examiner = new examiner();
     44 
     45 function testFinished() {
     46  window.examiner.remove();
     47  SimpleTest.finish();
     48 }
     49 
     50 addEventListener("message", function(e) {
     51  ok(false, "We should not execute JS in srcdoc iframe.");
     52  window.testFinished();
     53 })
     54 SimpleTest.waitForExplicitFinish();
     55 
     56 // save this for last so that our listeners are registered.
     57 // ... this loads the testbed of good and bad requests.
     58 document.getElementById('cspframe').src = 'file_iframe_sandbox_srcdoc.html';
     59 
     60 </script>
     61 </body>
     62 </html>