Bug 1481947 - When getting eTLD+1 fails, check if uri is an ip literal or localhost. r=asuth
authorDragana Damjanovic <dd.mozilla@gmail.com>
Mon, 26 Nov 2018 19:43:57 +0000
changeset 504663 a9127ac945bd49e22fd62cdb0c1305a866c2b2ce
parent 504662 99da1452e409ddf36bcdc827aa13c6241092cbc0
child 504664 0a594d7bf930fd83c3eb5da8daefbd8633c58bb6
push id10290
push userffxbld-merge
push dateMon, 03 Dec 2018 16:23:23 +0000
treeherdermozilla-beta@700bed2445e6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersasuth
bugs1481947
milestone65.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1481947 - When getting eTLD+1 fails, check if uri is an ip literal or localhost. r=asuth Differential Revision: https://phabricator.services.mozilla.com/D12739
netwerk/protocol/http/HttpBaseChannel.cpp
--- a/netwerk/protocol/http/HttpBaseChannel.cpp
+++ b/netwerk/protocol/http/HttpBaseChannel.cpp
@@ -1864,19 +1864,37 @@ HttpBaseChannel::SetReferrerWithPolicy(n
   if (userReferrerXOriginPolicy == 1) {
     nsAutoCString currentDomain = currentHost;
     nsAutoCString referrerDomain = referrerHost;
     uint32_t extraDomains = 0;
     nsCOMPtr<nsIEffectiveTLDService> eTLDService = do_GetService(
       NS_EFFECTIVETLDSERVICE_CONTRACTID);
     if (eTLDService) {
       rv = eTLDService->GetBaseDomain(mURI, extraDomains, currentDomain);
-      if (NS_FAILED(rv)) return rv;
+      if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
+          rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
+        // mURI is either an IP address, an alias such as 'localhost', an eTLD
+        // such as 'co.uk', or the empty string. Uses the normalized host in
+        // such cases.
+        rv = mURI->GetAsciiHost(currentDomain);
+      }
+      if (NS_FAILED(rv)) {
+        return rv;
+      }
       rv = eTLDService->GetBaseDomain(clone, extraDomains, referrerDomain);
-      if (NS_FAILED(rv)) return rv;
+      if (rv == NS_ERROR_HOST_IS_IP_ADDRESS ||
+          rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS) {
+        // clone is either an IP address, an alias such as 'localhost', an eTLD
+        // such as 'co.uk', or the empty string. Uses the normalized host in
+        // such cases.
+        rv = clone->GetAsciiHost(referrerDomain);
+      }
+      if (NS_FAILED(rv)) {
+        return rv;
+      }
     }
 
     // check policy for sending only when effective top level domain matches.
     // this falls back on using host if eTLDService does not work
     if (!currentDomain.Equals(referrerDomain))
       return NS_OK;
   }