tor-browser

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

frameStorageNullprincipal.sjs (1476B)


      1 // This is a sjs file which reads in frameStoragePrevented.html, and writes it out as a data: URI, which this page redirects to.
      2 // This produces a URI with the null principal, which should be unable to access storage.
      3 // We append the #nullprincipal hash to the end of the data: URI to tell the script that it shouldn't try to spawn a webworker,
      4 // as it won't be allowed to, as it has a null principal.
      5 
      6 function handleRequest(request, response) {
      7   // Get the nsIFile for frameStoragePrevented.html
      8   var file;
      9   getObjectState("SERVER_ROOT", function (serverRoot) {
     10     file = serverRoot.getFile(
     11       "/tests/dom/tests/mochitest/general/frameStoragePrevented.html"
     12     );
     13   });
     14 
     15   // Set up the file streams to read in the file as UTF-8
     16   let fstream = Cc["@mozilla.org/network/file-input-stream;1"].createInstance(
     17     Ci.nsIFileInputStream
     18   );
     19   fstream.init(file, -1, 0, 0);
     20   let cstream = Cc["@mozilla.org/intl/converter-input-stream;1"].createInstance(
     21     Ci.nsIConverterInputStream
     22   );
     23   cstream.init(fstream, "UTF-8", 0, 0);
     24 
     25   // Read in the file, and concatenate it onto the data string
     26   let data = "";
     27   let str = {};
     28   let read = 0;
     29   do {
     30     read = cstream.readString(0xffffffff, str);
     31     data += str.value;
     32   } while (read != 0);
     33 
     34   // Write out the file as a data: URI, and redirect to it
     35   response.setStatusLine("1.1", 302, "Found");
     36   response.setHeader(
     37     "Location",
     38     "data:text/html," + encodeURIComponent(data) + "#nullprincipal"
     39   );
     40 }