author | Alex Catarineu <acat@torproject.org> |
Fri, 12 Apr 2019 15:44:40 +0000 | |
changeset 469472 | f0ae73dd90f7f3f22bae40a15cd4b47479de50ec |
parent 469471 | 8d11a480d4ae56576b438cfcf5baf1876db25565 |
child 469473 | a7bb3810f26f2eb5266777e53e6afe17d89cc7e3 |
push id | 35872 |
push user | ncsoregi@mozilla.com |
push date | Mon, 15 Apr 2019 15:24:06 +0000 |
treeherder | mozilla-central@16d953cca414 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | baku |
bugs | 1542309 |
milestone | 68.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
|
caps/OriginAttributes.cpp | file | annotate | diff | comparison | revisions | |
caps/tests/gtest/TestOriginAttributes.cpp | file | annotate | diff | comparison | revisions |
--- a/caps/OriginAttributes.cpp +++ b/caps/OriginAttributes.cpp @@ -77,31 +77,42 @@ void OriginAttributes::SetFirstPartyDoma mFirstPartyDomain.AppendLiteral("]"); } else { mFirstPartyDomain = NS_ConvertUTF8toUTF16(ipAddr); } 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); if (scheme.EqualsLiteral("about")) { mFirstPartyDomain.AssignLiteral(ABOUT_URI_FIRST_PARTY_DOMAIN); return; } nsCOMPtr<nsIPrincipal> blobPrincipal; if (dom::BlobURLProtocolHandler::GetBlobURLPrincipal( aURI, getter_AddRefs(blobPrincipal))) { MOZ_ASSERT(blobPrincipal); mFirstPartyDomain = blobPrincipal->OriginAttributesRef().mFirstPartyDomain; return; } + + if (isInsufficientDomainLevels) { + nsAutoCString publicSuffix; + rv = tldService->GetPublicSuffix(aURI, publicSuffix); + if (NS_SUCCEEDED(rv)) { + mFirstPartyDomain = NS_ConvertUTF8toUTF16(publicSuffix); + } + return; + } } void OriginAttributes::SetFirstPartyDomain(const bool aIsTopLevelDocument, const nsACString& aDomain) { bool isFirstPartyEnabled = IsFirstPartyEnabled(); // If the pref is off or this is not a top level load, bail out. if (!isFirstPartyEnabled || !aIsTopLevelDocument) {
--- a/caps/tests/gtest/TestOriginAttributes.cpp +++ b/caps/tests/gtest/TestOriginAttributes.cpp @@ -1,27 +1,38 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * 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; attrs.CreateSuffix(suffix); OriginAttributes attrsFromSuffix; bool success = attrsFromSuffix.PopulateFromSuffix(suffix); EXPECT_TRUE(success); 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); } TEST(OriginAttributes, Suffix_appId_inIsolatedMozBrowser) { @@ -29,8 +40,26 @@ TEST(OriginAttributes, Suffix_appId_inIs TestSuffix(attrs); } 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); +}