tor-browser

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

file_iframe_test.sjs (1702B)


      1 // Bug 1658264 - HTTPS-Only and iFrames
      2 // see browser_iframe_test.js
      3 
      4 const IFRAME_CONTENT = `
      5 <!DOCTYPE HTML>
      6 <html>
      7   <head><meta charset="utf-8"></head>
      8   <body>Helo Friend!</body>
      9 </html>`;
     10 const DOCUMENT_CONTENT = q => `
     11 <!DOCTYPE HTML>
     12 <html>
     13   <head><meta charset="utf-8"></head>
     14   <body>
     15     <iframe src="http://example.com/browser/dom/security/test/https-only/file_iframe_test.sjs?com-${q}"></iframe>
     16     <iframe src="http://example.org/browser/dom/security/test/https-only/file_iframe_test.sjs?org-${q}"></iframe>
     17   </body>
     18 </html>`;
     19 
     20 function handleRequest(request, response) {
     21   // avoid confusing cache behaviors
     22   response.setHeader("Cache-Control", "no-cache", false);
     23   let queryString = request.queryString;
     24   const queryScheme = request.scheme;
     25 
     26   // Setup the state with an empty string and return "ok"
     27   if (queryString == "setup") {
     28     setState("receivedQueries", "");
     29     response.write("ok");
     30     return;
     31   }
     32 
     33   let receivedQueries = getState("receivedQueries");
     34 
     35   // Return result-string
     36   if (queryString == "results") {
     37     response.write(receivedQueries);
     38     return;
     39   }
     40 
     41   // Add semicolon to seperate strings
     42   if (receivedQueries !== "") {
     43     receivedQueries += ";";
     44   }
     45 
     46   // Requests from iFrames start with com or org
     47   if (queryString.startsWith("com-") || queryString.startsWith("org-")) {
     48     receivedQueries += queryString;
     49     setState("receivedQueries", `${receivedQueries}-${queryScheme}`);
     50     response.write(IFRAME_CONTENT);
     51     return;
     52   }
     53 
     54   // Everything else has to be a top-level request
     55   receivedQueries += `top-${queryString}`;
     56   setState("receivedQueries", `${receivedQueries}-${queryScheme}`);
     57   response.write(DOCUMENT_CONTENT(queryString));
     58 }