[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser/tor-browser-60.6.1esr-8.5-1] Bug 1542309 - Set firstPartyDomain to public suffix if getBaseDomain fails. r=baku



commit c722d57604db58695140d95565a78433989fe9ca
Author: Alex Catarineu <acat@xxxxxxxxxxxxxx>
Date:   Fri Apr 12 15:44:40 2019 +0000

    Bug 1542309 - Set firstPartyDomain to public suffix if getBaseDomain fails. r=baku
    
    Right now the firstPartyDomain is not set when host is in the public suffix list. The patch fixes it by setting firstPartyDomain to eTLD.getPublicSuffix in these cases.
    
    Differential Revision: https://phabricator.services.mozilla.com/D26767
    
    --HG--
    extra : moz-landing-system : lando
---
 caps/OriginAttributes.cpp                 | 11 +++++++++++
 caps/tests/gtest/TestOriginAttributes.cpp | 28 ++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+)

diff --git a/caps/OriginAttributes.cpp b/caps/OriginAttributes.cpp
index 8a501f18010c..7dc79e7c1b9a 100644
--- a/caps/OriginAttributes.cpp
+++ b/caps/OriginAttributes.cpp
@@ -78,6 +78,8 @@ void OriginAttributes::SetFirstPartyDomain(const bool aIsTopLevelDocument,
     return;
   }
 
+  // Saving isInsufficientDomainLevels before rv is overwritten.
+  bool isInsufficientDomainLevels = (rv == NS_ERROR_INSUFFICIENT_DOMAIN_LEVELS);
   nsAutoCString scheme;
   rv = aURI->GetScheme(scheme);
   NS_ENSURE_SUCCESS_VOID(rv);
@@ -96,6 +98,15 @@ void OriginAttributes::SetFirstPartyDomain(const bool aIsTopLevelDocument,
       }
     }
   }
+
+  if (isInsufficientDomainLevels) {
+    nsAutoCString publicSuffix;
+    rv = tldService->GetPublicSuffix(aURI, publicSuffix);
+    if (NS_SUCCEEDED(rv)) {
+      mFirstPartyDomain = NS_ConvertUTF8toUTF16(publicSuffix);
+    }
+    return;
+  }
 }
 
 void OriginAttributes::SetFirstPartyDomain(const bool aIsTopLevelDocument,
diff --git a/caps/tests/gtest/TestOriginAttributes.cpp b/caps/tests/gtest/TestOriginAttributes.cpp
index ffa4349939e4..12090bbbf1a5 100644
--- a/caps/tests/gtest/TestOriginAttributes.cpp
+++ b/caps/tests/gtest/TestOriginAttributes.cpp
@@ -3,8 +3,11 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 #include "gtest/gtest.h"
 #include "mozilla/BasePrincipal.h"
+#include "mozilla/Preferences.h"
+#include "nsNetUtil.h"
 
 using mozilla::OriginAttributes;
+using mozilla::Preferences;
 
 static void TestSuffix(const OriginAttributes& attrs) {
   nsAutoCString suffix;
@@ -17,6 +20,14 @@ static void TestSuffix(const OriginAttributes& attrs) {
   EXPECT_EQ(attrs, attrsFromSuffix);
 }
 
+static void TestFPD(const nsAString &spec, const nsAString &fpd) {
+  OriginAttributes attrs;
+  nsCOMPtr<nsIURI> url;
+  ASSERT_EQ(NS_NewURI(getter_AddRefs(url), spec), NS_OK);
+  attrs.SetFirstPartyDomain(true, url);
+  EXPECT_TRUE(attrs.mFirstPartyDomain.Equals(fpd));
+}
+
 TEST(OriginAttributes, Suffix_default) {
   OriginAttributes attrs;
   TestSuffix(attrs);
@@ -31,3 +42,20 @@ TEST(OriginAttributes, Suffix_maxAppId_inIsolatedMozBrowser) {
   OriginAttributes attrs(4294967295, true);
   TestSuffix(attrs);
 }
+
+TEST(OriginAttributes, FirstPartyDomain_default) {
+  static const char prefKey[] = "privacy.firstparty.isolate";
+  bool oldPref = Preferences::GetBool(prefKey);
+  Preferences::SetBool(prefKey, true);
+  TestFPD(NS_LITERAL_STRING("http://www.example.com";),
+          NS_LITERAL_STRING("example.com"));
+  TestFPD(NS_LITERAL_STRING("http://s3.amazonaws.com";),
+          NS_LITERAL_STRING("s3.amazonaws.com"));
+  TestFPD(NS_LITERAL_STRING("http://com";), NS_LITERAL_STRING("com"));
+  TestFPD(NS_LITERAL_STRING("http://.com";), NS_LITERAL_STRING(""));
+  TestFPD(NS_LITERAL_STRING("http://..com";), NS_LITERAL_STRING(""));
+  TestFPD(NS_LITERAL_STRING("http://127.0.0.1";),
+          NS_LITERAL_STRING("127.0.0.1"));
+  TestFPD(NS_LITERAL_STRING("http://[::1]";), NS_LITERAL_STRING("[::1]"));
+  Preferences::SetBool(prefKey, oldPref);
+}

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits