From b397940b1101f0610826143f7d09a7dd2c4025c7 Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Tue, 30 Jun 2020 12:50:48 +0000 Subject: [PATCH] Bug 1641905 - ThirdPartyUtil::IsThirdPartyWindow returns different values in fission - use the principal to inherit for about:blank channels, r=dimi Differential Revision: https://phabricator.services.mozilla.com/D81558 --- dom/base/ThirdPartyUtil.cpp | 57 ++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/dom/base/ThirdPartyUtil.cpp b/dom/base/ThirdPartyUtil.cpp index 2d8f8cd8e32e..7b2d302c7bbc 100644 --- a/dom/base/ThirdPartyUtil.cpp +++ b/dom/base/ThirdPartyUtil.cpp @@ -100,7 +100,9 @@ nsresult ThirdPartyUtil::IsThirdPartyInternal(const nsCString& aFirstDomain, nsresult rv = GetBaseDomain(aSecondURI, secondDomain); LOG(("ThirdPartyUtil::IsThirdPartyInternal %s =? %s", aFirstDomain.get(), secondDomain.get())); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } *aResult = IsThirdPartyInternal(aFirstDomain, secondDomain); return NS_OK; @@ -161,7 +163,9 @@ ThirdPartyUtil::IsThirdPartyURI(nsIURI* aFirstURI, nsIURI* aSecondURI, nsAutoCString firstHost; nsresult rv = GetBaseDomain(aFirstURI, firstHost); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } return IsThirdPartyInternal(firstHost, aSecondURI, aResult); } @@ -275,25 +279,58 @@ ThirdPartyUtil::IsThirdPartyChannel(nsIChannel* aChannel, nsIURI* aURI, } bool parentIsThird = false; + nsAutoCString channelDomain; // Obtain the URI from the channel, and its base domain. nsCOMPtr channelURI; rv = NS_GetFinalChannelURI(aChannel, getter_AddRefs(channelURI)); - if (NS_FAILED(rv)) return rv; + if (NS_FAILED(rv)) { + return rv; + } - nsAutoCString channelDomain; - rv = GetBaseDomain(channelURI, channelDomain); - if (NS_FAILED(rv)) return rv; + BasePrincipal* loadingPrincipal = nullptr; + nsCOMPtr loadInfo = aChannel->LoadInfo(); if (!doForce) { - nsCOMPtr loadInfo = aChannel->LoadInfo(); parentIsThird = loadInfo->GetIsInThirdPartyContext(); if (!parentIsThird && loadInfo->GetExternalContentPolicyType() != nsIContentPolicy::TYPE_DOCUMENT) { // Check if the channel itself is third-party to its own requestor. - // Unforunately, we have to go through the loading principal. - BasePrincipal* loadingPrincipal = - BasePrincipal::Cast(loadInfo->GetLoadingPrincipal()); + // Unfortunately, we have to go through the loading principal. + loadingPrincipal = BasePrincipal::Cast(loadInfo->GetLoadingPrincipal()); + } + } + + // Special consideration must be done for about:blank URIs because those + // inherit the principal from the parent context. For them, let's consider the + // principal URI. + if (NS_IsAboutBlank(channelURI)) { + nsCOMPtr principalToInherit = + loadInfo->FindPrincipalToInherit(aChannel); + if (!principalToInherit) { + *aResult = true; + return NS_OK; + } + + rv = principalToInherit->GetBaseDomain(channelDomain); + if (NS_FAILED(rv)) { + return rv; + } + + if (loadingPrincipal) { + rv = loadingPrincipal->IsThirdPartyPrincipal(principalToInherit, + &parentIsThird); + if (NS_FAILED(rv)) { + return rv; + } + } + } else { + rv = GetBaseDomain(channelURI, channelDomain); + if (NS_FAILED(rv)) { + return rv; + } + + if (loadingPrincipal) { rv = loadingPrincipal->IsThirdPartyURI(channelURI, &parentIsThird); if (NS_FAILED(rv)) { return rv;