From bea0b67d179bf459b501d2741f75c6b5488c034b Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 31 Jul 2019 19:32:01 +0000 Subject: [PATCH] Bug 1568341 - Part 1: Add a component for consuming the anti-tracking-url-decoration remote settings bucket and making it available to content processes; r=baku Differential Revision: https://phabricator.services.mozilla.com/D39919 --HG-- extra : moz-landing-system : lando --- modules/libpref/init/all.js | 4 ++ .../URLDecorationAnnotationsService.jsm | 70 +++++++++++++++++++ .../antitracking/antitracking.manifest | 1 + .../components/antitracking/components.conf | 7 ++ toolkit/components/antitracking/moz.build | 6 ++ .../nsIURLDecorationAnnotationsService.idl | 27 +++++++ 6 files changed, 115 insertions(+) create mode 100644 toolkit/components/antitracking/URLDecorationAnnotationsService.jsm create mode 100644 toolkit/components/antitracking/antitracking.manifest create mode 100644 toolkit/components/antitracking/nsIURLDecorationAnnotationsService.idl diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index e9ea301a8fa5..2c99b73f5db2 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1137,6 +1137,10 @@ pref("privacy.restrict3rdpartystorage.partitionedHosts", "accounts.google.com/o/ // before granting the storage access permission. pref("privacy.restrict3rdpartystorage.userInteractionRequiredForHosts", ""); +// The url decoration tokens used to for stripping document referrers based on. +// A list separated by spaces. This pref isn't meant to be changed by users. +pref("privacy.restrict3rdpartystorage.url_decorations", ""); + // Excessive reporting of blocked popups can be a DOS vector, // by overloading the main process as popups get blocked and when // users try to restore all popups, which is the most visible diff --git a/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm b/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm new file mode 100644 index 000000000000..34698e6dbda0 --- /dev/null +++ b/toolkit/components/antitracking/URLDecorationAnnotationsService.jsm @@ -0,0 +1,70 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +this.URLDecorationAnnotationsService = function() {}; + +const { Preferences } = ChromeUtils.import( + "resource://gre/modules/Preferences.jsm" +); + +ChromeUtils.defineModuleGetter( + this, + "RemoteSettings", + "resource://services-settings/remote-settings.js" +); + +const COLLECTION_NAME = "anti-tracking-url-decoration"; +const PREF_NAME = "privacy.restrict3rdpartystorage.url_decorations"; + +URLDecorationAnnotationsService.prototype = { + classID: Components.ID("{5874af6d-5719-4e1b-b155-ef4eae7fcb32}"), + QueryInterface: ChromeUtils.generateQI([ + Ci.nsIObserver, + Ci.nsIURLDecorationAnnotationsService, + ]), + + _initialized: false, + + onDataAvailable(entries) { + // Use this technique in order to ensure the pref cannot be changed by the + // user e.g. through about:config. This preferences is only intended as a + // mechanism for reflecting this data to content processes. + Preferences.unlock(PREF_NAME); + new Preferences({ defaultBranch: true }).set( + PREF_NAME, + entries.map(x => x.token.replace(/ /, "%20")).join(" ") + ); + Preferences.lock(PREF_NAME); + }, + + observe(aSubject, aTopic, aData) { + if (aTopic == "profile-after-change") { + this.ensureUpdated(); + } + }, + + ensureUpdated() { + if (this._initialized) { + return Promise.resolve(); + } + this._initialized = true; + + const client = RemoteSettings(COLLECTION_NAME); + client.on("sync", event => { + let { + data: { current }, + } = event; + this.onDataAvailable(current); + }); + + // Now trigger an update from the server if necessary to get a fresh copy + // of the data + return client.get({}).then(entries => { + this.onDataAvailable(entries); + return undefined; + }); + }, +}; + +var EXPORTED_SYMBOLS = ["URLDecorationAnnotationsService"]; diff --git a/toolkit/components/antitracking/antitracking.manifest b/toolkit/components/antitracking/antitracking.manifest new file mode 100644 index 000000000000..5eb37f9a3f99 --- /dev/null +++ b/toolkit/components/antitracking/antitracking.manifest @@ -0,0 +1 @@ +category profile-after-change URLDecorationAnnotationsService @mozilla.org/tracking-url-decoration-service;1 process=main diff --git a/toolkit/components/antitracking/components.conf b/toolkit/components/antitracking/components.conf index 8718e0a16980..07fddf13dea0 100644 --- a/toolkit/components/antitracking/components.conf +++ b/toolkit/components/antitracking/components.conf @@ -11,4 +11,11 @@ Classes = [ 'jsm': 'resource://gre/modules/TrackingDBService.jsm', 'constructor': 'TrackingDBService', }, + { + 'cid': '{5874af6d-5719-4e1b-b155-ef4eae7fcb32}', + 'contract_ids': ['@mozilla.org/tracking-url-decoration-service;1'], + 'jsm': 'resource://gre/modules/URLDecorationAnnotationsService.jsm', + 'constructor': 'URLDecorationAnnotationsService', + 'processes': ProcessSelector.MAIN_PROCESS_ONLY, + }, ] diff --git a/toolkit/components/antitracking/moz.build b/toolkit/components/antitracking/moz.build index 9f4edf70bdf1..e0dea941d5c9 100644 --- a/toolkit/components/antitracking/moz.build +++ b/toolkit/components/antitracking/moz.build @@ -9,12 +9,18 @@ with Files('**'): XPIDL_SOURCES += [ 'nsITrackingDBService.idl', + 'nsIURLDecorationAnnotationsService.idl', ] XPIDL_MODULE = 'toolkit_antitracking' +EXTRA_COMPONENTS += [ + 'antitracking.manifest', +] + EXTRA_JS_MODULES += [ 'TrackingDBService.jsm', + 'URLDecorationAnnotationsService.jsm', ] XPCOM_MANIFESTS += [ diff --git a/toolkit/components/antitracking/nsIURLDecorationAnnotationsService.idl b/toolkit/components/antitracking/nsIURLDecorationAnnotationsService.idl new file mode 100644 index 000000000000..357b8baaa272 --- /dev/null +++ b/toolkit/components/antitracking/nsIURLDecorationAnnotationsService.idl @@ -0,0 +1,27 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "nsISupports.idl" + +/** + * A service that monitors updates to the anti-tracking URL decoration + * annotations from remote settings. + */ +[scriptable, uuid(937d0c66-6821-4e3f-9e04-50dbc2b2b476)] +interface nsIURLDecorationAnnotationsService : nsISupports +{ + /** + * Ensures that the list is updated and resolves the returned promise when + * the update is finished. + * + * The new list will be written to a space-separated list of tokens inside + * the following string preference: + * privacy.restrict3rdpartystorage.url_decorations + * + * This preference will be kept up to date with future list updates from + * the remote settings server. This preference cannot be modified by any + * external component and is managed by this service. + */ + Promise ensureUpdated(); +};