tor-browser

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

file_redirect.sjs (1305B)


      1 // https://bugzilla.mozilla.org/show_bug.cgi?id=1613063
      2 
      3 // Step 1. Send request with redirect queryString (eg. file_redirect.sjs?302)
      4 // Step 2. Server responds with corresponding redirect code to http://example.com/../file_redirect.sjs?check
      5 // Step 3. Response from ?check indicates whether the redirected request was secure or not.
      6 
      7 const RESPONSE_SECURE = "secure-ok";
      8 const RESPONSE_INSECURE = "secure-error";
      9 const RESPONSE_ERROR = "unexpected-query";
     10 
     11 function handleRequest(request, response) {
     12   response.setHeader("Cache-Control", "no-cache", false);
     13 
     14   const query = request.queryString;
     15 
     16   // Send redirect header
     17   if ((query >= 301 && query <= 303) || query == 307) {
     18     const loc =
     19       "http://example.com/tests/dom/security/test/https-only/file_redirect.sjs?check";
     20     response.setStatusLine(request.httpVersion, query, "Moved");
     21     response.setHeader("Location", loc, false);
     22     return;
     23   }
     24 
     25   // Check if scheme is http:// oder https://
     26   if (query == "check") {
     27     const secure =
     28       request.scheme == "https" ? RESPONSE_SECURE : RESPONSE_INSECURE;
     29     response.setStatusLine(request.httpVersion, 200, "OK");
     30     response.write(secure);
     31     return;
     32   }
     33 
     34   // This should not happen
     35   response.setStatusLine(request.httpVersion, 500, "OK");
     36   response.write(RESPONSE_ERROR);
     37 }