Bug 1876736 - Record bounce trackers purged in anti-tracking stats. r=anti-tracking-reviewers,manuel

Differential Revision: https://phabricator.services.mozilla.com/D212798
This commit is contained in:
Paul Zuehlcke 2024-06-11 17:16:37 +00:00
Родитель 2981b800b9
Коммит f8830ccd7a
8 изменённых файлов: 85 добавлений и 42 удалений

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

@ -1582,7 +1582,7 @@ void WindowGlobalParent::ActorDestroy(ActorDestroyReason aWhy) {
nsCOMPtr<nsILoadContext> loadContext = browserParent->GetLoadContext();
if (loadContext && !loadContext->UsePrivateBrowsing() &&
BrowsingContext()->IsTopContent()) {
GetContentBlockingLog()->ReportLog(DocumentPrincipal());
GetContentBlockingLog()->ReportLog();
if (mDocumentURI && (net::SchemeIsHTTP(mDocumentURI) ||
net::SchemeIsHTTPS(mDocumentURI))) {

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

@ -99,6 +99,7 @@ Maybe<uint32_t> ContentBlockingLog::RecordLogParent(
case nsIWebProgressListener::STATE_BLOCKED_EMAILTRACKING_CONTENT:
case nsIWebProgressListener::STATE_LOADED_EMAILTRACKING_LEVEL_1_CONTENT:
case nsIWebProgressListener::STATE_LOADED_EMAILTRACKING_LEVEL_2_CONTENT:
case nsIWebProgressListener::STATE_PURGED_BOUNCETRACKER:
Unused << RecordLogInternal(aOrigin, aType, blockedValue);
break;
@ -184,10 +185,9 @@ Maybe<uint32_t> ContentBlockingLog::RecordLogParent(
return Some(events);
}
void ContentBlockingLog::ReportLog(nsIPrincipal* aFirstPartyPrincipal) {
void ContentBlockingLog::ReportLog() {
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(aFirstPartyPrincipal);
if (!StaticPrefs::browser_contentblocking_database_enabled()) {
return;

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

@ -92,11 +92,11 @@ class ContentBlockingLog final {
const nsACString& aOrigin, uint32_t aType, bool aBlocked,
const Maybe<
ContentBlockingNotifier::StorageAccessPermissionGrantedReason>&
aReason,
const nsTArray<nsCString>& aTrackingFullHashes,
aReason = Nothing(),
const nsTArray<nsCString>& aTrackingFullHashes = nsTArray<nsCString>(),
const Maybe<ContentBlockingNotifier::CanvasFingerprinter>&
aCanvasFingerprinter,
const Maybe<bool> aCanvasFingerprinterKnownText);
aCanvasFingerprinter = Nothing(),
const Maybe<bool> aCanvasFingerprinterKnownText = Nothing());
void RecordLog(
const nsACString& aOrigin, uint32_t aType, bool aBlocked,
@ -107,7 +107,7 @@ class ContentBlockingLog final {
RecordLogInternal(aOrigin, aType, aBlocked, aReason, aTrackingFullHashes);
}
void ReportLog(nsIPrincipal* aFirstPartyPrincipal);
void ReportLog();
void ReportCanvasFingerprintingLog(nsIPrincipal* aFirstPartyPrincipal);
void ReportFontFingerprintingLog(nsIPrincipal* aFirstPartyPrincipal);
void ReportEmailTrackingLog(nsIPrincipal* aFirstPartyPrincipal);

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

@ -255,6 +255,10 @@ TrackingDBService.prototype = {
state & Ci.nsIWebProgressListener.STATE_BLOCKED_CRYPTOMINING_CONTENT
) {
result = Ci.nsITrackingDBService.CRYPTOMINERS_ID;
} else if (
state & Ci.nsIWebProgressListener.STATE_PURGED_BOUNCETRACKER
) {
result = Ci.nsITrackingDBService.BOUNCETRACKERS_ID;
}
}
}

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

@ -32,6 +32,7 @@
#include "mozilla/dom/BrowsingContext.h"
#include "xpcpublic.h"
#include "mozilla/glean/GleanMetrics.h"
#include "mozilla/ContentBlockingLog.h"
#define TEST_OBSERVER_MSG_RECORD_BOUNCES_FINISHED "test-record-bounces-finished"
@ -558,25 +559,53 @@ BounceTrackingProtection::PurgeBounceTrackers() {
("%s: Done. Cleared %zu hosts.", __FUNCTION__,
aResults.ResolveValue().Length()));
// Check if any clear call failed.
bool anyFailed = false;
nsTArray<nsCString> purgedSiteHosts;
// If any clear call failed reject.
for (auto& result : aResults.ResolveValue()) {
if (result.IsReject()) {
mPurgeInProgress = false;
return PurgeBounceTrackersMozPromise::CreateAndReject(
NS_ERROR_FAILURE, __func__);
anyFailed = true;
} else {
purgedSiteHosts.AppendElement(result.ResolveValue());
}
purgedSiteHosts.AppendElement(result.ResolveValue());
}
// No clearing errors, resolve.
// Record successful purges via nsITrackingDBService for tracker
// stats.
if (purgedSiteHosts.Length() > 0) {
ReportPurgedTrackersToAntiTrackingDB(purgedSiteHosts);
}
mPurgeInProgress = false;
// If any clear call failed reject the promise.
if (anyFailed) {
return PurgeBounceTrackersMozPromise::CreateAndReject(
NS_ERROR_FAILURE, __func__);
}
return PurgeBounceTrackersMozPromise::CreateAndResolve(
std::move(purgedSiteHosts), __func__);
});
}
// static
void BounceTrackingProtection::ReportPurgedTrackersToAntiTrackingDB(
const nsTArray<nsCString>& aPurgedSiteHosts) {
MOZ_ASSERT(!aPurgedSiteHosts.IsEmpty());
ContentBlockingLog log;
for (const nsCString& host : aPurgedSiteHosts) {
nsAutoCString origin("https://");
origin.Append(host);
log.RecordLogParent(
origin, nsIWebProgressListener::STATE_PURGED_BOUNCETRACKER, true);
}
log.ReportLog();
}
nsresult BounceTrackingProtection::PurgeBounceTrackersForStateGlobal(
BounceTrackingStateGlobal* aStateGlobal,
BounceTrackingAllowList& aBounceTrackingAllowList,

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

@ -73,6 +73,11 @@ class BounceTrackingProtection final : public nsIBounceTrackingProtection {
MozPromise<nsTArray<nsCString>, nsresult, true>;
RefPtr<PurgeBounceTrackersMozPromise> PurgeBounceTrackers();
// Report purged trackers to the anti-tracking database via
// nsITrackingDBService.
static void ReportPurgedTrackersToAntiTrackingDB(
const nsTArray<nsCString>& aPurgedSiteHosts);
// Clear state for classified bounce trackers for a specific state global.
// aClearPromises is populated with promises for each host that is cleared.
[[nodiscard]] nsresult PurgeBounceTrackersForStateGlobal(

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

@ -62,4 +62,5 @@ interface nsITrackingDBService : nsISupports
const unsigned long FINGERPRINTERS_ID = 4;
const unsigned long SOCIAL_ID = 5;
const unsigned long SUSPICIOUS_FINGERPRINTERS_ID = 6;
const unsigned long BOUNCETRACKERS_ID = 7;
};

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

@ -362,36 +362,40 @@ interface nsIWebProgressListener : nsISupports
* STATE_BLOCKED_SUSPICIOUS_FINGERPRINTING
* Suspicious fingerprinting activity has been blocked by the fingerprinting
* protection.
*
* STATE_PURGED_BOUNCETRACKER
* BounceTrackingProtection purged state for a bounce tracker.
*/
const unsigned long STATE_BLOCKED_TRACKING_CONTENT = 0x00001000;
const unsigned long STATE_LOADED_LEVEL_1_TRACKING_CONTENT = 0x00002000;
const unsigned long STATE_LOADED_LEVEL_2_TRACKING_CONTENT = 0x00100000;
const unsigned long STATE_BLOCKED_FINGERPRINTING_CONTENT = 0x00000040;
const unsigned long STATE_LOADED_FINGERPRINTING_CONTENT = 0x00000400;
const unsigned long STATE_REPLACED_FINGERPRINTING_CONTENT = 0x08000000;
const unsigned long STATE_ALLOWED_FINGERPRINTING_CONTENT = 0x00000200;
const unsigned long STATE_BLOCKED_CRYPTOMINING_CONTENT = 0x00000800;
const unsigned long STATE_LOADED_CRYPTOMINING_CONTENT = 0x00200000;
const unsigned long STATE_BLOCKED_UNSAFE_CONTENT = 0x00004000;
const unsigned long STATE_COOKIES_LOADED = 0x00008000;
const unsigned long STATE_COOKIES_LOADED_TRACKER = 0x00040000;
const unsigned long STATE_COOKIES_LOADED_SOCIALTRACKER = 0x00080000;
const unsigned long STATE_COOKIES_BLOCKED_BY_PERMISSION = 0x10000000;
const unsigned long STATE_COOKIES_BLOCKED_TRACKER = 0x20000000;
const unsigned long STATE_COOKIES_BLOCKED_SOCIALTRACKER = 0x01000000;
const unsigned long STATE_COOKIES_BLOCKED_ALL = 0x40000000;
const unsigned long STATE_COOKIES_PARTITIONED_FOREIGN = 0x80000000;
const unsigned long STATE_COOKIES_BLOCKED_FOREIGN = 0x00000080;
const unsigned long STATE_BLOCKED_SOCIALTRACKING_CONTENT = 0x00010000;
const unsigned long STATE_LOADED_SOCIALTRACKING_CONTENT = 0x00020000;
const unsigned long STATE_REPLACED_TRACKING_CONTENT = 0x00000010;
const unsigned long STATE_ALLOWED_TRACKING_CONTENT = 0x00000020;
const unsigned long STATE_BLOCKED_EMAILTRACKING_CONTENT = 0x00400000;
const unsigned long STATE_LOADED_EMAILTRACKING_LEVEL_1_CONTENT = 0x00800000;
const unsigned long STATE_LOADED_EMAILTRACKING_LEVEL_2_CONTENT = 0x00000100;
const unsigned long STATE_ALLOWED_CANVAS_FINGERPRINTING = 0x02000000;
const unsigned long STATE_ALLOWED_FONT_FINGERPRINTING = 0x04000000;
const unsigned long STATE_BLOCKED_SUSPICIOUS_FINGERPRINTING = 0x00000004;
const unsigned long STATE_BLOCKED_TRACKING_CONTENT = 1 << 12;
const unsigned long STATE_LOADED_LEVEL_1_TRACKING_CONTENT = 1 << 13;
const unsigned long STATE_LOADED_LEVEL_2_TRACKING_CONTENT = 1 << 20;
const unsigned long STATE_BLOCKED_FINGERPRINTING_CONTENT = 1 << 6;
const unsigned long STATE_LOADED_FINGERPRINTING_CONTENT = 1 << 10;
const unsigned long STATE_REPLACED_FINGERPRINTING_CONTENT = 1 << 27;
const unsigned long STATE_ALLOWED_FINGERPRINTING_CONTENT = 1 << 9;
const unsigned long STATE_BLOCKED_CRYPTOMINING_CONTENT = 1 << 11;
const unsigned long STATE_LOADED_CRYPTOMINING_CONTENT = 1 << 21;
const unsigned long STATE_BLOCKED_UNSAFE_CONTENT = 1 << 14;
const unsigned long STATE_COOKIES_LOADED = 1 << 15;
const unsigned long STATE_COOKIES_LOADED_TRACKER = 1 << 18;
const unsigned long STATE_COOKIES_LOADED_SOCIALTRACKER = 1 << 19;
const unsigned long STATE_COOKIES_BLOCKED_BY_PERMISSION = 1 << 28;
const unsigned long STATE_COOKIES_BLOCKED_TRACKER = 1 << 29;
const unsigned long STATE_COOKIES_BLOCKED_SOCIALTRACKER = 1 << 24;
const unsigned long STATE_COOKIES_BLOCKED_ALL = 1 << 30;
const unsigned long STATE_COOKIES_PARTITIONED_FOREIGN = 1 << 31;
const unsigned long STATE_COOKIES_BLOCKED_FOREIGN = 1 << 7;
const unsigned long STATE_BLOCKED_SOCIALTRACKING_CONTENT = 1 << 16;
const unsigned long STATE_LOADED_SOCIALTRACKING_CONTENT = 1 << 17;
const unsigned long STATE_REPLACED_TRACKING_CONTENT = 1 << 4;
const unsigned long STATE_ALLOWED_TRACKING_CONTENT = 1 << 5;
const unsigned long STATE_BLOCKED_EMAILTRACKING_CONTENT = 1 << 22;
const unsigned long STATE_LOADED_EMAILTRACKING_LEVEL_1_CONTENT = 1 << 23;
const unsigned long STATE_LOADED_EMAILTRACKING_LEVEL_2_CONTENT = 1 << 8;
const unsigned long STATE_ALLOWED_CANVAS_FINGERPRINTING = 1 << 25;
const unsigned long STATE_ALLOWED_FONT_FINGERPRINTING = 1 << 26;
const unsigned long STATE_BLOCKED_SUSPICIOUS_FINGERPRINTING = 1 << 2;
const unsigned long STATE_PURGED_BOUNCETRACKER = 1 << 3;
/**
* Flags for HTTPS-Only and HTTPS-First Mode upgrades