зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1108017: Loosen third-party restrictions for tracking protection checks (r=sworkman)
This commit is contained in:
Родитель
a0f2b74c75
Коммит
a326516c92
|
@ -52,6 +52,7 @@ ThirdPartyUtil::IsThirdPartyInternal(const nsCString& aFirstDomain,
|
||||||
// Get the base domain for aSecondURI.
|
// Get the base domain for aSecondURI.
|
||||||
nsCString secondDomain;
|
nsCString secondDomain;
|
||||||
nsresult rv = GetBaseDomain(aSecondURI, secondDomain);
|
nsresult rv = GetBaseDomain(aSecondURI, secondDomain);
|
||||||
|
LOG(("ThirdPartyUtil::IsThirdPartyInternal %s =? %s", aFirstDomain.get(), secondDomain.get()));
|
||||||
if (NS_FAILED(rv))
|
if (NS_FAILED(rv))
|
||||||
return rv;
|
return rv;
|
||||||
|
|
||||||
|
@ -180,6 +181,7 @@ ThirdPartyUtil::IsThirdPartyChannel(nsIChannel* aChannel,
|
||||||
nsIURI* aURI,
|
nsIURI* aURI,
|
||||||
bool* aResult)
|
bool* aResult)
|
||||||
{
|
{
|
||||||
|
LOG(("ThirdPartyUtil::IsThirdPartyChannel [channel=%p]", aChannel));
|
||||||
NS_ENSURE_ARG(aChannel);
|
NS_ENSURE_ARG(aChannel);
|
||||||
NS_ASSERTION(aResult, "null outparam pointer");
|
NS_ASSERTION(aResult, "null outparam pointer");
|
||||||
|
|
||||||
|
|
|
@ -78,42 +78,61 @@ nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel *aChannel,
|
||||||
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
|
nsCOMPtr<mozIThirdPartyUtil> thirdPartyUtil =
|
||||||
do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
|
do_GetService(THIRDPARTYUTIL_CONTRACTID, &rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
// Third party checks don't work for chrome:// URIs in mochitests, so just
|
|
||||||
// default to isThirdParty = true
|
|
||||||
bool isThirdParty = true;
|
|
||||||
(void)thirdPartyUtil->IsThirdPartyChannel(aChannel, nullptr, &isThirdParty);
|
|
||||||
if (!isThirdParty) {
|
|
||||||
*result = false;
|
|
||||||
return NS_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
nsCOMPtr<nsIIOService> ios = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
|
||||||
|
|
||||||
nsCOMPtr<nsIHttpChannelInternal> chan = do_QueryInterface(aChannel, &rv);
|
nsCOMPtr<nsIHttpChannelInternal> chan = do_QueryInterface(aChannel, &rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCOMPtr<nsIURI> uri;
|
nsCOMPtr<nsIURI> topWinURI;
|
||||||
rv = chan->GetTopWindowURI(getter_AddRefs(uri));
|
rv = chan->GetTopWindowURI(getter_AddRefs(topWinURI));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
if (!uri) {
|
if (!topWinURI) {
|
||||||
LOG(("nsChannelClassifier[%p]: No window URI\n", this));
|
LOG(("nsChannelClassifier[%p]: No window URI\n", this));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIURI> chanURI;
|
||||||
|
rv = aChannel->GetURI(getter_AddRefs(chanURI));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// Third party checks don't work for chrome:// URIs in mochitests, so just
|
||||||
|
// default to isThirdParty = true. We check isThirdPartyWindow to expand
|
||||||
|
// the list of domains that are considered first party (e.g., if
|
||||||
|
// facebook.com includes an iframe from fatratgames.com, all subsources
|
||||||
|
// included in that iframe are considered third-party with
|
||||||
|
// isThirdPartyChannel, even if they are not third-party w.r.t.
|
||||||
|
// facebook.com), and isThirdPartyChannel to prevent top-level navigations
|
||||||
|
// from being detected as third-party.
|
||||||
|
bool isThirdPartyChannel = true;
|
||||||
|
bool isThirdPartyWindow = true;
|
||||||
|
thirdPartyUtil->IsThirdPartyURI(chanURI, topWinURI, &isThirdPartyWindow);
|
||||||
|
thirdPartyUtil->IsThirdPartyChannel(aChannel, nullptr, &isThirdPartyChannel);
|
||||||
|
if (!isThirdPartyWindow || !isThirdPartyChannel) {
|
||||||
|
*result = false;
|
||||||
|
#ifdef DEBUG
|
||||||
|
nsCString spec;
|
||||||
|
chanURI->GetSpec(spec);
|
||||||
|
LOG(("nsChannelClassifier[%p]: Skipping tracking protection checks for "
|
||||||
|
"first party or top-level load channel[%p] with uri %s", this, aChannel,
|
||||||
|
spec.get()));
|
||||||
|
#endif
|
||||||
|
return NS_OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
nsCOMPtr<nsIIOService> ios = do_GetService(NS_IOSERVICE_CONTRACTID, &rv);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
const char ALLOWLIST_EXAMPLE_PREF[] = "channelclassifier.allowlist_example";
|
const char ALLOWLIST_EXAMPLE_PREF[] = "channelclassifier.allowlist_example";
|
||||||
if (!uri && Preferences::GetBool(ALLOWLIST_EXAMPLE_PREF, false)) {
|
if (!topWinURI && Preferences::GetBool(ALLOWLIST_EXAMPLE_PREF, false)) {
|
||||||
LOG(("nsChannelClassifier[%p]: Allowlisting test domain\n", this));
|
LOG(("nsChannelClassifier[%p]: Allowlisting test domain\n", this));
|
||||||
rv = ios->NewURI(NS_LITERAL_CSTRING("http://allowlisted.example.com"),
|
rv = ios->NewURI(NS_LITERAL_CSTRING("http://allowlisted.example.com"),
|
||||||
nullptr, nullptr, getter_AddRefs(uri));
|
nullptr, nullptr, getter_AddRefs(topWinURI));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Take the host/port portion so we can allowlist by site. Also ignore the
|
// Take the host/port portion so we can allowlist by site. Also ignore the
|
||||||
// scheme, since users who put sites on the allowlist probably don't expect
|
// scheme, since users who put sites on the allowlist probably don't expect
|
||||||
// allowlisting to depend on scheme.
|
// allowlisting to depend on scheme.
|
||||||
nsCOMPtr<nsIURL> url = do_QueryInterface(uri, &rv);
|
nsCOMPtr<nsIURL> url = do_QueryInterface(topWinURI, &rv);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCString escaped(NS_LITERAL_CSTRING("https://"));
|
nsCString escaped(NS_LITERAL_CSTRING("https://"));
|
||||||
|
@ -123,7 +142,7 @@ nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel *aChannel,
|
||||||
escaped.Append(temp);
|
escaped.Append(temp);
|
||||||
|
|
||||||
// Stuff the whole thing back into a URI for the permission manager.
|
// Stuff the whole thing back into a URI for the permission manager.
|
||||||
rv = ios->NewURI(escaped, nullptr, nullptr, getter_AddRefs(uri));
|
rv = ios->NewURI(escaped, nullptr, nullptr, getter_AddRefs(topWinURI));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
nsCOMPtr<nsIPermissionManager> permMgr =
|
nsCOMPtr<nsIPermissionManager> permMgr =
|
||||||
|
@ -131,7 +150,7 @@ nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel *aChannel,
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
uint32_t permissions = nsIPermissionManager::UNKNOWN_ACTION;
|
uint32_t permissions = nsIPermissionManager::UNKNOWN_ACTION;
|
||||||
rv = permMgr->TestPermission(uri, "trackingprotection", &permissions);
|
rv = permMgr->TestPermission(topWinURI, "trackingprotection", &permissions);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -155,9 +174,8 @@ nsChannelClassifier::ShouldEnableTrackingProtection(nsIChannel *aChannel,
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
nsCString topspec;
|
nsCString topspec;
|
||||||
nsCString spec;
|
nsCString spec;
|
||||||
uri->GetSpec(topspec);
|
topWinURI->GetSpec(topspec);
|
||||||
aChannel->GetURI(getter_AddRefs(uri));
|
chanURI->GetSpec(spec);
|
||||||
uri->GetSpec(spec);
|
|
||||||
LOG(("nsChannelClassifier[%p]: Enabling tracking protection checks on channel[%p] "
|
LOG(("nsChannelClassifier[%p]: Enabling tracking protection checks on channel[%p] "
|
||||||
"with uri %s for toplevel window %s", this, aChannel, spec.get(),
|
"with uri %s for toplevel window %s", this, aChannel, spec.get(),
|
||||||
topspec.get()));
|
topspec.get()));
|
||||||
|
|
Загрузка…
Ссылка в новой задаче