Skip to content

Commit

Permalink
Bug 31562: Fix circuit display for error pages
Browse files Browse the repository at this point in the history
  • Loading branch information
acatarineu committed Sep 6, 2019
1 parent 1edfec5 commit 33f4fb1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
2 changes: 1 addition & 1 deletion chrome/content/torbutton.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ function torbutton_send_ctrl_cmd(command) {

// Bug 1506 P4: Needed for New IP Address
function torbutton_new_circuit() {
let firstPartyDomain = getDomainForBrowser(gBrowser);
let firstPartyDomain = getDomainForBrowser(gBrowser.selectedBrowser);

let domainIsolator = Cc["@torproject.org/domain-isolator;1"]
.getService(Ci.nsISupports).wrappedJSObject;
Expand Down
49 changes: 25 additions & 24 deletions modules/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
// ### Import Mozilla Services
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

// ### About firstPartyDomain literal
const k_tb_about_uri_first_party_domain = "about.ef2a7dd5-93bc-417f-a698-142c3116864f.mozilla";

// ## Pref utils

// __prefs__. A shortcut to Mozilla Services.prefs.
Expand Down Expand Up @@ -212,30 +209,34 @@ var show_torbrowser_manual = () => {
return availableLocales.indexOf(shortLocale) >= 0;
}

var getFPDFromHost = (hostname) => {
try {
return Services.eTLD.getBaseDomainFromHost(hostname);
} catch (e) {
if (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS ||
e.result == Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
return hostname;
}
}
return null;
}

// Assuming this is called with gBrowser.selectedBrowser
var getDomainForBrowser = (browser) => {
let firstPartyDomain = browser.contentPrincipal.originAttributes.firstPartyDomain;
// Bug 22538: For neterror or certerror, get firstPartyDomain causing it from the u param
if (firstPartyDomain === k_tb_about_uri_first_party_domain) {
let knownErrors = ["about:neterror", "about:certerror"];
let origin = browser.contentPrincipal.origin || '';
if (knownErrors.some(x => origin.startsWith(x))) {
try {
let urlOrigin = new URL(origin);
let { hostname } = new URL(urlOrigin.searchParams.get('u'));
if (hostname) {
try {
firstPartyDomain = Services.eTLD.getBaseDomainFromHost(hostname);
} catch (e) {
if (e.result == Cr.NS_ERROR_HOST_IS_IP_ADDRESS ||
e.result == Cr.NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
firstPartyDomain = hostname;
}
}
}
} catch (e) {}
let fpd = browser.contentPrincipal.originAttributes.firstPartyDomain;
// Bug 31562: For neterror or certerror, get the original URL from
// browser.currentURI and use it to calculate the firstPartyDomain.
let knownErrors = ["about:neterror", "about:certerror"];
let documentURI = browser.documentURI;
if (documentURI && documentURI.schemeIs('about') &&
knownErrors.some(x => documentURI.spec.startsWith(x))) {
let knownSchemes = ["http", "https", "ftp"];
let currentURI = browser.currentURI;
if (currentURI && knownSchemes.some(x => currentURI.schemeIs(x))) {
fpd = getFPDFromHost(currentURI.host) || fpd;
}
}
return firstPartyDomain;
return fpd;
};

// Export utility functions for external use.
Expand Down

0 comments on commit 33f4fb1

Please sign in to comment.