Bug 1325955 - Prevent providing wrong baseDomain if scheme is not recognized. r=sebastian, a=gchang
authorJulian_Chu <walkingice0204@gmail.com>
Mon, 27 Mar 2017 17:00:37 -0400
changeset 379278 a9e49ecff8894d8705095c02ffe19e8a1da61905
parent 379277 acd954655ea8e5046e6c83e393540bedd4c2bfb8
child 379279 07f281ba59547dfc6a70b6fe837fa70ac3992421
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssebastian, gchang
bugs1325955
milestone53.0
Bug 1325955 - Prevent providing wrong baseDomain if scheme is not recognized. r=sebastian, a=gchang If location change to some special scheme, we might misuse the location to parse domain. Now only get base domain from host if the scheme is recognized.(http/https/ftp) MozReview-Commit-ID: 4MkrNfsUJqQ
mobile/android/chrome/content/browser.js
--- a/mobile/android/chrome/content/browser.js
+++ b/mobile/android/chrome/content/browser.js
@@ -4308,31 +4308,23 @@ Tab.prototype = {
     }
 
     // Reset state of click-to-play plugin notifications.
     clearTimeout(this.pluginDoorhangerTimeout);
     this.pluginDoorhangerTimeout = null;
     this.shouldShowPluginDoorhanger = true;
     this.clickToPlayPluginsActivated = false;
 
-    let documentURI = contentWin.document.documentURIObject.spec;
-
-    // If reader mode, get the base domain for the original url.
-    let strippedURI = this._stripAboutReaderURL(documentURI);
-
-    // Borrowed from desktop Firefox: http://hg.mozilla.org/mozilla-central/annotate/72835344333f/browser/base/content/urlbarBindings.xml#l236
-    let matchedURL = strippedURI.match(/^((?:[a-z]+:\/\/)?(?:[^\/]+@)?)(.+?)(?::\d+)?(?:\/|$)/);
     let baseDomain = "";
-    if (matchedURL) {
-      var domain = "";
-      [, , domain] = matchedURL;
-
+    // For recognized scheme, get base domain from host.
+    let principalURI = contentWin.document.nodePrincipal.URI;
+    if (principalURI && ["http", "https", "ftp"].includes(principalURI.scheme) && principalURI.host) {
       try {
-        baseDomain = Services.eTLD.getBaseDomainFromHost(domain);
-        if (!domain.endsWith(baseDomain)) {
+        baseDomain = Services.eTLD.getBaseDomainFromHost(principalURI.host);
+        if (!principalURI.host.endsWith(baseDomain)) {
           // getBaseDomainFromHost converts its resultant to ACE.
           let IDNService = Cc["@mozilla.org/network/idn-service;1"].getService(Ci.nsIIDNService);
           baseDomain = IDNService.convertACEtoUTF8(baseDomain);
         }
       } catch (e) {}
     }
 
     // If we are navigating to a new location with a different host,