tor-browser

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

set-samesite-cookies-and-redirect.sjs (1484B)


      1 /* Any copyright is dedicated to the Public Domain.
      2    http://creativecommons.org/publicdomain/zero/1.0/ */
      3 
      4 "use strict";
      5 
      6 function handleRequest(request, response) {
      7   // Set cookies and redirect for .org:
      8   if (request.host.endsWith(".org")) {
      9     response.setHeader("Set-Cookie", "normalCookie=true; path=/;", true);
     10     response.setHeader(
     11       "Set-Cookie",
     12       "laxHeader=true; path=/; SameSite=Lax",
     13       true
     14     );
     15     response.setHeader(
     16       "Set-Cookie",
     17       "strictHeader=true; path=/; SameSite=Strict",
     18       true
     19     );
     20     response.setHeader("Content-Type", "text/html");
     21     response.write(`
     22       <head>
     23         <meta http-equiv='set-cookie' content='laxMeta=true; path=/; SameSite=Lax'>
     24         <meta http-equiv='set-cookie' content='strictMeta=true; path=/; SameSite=Strict'>
     25       </head>
     26       <body>
     27         <script>
     28         document.cookie = 'laxScript=true; path=/; SameSite=Lax';
     29         document.cookie = 'strictScript=true; path=/; SameSite=Strict';
     30         location.href = location.href.replace(/\.org/, ".com");
     31         </script>
     32       </body>`);
     33   } else {
     34     let baseURI =
     35       "https://example.org/" +
     36       request.path.replace(/[a-z-]*\.sjs/, "mimeme.sjs?type=");
     37     response.setHeader("Content-Type", "text/html");
     38     response.write(`
     39       <link rel="stylesheet" type="text/css" href="${baseURI}css">
     40       <iframe src="${baseURI}html"></iframe>
     41       <script src="${baseURI}js"></script>
     42       <img src="${baseURI}png">
     43     `);
     44   }
     45 }