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;