From 7753e8c47c20f030c64d0eb784df9ddb52f78a4c Mon Sep 17 00:00:00 2001 From: Jacob Hoffman-Andrews Date: Mon, 24 Oct 2016 21:20:40 -0700 Subject: [PATCH 1/2] In HTTP Nowhere mode, attempt HTTPS before block. This applies to both main frame resources and subresource loads, though in practice only image subresources get a chance to be rewritten, due to mixed content blocking. Loop detection still works, so pages that redirect back to HTTP will get caught by that and eventually get the "cancelled by extension" message. --- chromium/background.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/chromium/background.js b/chromium/background.js index b3c501a265b9..e0dc0ee6b213 100644 --- a/chromium/background.js +++ b/chromium/background.js @@ -241,8 +241,6 @@ function onBeforeRequest(details) { } var potentiallyApplicable = all_rules.potentiallyApplicableRulesets(uri.hostname); - // If no rulesets could apply, let's get out of here! - if (potentiallyApplicable.size === 0) { return {cancel: shouldCancel}; } if (redirectCounter[details.requestId] >= 8) { log(NOTE, "Redirect counter hit for " + canonical_url); @@ -282,6 +280,15 @@ function onBeforeRequest(details) { } if (httpNowhereOn) { + // If loading a main frame, try the HTTPS version as an alternative to + // failing. + if (shouldCancel) { + if (!newuristr) { + return {redirectUrl: canonical_url.replace(/^http:/, "https:")}; + } else { + return {redirectUrl: newuristr.replace(/^http:/, "https:")}; + } + } if (newuristr && newuristr.substring(0, 5) === "http:") { // Abort early if we're about to redirect to HTTP in HTTP Nowhere mode return {cancel: true}; From 51769be5fd966b8a6fe464512ab1268ba465a28e Mon Sep 17 00:00:00 2001 From: William Budington Date: Fri, 4 Nov 2016 17:27:58 -0700 Subject: [PATCH 2/2] Implement for XPCOM: HTTP Nowhere attempting HTTPS before blocking --- src/chrome/content/code/HTTPS.js | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/chrome/content/code/HTTPS.js b/src/chrome/content/code/HTTPS.js index 1ba27b4a0101..7ab22c4c36e7 100644 --- a/src/chrome/content/code/HTTPS.js +++ b/src/chrome/content/code/HTTPS.js @@ -42,14 +42,22 @@ const HTTPS = { var blob = HTTPSRules.rewrittenURI(applicable_list, channel.URI.clone()); var isSTS = securityService.isSecureURI( CI.nsISiteSecurityService.HEADER_HSTS, channel.URI, 0); + var uri; if (blob === null) { // Abort insecure non-onion requests if HTTP Nowhere is on if (httpNowhereEnabled && channel.URI.schemeIs("http") && !isSTS && !/\.onion$/.test(channel.URI.host)) { - IOUtil.abort(channel); + var newurl = channel.URI.spec.replace(/^http:/, "https:"); + uri = CC["@mozilla.org/network/standard-url;1"]. + createInstance(CI.nsIStandardURL); + uri.init(CI.nsIStandardURL.URLTYPE_STANDARD, 443, + newurl, channel.URI.originCharset, null); + uri = uri.QueryInterface(CI.nsIURI); + } else { + return false; // no rewrite } - return false; // no rewrite + } else { + uri = blob.newuri; } - var uri = blob.newuri; if (!uri) this.log(WARN, "OH NO BAD ARGH\nARGH"); // Abort downgrading if HTTP Nowhere is on @@ -66,11 +74,13 @@ const HTTPS = { if (c2.redirectionLimit < 10) { this.log(WARN, "Redirection loop trying to set HTTPS on:\n " + channel.URI.spec +"\n(falling back to HTTP)"); - if (!blob.applied_ruleset) { - this.log(WARN,"Blacklisting rule for: " + channel.URI.spec); - https_everywhere_blacklist[channel.URI.spec] = true; + if (blob) { + if (!blob.applied_ruleset) { + this.log(WARN,"Blacklisting rule for: " + channel.URI.spec); + https_everywhere_blacklist[channel.URI.spec] = true; + } + https_everywhere_blacklist[channel.URI.spec] = blob.applied_ruleset; } - https_everywhere_blacklist[channel.URI.spec] = blob.applied_ruleset; var domain = null; try { domain = channel.URI.host; } catch (e) {} if (domain) https_blacklist_domains[domain] = true;