зеркало из https://github.com/mozilla/gecko-dev.git
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
This commit is contained in:
Родитель
fba2d34e37
Коммит
6b2106e24a
|
@ -82,6 +82,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);
|
||||
|
@ -97,6 +99,15 @@ void OriginAttributes::SetFirstPartyDomain(const bool aIsTopLevelDocument,
|
|||
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,
|
||||
|
|
|
@ -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;
|
||||
|
@ -34,3 +45,21 @@ 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);
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче