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
This commit is contained in:
Andrea Marchesini 2020-06-30 12:50:48 +00:00
Родитель 118d838da8
Коммит b397940b11
1 изменённых файлов: 47 добавлений и 10 удалений

Просмотреть файл

@ -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<nsIURI> 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<nsILoadInfo> loadInfo = aChannel->LoadInfo();
if (!doForce) {
nsCOMPtr<nsILoadInfo> 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<nsIPrincipal> 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;