Bug 1625568 - Add compatibility heuristics to third-party cookie blocking - part 5 - extra code to enable heuristics, r=timhuang

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

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Andrea Marchesini 2020-04-02 14:59:44 +00:00
Родитель 24cba91c2a
Коммит 7400947ea3
4 изменённых файлов: 42 добавлений и 13 удалений

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

@ -15068,9 +15068,17 @@ void Document::MaybeAllowStorageForOpenerAfterUserInteraction() {
return;
}
// We care about first-party tracking resources only.
if (!nsContentUtils::IsFirstPartyTrackingResourceWindow(inner)) {
return;
uint32_t cookieBehavior = CookieJarSettings()->GetCookieBehavior();
if (cookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
cookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN) {
// We care about first-party tracking resources only.
if (!nsContentUtils::IsFirstPartyTrackingResourceWindow(inner)) {
return;
}
} else {
MOZ_ASSERT(net::CookieJarSettings::IsRejectThirdPartyWithExceptions(
cookieBehavior));
}
auto* outer = nsGlobalWindowOuter::Cast(inner->GetOuterWindow());

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

@ -48,6 +48,7 @@
#endif
#include "nsBaseCommandController.h"
#include "nsError.h"
#include "nsICookieService.h"
#include "nsISizeOfEventTarget.h"
#include "nsDOMJSUtils.h"
#include "nsArrayUtils.h"
@ -2504,14 +2505,31 @@ nsresult nsGlobalWindowOuter::SetNewDocument(Document* aDocument,
if (newInnerWindow &&
aDocument->CookieJarSettings()->GetRejectThirdPartyContexts() &&
nsContentUtils::IsThirdPartyWindowOrChannel(newInnerWindow, nullptr,
uri) &&
nsContentUtils::IsThirdPartyTrackingResourceWindow(newInnerWindow)) {
uri)) {
uint32_t cookieBehavior =
aDocument->CookieJarSettings()->GetCookieBehavior();
// Grant storage access by default if the first-party storage access
// permission has been granted already.
// Don't notify in this case, since we would be notifying the user
// needlessly.
mHasStorageAccess =
ContentBlocking::ShouldAllowAccessFor(newInnerWindow, uri, nullptr);
bool checkStorageAccess = false;
if (net::CookieJarSettings::IsRejectThirdPartyWithExceptions(
cookieBehavior)) {
checkStorageAccess = true;
} else {
MOZ_ASSERT(
cookieBehavior == nsICookieService::BEHAVIOR_REJECT_TRACKER ||
cookieBehavior ==
nsICookieService::BEHAVIOR_REJECT_TRACKER_AND_PARTITION_FOREIGN);
if (nsContentUtils::IsThirdPartyTrackingResourceWindow(newInnerWindow)) {
checkStorageAccess = true;
}
}
if (checkStorageAccess) {
mHasStorageAccess =
ContentBlocking::ShouldAllowAccessFor(newInnerWindow, uri, nullptr);
}
}
newInnerWindow->GetWindowGlobalChild()

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

@ -23,6 +23,7 @@
#include "mozilla/dom/ipc/StructuredCloneData.h"
#include "mozilla/ServoCSSParser.h"
#include "mozilla/ServoStyleSet.h"
#include "mozilla/StaticPrefs_network.h"
#include "mozJSComponentLoader.h"
#include "nsContentUtils.h"
#include "nsDocShell.h"
@ -321,12 +322,14 @@ void WindowGlobalParent::NotifyContentBlockingEvent(
const nsTArray<nsCString>& aTrackingFullHashes,
const Maybe<ContentBlockingNotifier::StorageAccessGrantedReason>& aReason) {
MOZ_ASSERT(NS_IsMainThread());
DebugOnly<bool> isCookiesBlockedTracker =
DebugOnly<bool> isCookiesBlocked =
aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_TRACKER ||
aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER;
aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_SOCIALTRACKER ||
(aEvent == nsIWebProgressListener::STATE_COOKIES_BLOCKED_FOREIGN &&
StaticPrefs::network_cookie_rejectForeignWithExceptions_enabled());
MOZ_ASSERT_IF(aBlocked, aReason.isNothing());
MOZ_ASSERT_IF(!isCookiesBlockedTracker, aReason.isNothing());
MOZ_ASSERT_IF(isCookiesBlockedTracker && !aBlocked, aReason.isSome());
MOZ_ASSERT_IF(!isCookiesBlocked, aReason.isNothing());
MOZ_ASSERT_IF(isCookiesBlocked && !aBlocked, aReason.isSome());
MOZ_DIAGNOSTIC_ASSERT(XRE_IsParentProcess());
// TODO: temporarily remove this until we find the root case of Bug 1609144
// MOZ_DIAGNOSTIC_ASSERT_IF(XRE_IsE10sParentProcess(), !IsInProcess());

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

@ -172,8 +172,8 @@ nsCString ImageCacheKey::GetTopLevelBaseDomain(Document* aDocument,
// If the window is 3rd party resource, let's see if first-party storage
// access is granted for this image.
if (nsContentUtils::IsThirdPartyTrackingResourceWindow(
aDocument->GetInnerWindow())) {
if (nsContentUtils::IsThirdPartyWindowOrChannel(aDocument->GetInnerWindow(),
nullptr, nullptr)) {
return StorageDisabledByAntiTracking(aDocument, aURI)
? aDocument->GetBaseDomain()
: EmptyCString();