diff --git a/tool/block_cloudflare_requests_pm/src/header.js b/tool/block_cloudflare_requests_pm/src/header.js new file mode 100644 index 000000000..3bd0371a5 --- /dev/null +++ b/tool/block_cloudflare_requests_pm/src/header.js @@ -0,0 +1,35 @@ +const Cc = Components.classes, + Ci = Components.interfaces; +function ignoreCF(h) { + return /(cloudflare(\-(dns|free|ipfs|quic)|(support|warp)))\.com$/.test(h) ? true : false; +} +let knownCF = []; +let CFBlocking = { + observe: function (subject, topic, data) { + let httpChl = subject.QueryInterface(Ci.nsIHttpChannel), + reqURL = subject.URI.spec; + if (reqURL.indexOf('http') === 0 && reqURL.indexOf('.archive.org/') === -1) { + let hostN = (new URL(reqURL)).hostname; + if (topic == 'http-on-modify-request') { + if (knownCF.includes(hostN)) { + httpChl.cancel(Cr.NS_BINDING_ABORTED); + } + } + if (topic == 'http-on-examine-response') { + let rayid = ''; + try { + rayid = httpChl.getResponseHeader('cf-ray'); + } catch (e) {} + if (rayid.length > 3) { + if (!knownCF.includes(hostN) && !ignoreCF(hostN)) { + knownCF.push(hostN); + } + httpChl.cancel(Cr.NS_BINDING_ABORTED); + } + } + } + } +}; +let OBS = Cc['@mozilla.org/observer-service;1'].getService(Ci.nsIObserverService); +OBS.addObserver(CFBlocking, 'http-on-modify-request', false); +OBS.addObserver(CFBlocking, 'http-on-examine-response', false); \ No newline at end of file diff --git a/tool/block_cloudflare_requests_pm/src/header.xul b/tool/block_cloudflare_requests_pm/src/header.xul new file mode 100644 index 000000000..cb78e57c9 --- /dev/null +++ b/tool/block_cloudflare_requests_pm/src/header.xul @@ -0,0 +1,4 @@ + + + + \ No newline at end of file