tor-browser

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

test_strict_dynamic_parser_inserted.html (3002B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>Bug 1299483 - CSP: Implement 'strict-dynamic'</title>
      5  <!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
      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  <iframe style="width:100%;" id="testframe"></iframe>
     11 
     12 <script class="testbody" type="text/javascript">
     13 
     14 SimpleTest.waitForExplicitFinish();
     15 
     16 /* Description of the test:
     17 * We loader parser and non parser inserted scripts making sure that
     18 * parser inserted scripts are blocked if strict-dynamic is present
     19 * and no valid nonce and also making sure that non-parser inserted
     20 * scripts are allowed to execute.
     21 */
     22 
     23 var tests = [
     24  {
     25    desc: "(parser inserted script) using doc.write(<script>) should be blocked",
     26    result: "blocked",
     27    file: "file_strict_dynamic_parser_inserted_doc_write.html",
     28    policy: "script-src 'strict-dynamic' 'nonce-foo' http:"
     29  },
     30  {
     31    desc: "(parser inserted script with valid nonce) using doc.write(<script>) should be allowed",
     32    result: "allowed",
     33    file: "file_strict_dynamic_parser_inserted_doc_write_correct_nonce.html",
     34    policy: "script-src 'strict-dynamic' 'nonce-foo' https:"
     35  },
     36  {
     37    desc: "(non parser inserted script) using appendChild() should allow external script",
     38    result: "allowed",
     39    file: "file_strict_dynamic_non_parser_inserted.html",
     40    policy: "script-src 'strict-dynamic' 'nonce-foo' https:"
     41  },
     42  {
     43     desc: "(non parser inserted script) using appendChild() should allow inline script",
     44     result: "allowed",
     45     file: "file_strict_dynamic_non_parser_inserted_inline.html",
     46     policy: "script-src 'strict-dynamic' 'nonce-foo' https:"
     47  },
     48  {
     49     desc: "strict-dynamic should not invalidate 'unsafe-eval'",
     50     result: "allowed",
     51     file: "file_strict_dynamic_unsafe_eval.html",
     52     policy: "script-src 'strict-dynamic' 'nonce-foo' 'unsafe-eval'"
     53   },
     54 ];
     55 
     56 var counter = 0;
     57 var curTest;
     58 
     59 function loadNextTest() {
     60  if (counter == tests.length) {
     61    SimpleTest.finish();
     62    return;
     63  }
     64 
     65  curTest = tests[counter++];
     66  var src = "file_testserver.sjs?file=";
     67  // append the file that should be served
     68  src += escape("tests/dom/security/test/csp/" + curTest.file)
     69  // append the CSP that should be used to serve the file
     70  src += "&csp=" + escape(curTest.policy);
     71 
     72  document.getElementById("testframe").addEventListener("load", test);
     73  document.getElementById("testframe").src = src;
     74 }
     75 
     76 function test() {
     77  try {
     78    document.getElementById("testframe").removeEventListener('load', test);
     79    var testframe = document.getElementById("testframe");
     80    var divcontent = testframe.contentWindow.document.getElementById('testdiv').innerHTML;
     81    is(divcontent, curTest.result, curTest.desc);
     82  }
     83  catch (e) {
     84    ok(false, "ERROR: could not access content for test: '" + curTest.desc + "'");
     85  }
     86  loadNextTest();
     87 }
     88 
     89 // start running the tests
     90 loadNextTest();
     91 
     92 </script>
     93 </body>
     94 </html>