Bug 1570159 - CreatePairwiseWhitelistURI return success when it cannot get host from the top-level page. r=Ehsan

Before this patch, when we cannot get the host name from the top-level page, for example,
aboout page, UrlClassifeirCommon::CreatePairwiseWhitelistURI returns an error.

After this patch, when |GetHost| fails, we returns NS_OK to just skip looking up
whiltelist for this URI. Note that the lookup against blacklist tables will
still be performed.

Differential Revision: https://phabricator.services.mozilla.com/D49983

--HG--
extra : moz-landing-system : lando
This commit is contained in:
DimiDL 2019-10-25 07:31:12 +00:00
Родитель d99cac29b3
Коммит 3937de1977
2 изменённых файлов: 20 добавлений и 4 удалений

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

@ -707,16 +707,22 @@ nsresult FeatureData::InitializeList(
nsIUrlClassifierFeature::URIType URIType;
nsresult rv = mFeature->GetURIByListType(aChannel, aListType, &URIType,
getter_AddRefs(uri));
if (NS_WARN_IF(NS_FAILED(rv)) || !uri) {
if (NS_WARN_IF(NS_FAILED(rv))) {
if (UC_LOG_ENABLED()) {
nsAutoCString errorName;
GetErrorName(rv, errorName);
UC_LOG(("FeatureData::InitializeList got an unexpected error (rv=%s)",
errorName.get()));
UC_LOG(("FeatureData::InitializeList[%p] got an unexpected error (rv=%s)",
this, errorName.get()));
}
return rv;
}
if (!uri) {
// Return success when the URI is empty to conitnue to do the lookup.
UC_LOG(("FeatureData::InitializeList[%p] got an empty URL", this));
return NS_OK;
}
nsCOMPtr<nsIURI> innermostURI = NS_GetInnermostURI(uri);
if (NS_WARN_IF(!innermostURI)) {
return NS_ERROR_FAILURE;

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

@ -338,7 +338,17 @@ nsresult UrlClassifierCommon::CreatePairwiseWhiteListURI(nsIChannel* aChannel,
// Craft a whitelist URL like "toplevel.page/?resource=third.party.domain"
nsAutoCString pageHostname, resourceDomain;
rv = topWinURI->GetHost(pageHostname);
NS_ENSURE_SUCCESS(rv, rv);
if (NS_FAILED(rv)) {
// When the top-level page doesn't support GetHost, for example, about:home,
// we don't return an error here; instead, we return success to make sure
// that the lookup process calling this API continues to run.
UC_LOG(
("CreatePairwiseWhiteListURI: Cannot get host from the top-level "
"(channel=%p)",
aChannel));
return NS_OK;
}
rv = chanPrincipal->GetBaseDomain(resourceDomain);
NS_ENSURE_SUCCESS(rv, rv);
nsAutoCString whitelistEntry = NS_LITERAL_CSTRING("http://") + pageHostname +