tor-browser

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

file_same_site_cookies_toplevel_set_cookie.sjs (1779B)


      1 // Custom *.sjs file specifically for the needs of Bug 1454242
      2 
      3 const WIN = `
      4   <html>
      5   <body>
      6   <script type="application/javascript">
      7     let newWin = window.open("http://mochi.test:8888/tests/dom/security/test/general/file_same_site_cookies_toplevel_set_cookie.sjs?loadWinAndSetCookie");
      8     newWin.onload = function() {
      9       newWin.close();
     10     }
     11   </script>
     12   </body>
     13   </html>`;
     14 
     15 const DUMMY_WIN = `
     16   <html>
     17   <body>
     18   just a dummy window that sets a same-site=lax cookie
     19   <script type="application/javascript">
     20     window.opener.opener.postMessage({value: 'testSetupComplete'}, '*');
     21   </script>
     22   </body>
     23   </html>`;
     24 
     25 const FRAME = `
     26   <html>
     27   <body>
     28   <script type="application/javascript">
     29     let cookie = document.cookie;
     30     // now reset the cookie for the next test
     31     document.cookie = "myKey=;" + "expires=Thu, 01 Jan 1970 00:00:00 GMT";
     32     window.parent.postMessage({value: cookie}, 'http://mochi.test:8888');
     33   </script>
     34   </body>
     35   </html>`;
     36 
     37 const SAME_ORIGIN = "http://mochi.test:8888/";
     38 const CROSS_ORIGIN = "http://example.com/";
     39 const PATH =
     40   "tests/dom/security/test/general/file_same_site_cookies_redirect.sjs";
     41 
     42 function handleRequest(request, response) {
     43   // avoid confusing cache behaviors
     44   response.setHeader("Cache-Control", "no-cache", false);
     45 
     46   if (request.queryString === "loadWin") {
     47     response.write(WIN);
     48     return;
     49   }
     50 
     51   if (request.queryString === "loadWinAndSetCookie") {
     52     response.setHeader(
     53       "Set-Cookie",
     54       "myKey=laxSameSiteCookie; samesite=lax",
     55       true
     56     );
     57     response.write(DUMMY_WIN);
     58     return;
     59   }
     60 
     61   if (request.queryString === "checkCookie") {
     62     response.write(FRAME);
     63     return;
     64   }
     65 
     66   // we should never get here, but just in case return something unexpected
     67   response.write("D'oh");
     68 }