Skip to content
This repository was archived by the owner on Nov 6, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions chromium/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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:") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This if clause is redundant and should probably be removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's actually not: the previous clause (if (shouldCancel)) covers the case where the request started with an HTTP request. This clause (if (newuristr && newuristr.substring(0, 5) === "http:")) covers the case where we started on an HTTPS page and got redirected to HTTP (by 301 or by a downgrade rule).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I rescind my comments then.

// Abort early if we're about to redirect to HTTP in HTTP Nowhere mode
return {cancel: true};
Expand Down
24 changes: 17 additions & 7 deletions src/chrome/content/code/HTTPS.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down