tor-browser

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

fetch_from_tracker.sjs (4196B)


      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   let params = new URLSearchParams(request.queryString);
      8   response.setHeader("Content-Type", "text/javascript; charset=UTF-8", false);
      9   let rand = params.get("rand");
     10 
     11   let fetchScript = `
     12     results.fetch = "PENDING";
     13     fetch("http://localhost:21555/?type=fetch&rand=${rand}")
     14       .then(_res => {
     15         results.fetch = "OK";
     16       })
     17       .catch(_err => {
     18         results.fetch = "FAIL";
     19       });
     20   `;
     21 
     22   let xhrScript = `
     23     results.xhr = "PENDING";
     24     const xhr = new XMLHttpRequest();
     25     xhr.open("GET", "http://localhost:21555/?type=xhr&rand=${rand}");
     26     xhr.onload = () => results.xhr = xhr.status === 200 ? "OK" : "FAIL";
     27     xhr.onerror = () => results.xhr = "FAIL";
     28     xhr.send();
     29   `;
     30 
     31   let imgScript = `
     32     results.img = "PENDING";
     33     const img = document.createElement('img');
     34     img.src = 'http://localhost:21555/?type=img&rand=${rand}';
     35     img.alt = 'Injected Image';
     36     img.onload = () => results.img = "OK";
     37     img.onerror = () => results.img = "FAIL";
     38     document.body.appendChild(img);
     39   `;
     40 
     41   let cssScript = `
     42     results.css = "PENDING";
     43     const link = document.createElement('link');
     44     link.rel = 'stylesheet';
     45     link.href = 'http://localhost:21555/?type=css&rand=${rand}';
     46     link.onload = () => results.css = "OK";
     47     link.onerror = () => results.css = "FAIL";
     48     document.head.appendChild(link);
     49   `;
     50 
     51   let videoScript = `
     52     results.video = "PENDING";
     53     const video = document.createElement('video');
     54     video.src = 'http://localhost:21555/?type=video&rand=${rand}';
     55     video.onloadeddata = () => results.video = "OK";
     56     video.onerror = () => results.video = "FAIL";
     57     document.body.appendChild(video);
     58   `;
     59 
     60   let audioScript = `
     61     results.audio = "PENDING";
     62     const audio = document.createElement('audio');
     63     audio.src = 'http://localhost:21555/?type=audio&rand=${rand}';
     64     audio.onloadeddata = () => results.audio = "OK";
     65     audio.onerror = () => results.audio = "FAIL";
     66     document.body.appendChild(audio);
     67   `;
     68 
     69   let iframeScript = `
     70     results.iframe = "PENDING";
     71     const iframe = document.createElement('iframe');
     72     iframe.src = 'http://localhost:21555/?type=iframe&rand=${rand}';
     73     iframe.onload = () => results.iframe = "OK";
     74     iframe.onerror = () => results.iframe = "FAIL";
     75     document.body.appendChild(iframe);
     76   `;
     77 
     78   let scriptScript = `
     79     results.script = "PENDING";
     80     const script = document.createElement('script');
     81     script.src = 'http://localhost:21555/?type=script&rand=${rand}';
     82     script.onload = () => results.script = "OK";
     83     script.onerror = () => results.script = "FAIL";
     84     document.head.appendChild(script);
     85   `;
     86 
     87   let fontScript = `
     88     results.font = "PENDING";
     89     const font = new FontFace('TestFont', 'url(http://localhost:21555/?type=font&rand=${rand})');
     90     font.load().then(() => {
     91       document.fonts.add(font);
     92       results.font = "OK";
     93     }).catch(() => {
     94       results.font = "FAIL";
     95     });
     96   `;
     97 
     98   let websocketScript = `
     99     results.websocket = "PENDING";
    100     try {
    101       const ws = new WebSocket("ws://localhost:21555/?type=websocket&rand=${rand}");
    102       ws.onopen = () => results.websocket = "OK";
    103       ws.onerror = () => results.websocket = "FAIL";
    104     } catch (e) {
    105       results.websocket = "FAIL";
    106     }
    107   `;
    108 
    109   switch (params.get("test")) {
    110     case "fetch":
    111       response.write(fetchScript);
    112       return;
    113     case "xhr":
    114       response.write(xhrScript);
    115       return;
    116     case "img":
    117       response.write(imgScript);
    118       return;
    119     case "css":
    120       response.write(cssScript);
    121       return;
    122     case "video":
    123       response.write(videoScript);
    124       return;
    125     case "audio":
    126       response.write(audioScript);
    127       return;
    128     case "iframe":
    129       response.write(iframeScript);
    130       return;
    131     case "script":
    132       response.write(scriptScript);
    133       return;
    134     case "font":
    135       response.write(fontScript);
    136       return;
    137     case "websocket":
    138       response.write(websocketScript);
    139       return;
    140   }
    141   response.write(`console.log("unknown test type")`);
    142 }