diff options
author | nullius <nullius@nym.zone> | 2017-12-12 04:31:18 +0000 |
---|---|---|
committer | nullius <nullius@nym.zone> | 2017-12-12 04:31:18 +0000 |
commit | 9c4cd9c9841567fdf68919da245f9587bbab78c6 (patch) | |
tree | c564ea0bc1b0b39e7b5a202c4a3f3ea31175078b | |
parent | 5370bb3fe2f34d8de5692a1d710e8548f563a0c5 (diff) | |
download | cloudflare-tor-9c4cd9c9841567fdf68919da245f9587bbab78c6.tar.lz cloudflare-tor-9c4cd9c9841567fdf68919da245f9587bbab78c6.tar.xz cloudflare-tor-9c4cd9c9841567fdf68919da245f9587bbab78c6.zip |
Restyle main Javascript file
I tried to copy the indent style of files seen in Torbutton, with added
guidance from my instincts as a C programmer accustomed to KNF. This
can now be edited without wrecking diffs, unless I change it again
because this will drive me crazy.
Closes issue #1.
-rw-r--r-- | src/stop_cf_mitm.js | 73 |
1 files changed, 42 insertions, 31 deletions
diff --git a/src/stop_cf_mitm.js b/src/stop_cf_mitm.js index f00c9eb2..c438d2bc 100644 --- a/src/stop_cf_mitm.js +++ b/src/stop_cf_mitm.js @@ -1,33 +1,44 @@ -/* - <<< Detect Cloudflare MiTM Attack >>> - by Sw - why? because... - https://trac.torproject.org/projects/tor/ticket/24351 - http://www.crimeflare.com/ -*/ -//=============================================== -function analyzemydata(res){ -//console.log("mitmdetector: scanning: "+res.url); -var cflink=document.createElement('a');cflink.setAttribute('href',res.url); -var cf_hostname=cflink.hostname; -var cf_protocol=cflink.protocol; -var cf_gothead=res.responseHeaders; -cflink=null; -if ((cf_protocol=='http:'||cf_protocol=='https:') && cf_hostname.length>=4){ -//console.log("mitmdetector: testing...: "+res.url); -var is_cloudflare_infected=0;// 2 to confirm -for(var i=0;i<cf_gothead.length;i++){ -var cfv=cf_gothead[i]; -if (cfv['name']=='cf-ray' && cfv['value']!=undefined){is_cloudflare_infected+=1;} -if (cfv['name']=='server' && cfv['value'].includes("cloudflare")){is_cloudflare_infected+=1;} -if (is_cloudflare_infected==2){break;} -} -if (is_cloudflare_infected>=1){ -console.log('SECURITY_WARN: Cloudflare Detected: '+res.url); -return {redirectUrl: "https://0.0.0.0/"};// just drop the connection -} -} -return; +/** + * <<< Detect Cloudflare MiTM Attack >>> + * by Sw + * why? because... + * https://trac.torproject.org/projects/tor/ticket/24351 + * http://www.crimeflare.com/ + */ + +function analyzemydata(res) { + //console.log("mitmdetector: scanning: "+res.url); + var cflink = document.createElement('a'); + cflink.setAttribute('href',res.url); + var cf_hostname = cflink.hostname; + var cf_protocol = cflink.protocol; + var cf_gothead = res.responseHeaders; + cflink = null; + + if ((cf_protocol == 'http:' || cf_protocol == 'https:') && + cf_hostname.length >= 4) { + //console.log("mitmdetector: testing...: "+res.url); + var is_cloudflare_infected=0; // 2 to confirm + + for (var i=0; i < cf_gothead.length; i++) { + var cfv=cf_gothead[i]; + if (cfv['name'] == 'cf-ray' && cfv['value'] != undefined) { + is_cloudflare_infected += 1; + } + if (cfv['name'] == 'server' && cfv['value'].includes("cloudflare")) { + is_cloudflare_infected += 1; + } + if (is_cloudflare_infected == 2) { + break; + } + } + + if (is_cloudflare_infected >= 1) { + console.log('SECURITY_WARN: Cloudflare Detected: '+res.url); + return {redirectUrl: "https://0.0.0.0/"}; // just drop the connection + } + } + return; } + browser.webRequest.onHeadersReceived.addListener(analyzemydata,{urls: ["<all_urls>"]},["blocking","responseHeaders"]); -//
\ No newline at end of file |