123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236 |
- From c572b11d9d112f534b2855e8825f81d6304fd3fd Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 17:20:39 +0200
- Subject: [PATCH 01/13] Point to local omni.ja files, not remote server
- This patch series tries to remove any network communication with Remote
- Settings [1], which can be used by Mozilla to silently push data to client
- browsers. This data can include references to nonfree software, for example,
- to search engines or other websites that contain nonfree JavaScript code.
- Without this patching, it would be hard to make sure the browser does not
- violate paragraph 4 of [2]: "Programs in the system should not suggest
- installing nonfree plugins, documentation, and so on."
- Changes in the current patch:
- First of all, replace every occurrence of Remote Settings server domain name
- with URIs that point to built-in local files within omni.ja.
- Some links to json files may point to non-existing files, but that's OK
- because it's better than leave them point to Remote Settings server.
- If necessary, missing files can be added later.
- [1] https://remote-settings.readthedocs.io/en/latest/introduction.html
- [2] https://www.gnu.org/distros/free-system-distribution-guidelines.en.html#license-rules
- ---
- browser/components/asrouter/bin/import-rollouts.js | 4 ++--
- .../components/ASRouterAdmin/ASRouterAdmin.jsx | 2 +-
- .../components/asrouter/content/asrouter-admin.bundle.js | 2 +-
- .../feature/search/telemetry/SerpTelemetryRepository.kt | 2 +-
- .../support/remotesettings/RemoteSettingsClient.kt | 2 +-
- .../support/remotesettings/RemoteSettingsClientTest.kt | 2 +-
- .../docs/_posts/2018-08-10-fretboard.md | 2 +-
- .../src/main/java/org/mozilla/fenix/components/Core.kt | 4 ++--
- .../org/mozilla/focus/telemetry/GleanMetricsService.kt | 4 ++--
- services/settings/Utils.sys.mjs | 2 +-
- services/settings/docs/index.rst | 4 ++--
- .../periodic-updates/scripts/periodic_file_updates.sh | 2 +-
- third_party/rust/remote_settings/.cargo-checksum.json | 2 +-
- third_party/rust/remote_settings/src/client.rs | 2 +-
- third_party/rust/remote_settings/src/config.rs | 6 +++---
- .../components/antitracking/docs/query-stripping/index.md | 2 +-
- .../backgroundtasks/BackgroundTask_message.sys.mjs | 6 +++---
- toolkit/components/search/SearchUtils.sys.mjs | 8 ++++----
- toolkit/components/search/docs/DefaultSearchEngines.rst | 2 +-
- .../components/search/docs/SearchEngineConfiguration.rst | 8 ++++----
- .../search/docs/SearchEngineConfigurationArchive.rst | 2 +-
- toolkit/modules/AppConstants.sys.mjs | 4 ++--
- 22 files changed, 37 insertions(+), 37 deletions(-)
- diff --git a/browser/components/asrouter/bin/import-rollouts.js b/browser/components/asrouter/bin/import-rollouts.js
- index b8e4b3fff7..9cf2e7ebef 100644
- --- a/browser/components/asrouter/bin/import-rollouts.js
- +++ b/browser/components/asrouter/bin/import-rollouts.js
- @@ -36,7 +36,7 @@ const jsonschema = require("../../../../third_party/js/cfworker/json-schema.js")
-
- const DEFAULT_COLLECTION_ID = "nimbus-desktop-experiments";
- const BASE_URL =
- - "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/";
- + "resource://app/defaults/settings/main/";
- const EXPERIMENTER_URL = "https://experimenter.services.mozilla.com/nimbus/";
- const OUTPUT_PATH = "./tests/NimbusRolloutMessageProvider.sys.mjs";
- const LICENSE_STRING = `/* This Source Code Form is subject to the terms of the Mozilla Public
- @@ -237,7 +237,7 @@ async function main() {
- }
- );
-
- - const RECORDS_URL = `${BASE_URL}${cli.flags.collection}/records`;
- + const RECORDS_URL = `${BASE_URL}${cli.flags.collection}.json`;
-
- console.log(`Fetching records from ${chalk.underline.yellow(RECORDS_URL)}`);
-
- diff --git a/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx b/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx
- index a5edd0c481..cb6e735cfc 100644
- --- a/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx
- +++ b/browser/components/asrouter/content-src/components/ASRouterAdmin/ASRouterAdmin.jsx
- @@ -816,7 +816,7 @@ export class ASRouterAdminInner extends React.PureComponent {
- <a
- className="small-text"
- target="_blank"
- - href="https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/nimbus-desktop-experiments/records"
- + href="resource://app/defaults/settings/main/nimbus-desktop-experiments.json"
- rel="noopener noreferrer"
- >
- nimbus-desktop-experiments
- diff --git a/browser/components/asrouter/content/asrouter-admin.bundle.js b/browser/components/asrouter/content/asrouter-admin.bundle.js
- index 206610282a..bac1763595 100644
- --- a/browser/components/asrouter/content/asrouter-admin.bundle.js
- +++ b/browser/components/asrouter/content/asrouter-admin.bundle.js
- @@ -1152,7 +1152,7 @@ class ASRouterAdminInner extends (react__WEBPACK_IMPORTED_MODULE_1___default().P
- label = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement("span", null, "remote settings (", /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1___default().createElement("a", {
- className: "small-text",
- target: "_blank",
- - href: "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/nimbus-desktop-experiments/records",
- + href: "resource://app/defaults/settings/main/nimbus-desktop-experiments.json",
- rel: "noopener noreferrer"
- }, "nimbus-desktop-experiments"), ")");
- }
- diff --git a/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt b/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt
- index 436b0e22db..129e728872 100644
- --- a/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt
- +++ b/mobile/android/android-components/components/feature/search/src/main/java/mozilla/components/feature/search/telemetry/SerpTelemetryRepository.kt
- @@ -16,7 +16,7 @@ import org.json.JSONException
- import org.json.JSONObject
- import java.io.File
-
- -internal const val REMOTE_PROD_ENDPOINT_URL = "https://firefox.settings.services.mozilla.com"
- +internal const val REMOTE_PROD_ENDPOINT_URL = "resource://app/defaults/settings"
- internal const val REMOTE_ENDPOINT_BUCKET_NAME = "main"
-
- /**
- diff --git a/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt b/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt
- index c9e448e8a2..ba2638ff10 100644
- --- a/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt
- +++ b/mobile/android/android-components/components/support/remotesettings/src/main/java/mozilla/components/support/remotesettings/RemoteSettingsClient.kt
- @@ -43,7 +43,7 @@ import java.net.URL
-
- class RemoteSettingsClient(
- private val storageRootDirectory: File,
- - private val serverUrl: String = "https://firefox.settings.services.mozilla.com",
- + private val serverUrl: String = "resource://app/defaults/settings",
- private val bucketName: String = "main",
- private val collectionName: String,
- ) {
- diff --git a/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt b/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt
- index e6b153a9a4..afca8776f5 100644
- --- a/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt
- +++ b/mobile/android/android-components/components/support/remotesettings/src/test/java/mozilla/components/support/remotesettings/RemoteSettingsClientTest.kt
- @@ -37,7 +37,7 @@ class RemoteSettingsClientTest {
- mockFileReader = mock()
- mockJsonObject = mock()
- mockRemoteSettings = mock()
- - remoteSettingsClient = RemoteSettingsClient(File(""), "https://firefox.settings.services.mozilla.com", "", "")
- + remoteSettingsClient = RemoteSettingsClient(File(""), "resource://app/defaults/settings", "", "")
- }
-
- @Test
- diff --git a/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md b/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md
- index f4f852eeb1..b877808e79 100644
- --- a/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md
- +++ b/mobile/android/android-components/docs/_posts/2018-08-10-fretboard.md
- @@ -8,7 +8,7 @@ author: fernando
- ## Overview
- Firefox for Android (codenamed Fennec) started using [KeepSafe's Switchboard library](https://github.com/KeepSafe/Switchboard) and server component in order to run A/B testing or staged rollout of features, but since then the code changed significantly. It used a special [switchboard server](https://github.com/mozilla-services/switchboard-server) that decided which experiments a client is part of and returned a simplified list for the client to consume. However, this required the client to send data (including a unique id) to the server.
-
- -To avoid this Firefox moved to using [Kinto](https://github.com/Kinto/kinto) as storage and server of the experiment configuration. Clients now download the whole list of experiments and decide locally what experiments they are enrolled in (the configuration for Fennec [looks like this](https://firefox.settings.services.mozilla.com/v1/buckets/fennec/collections/experiments/records)).
- +To avoid this Firefox moved to using [Kinto](https://github.com/Kinto/kinto) as storage and server of the experiment configuration. Clients now download the whole list of experiments and decide locally what experiments they are enrolled in (the configuration for Fennec [looks like this](resource://app/defaults/settings/fennec/experiments.json)).
-
- The purpose of this Google Summer of Code project, which is called Fretboard, was to develop an A/B testing framework written in Kotlin based on the existing code from Fennec, but making it independent of both the server used and the local storage mechanism, allowing it to be used on other apps, such as Firefox Focus, which started to need to do some A/B tests.
-
- diff --git a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt
- index fcdc1ad20f..8403d64c0c 100644
- --- a/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt
- +++ b/mobile/android/fenix/app/src/main/java/org/mozilla/fenix/components/Core.kt
- @@ -676,7 +676,7 @@ class Core(
-
- // collection name to fetch from server for SERP telemetry
- const val COLLECTION_NAME = "search-telemetry-v2"
- - internal const val REMOTE_PROD_ENDPOINT_URL = "https://firefox.settings.services.mozilla.com"
- - internal const val REMOTE_STAGE_ENDPOINT_URL = "https://firefox.settings.services.allizom.org"
- + internal const val REMOTE_PROD_ENDPOINT_URL = "resource://app/defaults/settings"
- + internal const val REMOTE_STAGE_ENDPOINT_URL = "resource://app/defaults/settings"
- }
- }
- diff --git a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt
- index b419f85faf..9a3fc984e2 100644
- --- a/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt
- +++ b/mobile/android/focus-android/app/src/main/java/org/mozilla/focus/telemetry/GleanMetricsService.kt
- @@ -62,8 +62,8 @@ class GleanMetricsService(context: Context) : MetricsService {
- const val COLLECTION_NAME = "search-telemetry-v2"
-
- // urls for prod and stage remote settings server
- - internal const val REMOTE_PROD_ENDPOINT_URL = "https://firefox.settings.services.mozilla.com"
- - internal const val REMOTE_STAGE_ENDPOINT_URL = "https://firefox.settings.services.allizom.org"
- + internal const val REMOTE_PROD_ENDPOINT_URL = "resource://app/defaults/settings"
- + internal const val REMOTE_STAGE_ENDPOINT_URL = "resource://app/defaults/settings"
-
- private val isEnabledByDefault: Boolean
- get() = !AppConstants.isKlarBuild
- diff --git a/services/settings/Utils.sys.mjs b/services/settings/Utils.sys.mjs
- index 12fef6cde8..13d940455e 100644
- --- a/services/settings/Utils.sys.mjs
- +++ b/services/settings/Utils.sys.mjs
- @@ -102,7 +102,7 @@ export var Utils = {
- : AppConstants.REMOTE_SETTINGS_SERVER_URL;
- },
-
- - CHANGES_PATH: "/buckets/monitor/collections/changes/changeset",
- + CHANGES_PATH: "/monitor/changes",
-
- /**
- * Logger instance.
- diff --git a/services/settings/docs/index.rst b/services/settings/docs/index.rst
- index a834bb74a0..17c7f7b9cc 100644
- --- a/services/settings/docs/index.rst
- +++ b/services/settings/docs/index.rst
- @@ -190,11 +190,11 @@ It is possible to package a dump of the server records that will be loaded into
-
- The JSON dump will serve as the default dataset for ``.get()``, instead of doing a round-trip to pull the latest data. It will also reduce the amount of data to be downloaded on the first synchronization.
-
- -#. Place the JSON dump of the server records in the ``services/settings/dumps/main/`` folder. Using this command:
- +#. Place the JSON dump of the server records in the ``services/settings/dumps/main/`` folder. Using this command (replace 'https://settings.invalid' with your Remote Settings address):
- ::
-
- CID="your-collection"
- - curl "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/${CID}/changeset?_expected=0" | jq '{"data": .changes, "timestamp": .timestamp}' > services/settings/dumps/main/${CID}.json``
- + curl "https://settings.invalid/v1/buckets/main/collections/${CID}/changeset?_expected=0" | jq '{"data": .changes, "timestamp": .timestamp}' > services/settings/dumps/main/${CID}.json``
-
- #. Add the filename to the relevant ``FINAL_TARGET_FILES`` list in ``services/settings/dumps/main/moz.build``
-
- diff --git a/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh b/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh
- index dd90445a30..7f3e878ca3 100755
- --- a/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh
- +++ b/taskcluster/docker/periodic-updates/scripts/periodic_file_updates.sh
- @@ -295,7 +295,7 @@ function compare_suffix_lists {
- }
-
- function compare_remote_settings_files {
- - REMOTE_SETTINGS_SERVER="https://firefox.settings.services.mozilla.com/v1"
- + REMOTE_SETTINGS_SERVER="resource://app/defaults/settings"
-
- # 1. List remote settings collections from server.
- echo "INFO: fetch remote settings list from server"
- diff --git a/third_party/rust/remote_settings/.cargo-checksum.json b/third_party/rust/remote_settings/.cargo-checksum.json
- index edae407f85..a5396ba2c1 100644
- --- a/third_party/rust/remote_settings/.cargo-checksum.json
- +++ b/third_party/rust/remote_settings/.cargo-checksum.json
- @@ -1 +1 @@
- -{"files":{"Cargo.toml":"e607c012c7d59d412f2795ad83281d67fe373c9c10859ea2a35a48e3def02a1d","src/cache.rs":"9c16f17353730103d57132a0f055863b085d2d3eb3a78f6a6f8d095f897d0c0d","src/client.rs":"e70cbbdf8a739d6a60f588ad8cc4f127aedc3db08091ff76a43dd813424148f0","src/config.rs":"496299f100673fb862aaeffdec61173f5265779e8990ab326ac91a7270fab8cc","src/error.rs":"832b80cf4d2b4464f5824ed36a37726bc99535b28d4c5c384df22ef3b906b187","src/lib.rs":"baf2e1e47f2c059531f00320ff7715a7d84ddf7df5ad1c4ec7ec4f01bee92edf","uniffi.toml":"88cfb5e8e6ea16b0a3998f34791232a22478b2027ea4f1932dcc417b51fe2e7a"},"package":null}
- \ No newline at end of file
- +{"files":{"Cargo.toml":"e607c012c7d59d412f2795ad83281d67fe373c9c10859ea2a35a48e3def02a1d","src/cache.rs":"9c16f17353730103d57132a0f055863b085d2d3eb3a78f6a6f8d095f897d0c0d","src/client.rs":"b29ba1a84ec833e0a863587feedb181d594d1b0edacc4f07db5974c728790814","src/config.rs":"6893db5c9a2499aed911a276077928204f3f02ab4812bb1b78c2cdf396f53ccd","src/error.rs":"832b80cf4d2b4464f5824ed36a37726bc99535b28d4c5c384df22ef3b906b187","src/lib.rs":"baf2e1e47f2c059531f00320ff7715a7d84ddf7df5ad1c4ec7ec4f01bee92edf","uniffi.toml":"88cfb5e8e6ea16b0a3998f34791232a22478b2027ea4f1932dcc417b51fe2e7a"},"package":null}
- diff --git a/third_party/rust/remote_settings/src/client.rs b/third_party/rust/remote_settings/src/client.rs
- index 8475b6689b..6839ae4cb2 100644
- --- a/third_party/rust/remote_settings/src/client.rs
- +++ b/third_party/rust/remote_settings/src/client.rs
- @@ -536,7 +536,7 @@ mod test {
- };
- let client = Client::new(config).unwrap();
- assert_eq!(
- - Url::parse("https://firefox.settings.services.mozilla.com").unwrap(),
- + Url::parse("resource://app/defaults/settings").unwrap(),
- client.base_url
- );
- assert_eq!(String::from("main"), client.bucket_name);
- diff --git a/third_party/rust/remote_settings/src/config.rs b/third_party/rust/remote_settings/src/config.rs
- index f4029e5bc6..6405328481 100644
- --- a/third_party/rust/remote_settings/src/config.rs
- +++ b/third_party/rust/remote_settings/src/config.rs
- @@ -51,9 +51,9 @@ impl RemoteSettingsServer {
- /// inside the crate.
- pub(crate) fn get_url(&self) -> Result<Url> {
- Ok(match self {
- - Self::Prod => Url::parse("https://firefox.settings.services.mozilla.com").unwrap(),
- - Self::Stage => Url::parse("https://firefox.settings.services.allizom.org").unwrap(),
- - Self::Dev => Url::parse("https://remote-settings-dev.allizom.org").unwrap(),
- + Self::Prod => Url::parse("resource://app/defaults/settings").unwrap(),
- + Self::Stage => Url::parse("resource://app/defaults/settings").unwrap(),
- + Self::Dev => Url::parse("resource://app/defaults/settings").unwrap(),
- Self::Custom { url } => Url::parse(url)?,
- })
- }
- diff --git a/toolkit/components/antitracking/docs/query-stripping/index.md b/toolkit/components/antitracking/docs/query-stripping/index.md
- index e49d8513ba..c1c6ae5deb 100644
- --- a/toolkit/components/antitracking/docs/query-stripping/index.md
- +++ b/toolkit/components/antitracking/docs/query-stripping/index.md
- @@ -63,7 +63,7 @@ of query params:
- It is enabled in Nightly by default in all modes with an extended
- strip-list. You can find the current list of parameters that are
- stripped
- -[here](https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/query-stripping/records).
- +[here](resource://app/defaults/settings/main/collections/query-stripping/records).
- Note that some records have a *filter\_expression* that limits where
- they apply.
-
- diff --git a/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs b/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs
- index aafe4a6dcf..cfdefe2ef8 100644
- --- a/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs
- +++ b/toolkit/components/backgroundtasks/BackgroundTask_message.sys.mjs
- @@ -19,8 +19,8 @@
- // environment variables still apply.
- //
- // --stage: use stage Remote Settings
- -// (`https://firefox.settings.services.allizom.org/v1`) rather than production
- -// (`https://firefox.settings.services.mozilla.com/v1`)
- +// (`resource://app/defaults/settings/`) rather than production
- +// (`resource://app/defaults/settings/`)
- //
- // --preview: enable Remote Settings and Experiment previews.
- //
- @@ -71,7 +71,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
- Utils: "resource://services-settings/Utils.sys.mjs",
- });
-
- -const SERVER_STAGE = "https://firefox.settings.services.allizom.org/v1";
- +const SERVER_STAGE = "resource://app/defaults/settings";
-
- // Default profile targeting snapshot.
- let defaultProfileTargetingSnapshot = {};
- diff --git a/toolkit/components/search/SearchUtils.sys.mjs b/toolkit/components/search/SearchUtils.sys.mjs
- index d7c5c05cb5..b2e4dd3f6c 100644
- --- a/toolkit/components/search/SearchUtils.sys.mjs
- +++ b/toolkit/components/search/SearchUtils.sys.mjs
- @@ -162,13 +162,13 @@ export var SearchUtils = {
-
- ENGINES_URLS: {
- "prod-main":
- - "https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config/records",
- + "resource://app/defaults/settings/main/search-config.json",
- "prod-preview":
- - "https://firefox.settings.services.mozilla.com/v1/buckets/main-preview/collections/search-config/records",
- + "resource://app/defaults/settings/main/search-config.json",
- "stage-main":
- - "https://firefox.settings.services.allizom.org/v1/buckets/main/collections/search-config/records",
- + "resource://app/defaults/settings/main/search-config.json",
- "stage-preview":
- - "https://firefox.settings.services.allizom.org/v1/buckets/main-preview/collections/search-config/records",
- + "resource://app/defaults/settings/main/search-config.json",
- },
-
- // The following constants are left undocumented in nsISearchService.idl
- diff --git a/toolkit/components/search/docs/DefaultSearchEngines.rst b/toolkit/components/search/docs/DefaultSearchEngines.rst
- index 3dfe68abb1..26d5f18a7b 100644
- --- a/toolkit/components/search/docs/DefaultSearchEngines.rst
- +++ b/toolkit/components/search/docs/DefaultSearchEngines.rst
- @@ -99,4 +99,4 @@ is updated.
-
- .. _configuration schema: SearchConfigurationSchema.html
- .. _remote settings: /services/settings/index.html
- -.. _search-default-override-allowlist bucket: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-default-override-allowlist/records
- +.. _search-default-override-allowlist bucket: resource://app/defaults/settings/main/search-default-override-allowlist.json
- diff --git a/toolkit/components/search/docs/SearchEngineConfiguration.rst b/toolkit/components/search/docs/SearchEngineConfiguration.rst
- index ca6009a0ef..66ef611e73 100644
- --- a/toolkit/components/search/docs/SearchEngineConfiguration.rst
- +++ b/toolkit/components/search/docs/SearchEngineConfiguration.rst
- @@ -40,7 +40,7 @@ An outline of the schemas may be found on the `Search Configuration Schema`_ pag
- .. _JSON schema: https://json-schema.org/
- .. _stored in mozilla-central: https://searchfox.org/mozilla-central/source/toolkit/components/search/schema/
- .. _Search Configuration Schema: SearchConfigurationSchema.html
- -.. _viewed live: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config-v2/records
- -.. _search-config-icons: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config-icons/records
- -.. _search-config-overrides-v2: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config-overrides-v2/records
- -.. _search-default-override-allowlist: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-default-override-allowlist/records
- +.. _viewed live: resource://app/defaults/settings/main/search-config-v2.json
- +.. _search-config-icons: resource://app/defaults/settings/main/search-config-icons.json
- +.. _search-config-overrides-v2: resource://app/defaults/settings/main/search-config-overrides-v2.json
- +.. _search-default-override-allowlist: resource://app/defaults/settings/main/search-default-override-allowlist.json
- diff --git a/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst b/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst
- index a6aba91a42..0700ab0b69 100644
- --- a/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst
- +++ b/toolkit/components/search/docs/SearchEngineConfigurationArchive.rst
- @@ -68,5 +68,5 @@ related. As a result several situations may occur:
- .. _JSON schema: https://json-schema.org/
- .. _stored in mozilla-central: https://searchfox.org/mozilla-central/source/toolkit/components/search/schema/
- .. _Search Configuration Schema: SearchConfigurationSchema.html
- -.. _viewed live: https://firefox.settings.services.mozilla.com/v1/buckets/main/collections/search-config/records
- +.. _viewed live: resource://app/defaults/settings/main/search-config.json
- .. _Normandy: /toolkit/components/normandy/normandy/services.html
- diff --git a/toolkit/modules/AppConstants.sys.mjs b/toolkit/modules/AppConstants.sys.mjs
- index a20e45c613..6c200784fe 100644
- --- a/toolkit/modules/AppConstants.sys.mjs
- +++ b/toolkit/modules/AppConstants.sys.mjs
- @@ -390,9 +390,9 @@ export var AppConstants = Object.freeze({
-
- REMOTE_SETTINGS_SERVER_URL:
- #ifdef MOZ_THUNDERBIRD
- - "https://thunderbird-settings.thunderbird.net/v1",
- + "resource://app/defaults/settings",
- #else
- - "https://firefox.settings.services.mozilla.com/v1",
- + "resource://app/defaults/settings",
- #endif
-
- REMOTE_SETTINGS_VERIFY_SIGNATURE:
- --
- 2.47.0
- From 23be7658779a5d1cab0e1f0c146420395b99f6f8 Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 17:34:08 +0200
- Subject: [PATCH 02/13] Remove polling triggered by push broadcasts
- When initialized, remote-settings.sys.mjs adds a listener to push broadcasts,
- that let Remote Settings server send push messages to trigger polling
- for changes from the client side. This is not needed for local-only
- setup. Remove the record from broadcast-listeners.json file stored in
- the user profile, so that it doesn't get picked up by push broadcast
- service.
- ---
- dom/push/PushBroadcastService.sys.mjs | 13 +++++++++++++
- services/settings/remote-settings.sys.mjs | 11 ++---------
- 2 files changed, 15 insertions(+), 9 deletions(-)
- diff --git a/dom/push/PushBroadcastService.sys.mjs b/dom/push/PushBroadcastService.sys.mjs
- index eea31ef192..529ecd6917 100644
- --- a/dom/push/PushBroadcastService.sys.mjs
- +++ b/dom/push/PushBroadcastService.sys.mjs
- @@ -168,6 +168,19 @@ export var BroadcastService = class {
- }
- }
-
- + async deleteListener(broadcastId) {
- + await this.initializePromise;
- +
- + if (this.jsonFile.data.listeners.hasOwnProperty(broadcastId)) {
- + console.info(
- + "deleteListener: deleting listener",
- + broadcastId
- + );
- + delete this.jsonFile.data.listeners[broadcastId];
- + this.jsonFile.saveSoon();
- + }
- + }
- +
- /**
- * Call the listeners of the specified broadcasts.
- *
- diff --git a/services/settings/remote-settings.sys.mjs b/services/settings/remote-settings.sys.mjs
- index 7a5530abd2..e17f1b5b5b 100644
- --- a/services/settings/remote-settings.sys.mjs
- +++ b/services/settings/remote-settings.sys.mjs
- @@ -586,11 +586,7 @@ function remoteSettingsFunction() {
- moduleURI: import.meta.url,
- symbolName: "remoteSettingsBroadcastHandler",
- };
- - lazy.pushBroadcastService.addListener(
- - BROADCAST_ID,
- - currentVersion,
- - moduleInfo
- - );
- + lazy.pushBroadcastService.deleteListener(BROADCAST_ID);
- };
-
- return remoteSettings;
- @@ -610,9 +606,6 @@ export var remoteSettingsBroadcastHandler = {
- `Push notification received (version=${version} phase=${phase})`
- );
-
- - return RemoteSettings.pollChanges({
- - expectedTimestamp: version,
- - trigger: isStartup ? "startup" : "broadcast",
- - });
- + return;
- },
- };
- --
- 2.47.0
- From eeae799a1b5ab7d9b167ee8010cedadebc6b56bc Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 17:41:54 +0200
- Subject: [PATCH 03/13] Remove timer that triggers polling for changes
- That is not needed for local-only setup.
- ---
- services/settings/components.conf | 9 +--------
- services/settings/servicesSettings.manifest | 4 ----
- 2 files changed, 1 insertion(+), 12 deletions(-)
- diff --git a/services/settings/components.conf b/services/settings/components.conf
- index fbc4df9bfc..25109415a7 100644
- --- a/services/settings/components.conf
- +++ b/services/settings/components.conf
- @@ -4,11 +4,4 @@
- # 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/.
-
- -Classes = [
- - {
- - 'cid': '{5e756573-234a-49ea-bbe4-59ec7a70657d}',
- - 'contract_ids': ['@mozilla.org/services/settings;1'],
- - 'esModule': 'resource://services-settings/RemoteSettingsComponents.sys.mjs',
- - 'constructor': 'RemoteSettingsTimer',
- - },
- -]
- +Classes = []
- diff --git a/services/settings/servicesSettings.manifest b/services/settings/servicesSettings.manifest
- index 3bfed26ea4..807eb220ec 100644
- --- a/services/settings/servicesSettings.manifest
- +++ b/services/settings/servicesSettings.manifest
- @@ -1,7 +1,3 @@
- # Register resource aliases
- resource services-settings resource://gre/modules/services-settings/
-
- -# Schedule polling of remote settings changes
- -# (default 24H, max 72H)
- -# see syntax https://searchfox.org/mozilla-central/rev/cc280c4be94ff8cf64a27cc9b3d6831ffa49fa45/toolkit/components/timermanager/UpdateTimerManager.jsm#155
- -category update-timer RemoteSettingsComponents @mozilla.org/services/settings;1,getService,services-settings-poll-changes,services.settings.poll_interval,86400,259200
- --
- 2.47.0
- From 1352df7a424eeceec577ae53660ef06337608693 Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 17:47:41 +0200
- Subject: [PATCH 04/13] Utils: fetch timestamps of each collection locally
- Utils.CHANGES_PATH points to
- services/settings/dumps/monitor/changes
- which will be generated later by JSON processing script. Fetch the
- timestamps from that file and mock response headers to not confuse any
- code that expects them.
- ---
- services/settings/Utils.sys.mjs | 28 ++++++++++++++++++++---
- services/settings/dumps/monitor/moz.build | 8 +++++++
- services/settings/dumps/moz.build | 1 +
- 3 files changed, 34 insertions(+), 3 deletions(-)
- create mode 100644 services/settings/dumps/monitor/moz.build
- diff --git a/services/settings/Utils.sys.mjs b/services/settings/Utils.sys.mjs
- index 13d940455e..d5dfe84823 100644
- --- a/services/settings/Utils.sys.mjs
- +++ b/services/settings/Utils.sys.mjs
- @@ -411,7 +411,7 @@ export var Utils = {
- async fetchLatestChanges(serverUrl, options = {}) {
- const { expectedTimestamp, lastEtag = "", filters = {} } = options;
-
- - let url = serverUrl + Utils.CHANGES_PATH;
- + let url = Utils.SERVER_URL + Utils.CHANGES_PATH;
- const params = {
- ...filters,
- _expected: expectedTimestamp ?? 0,
- @@ -426,7 +426,21 @@ export var Utils = {
- .map(([k, v]) => `${k}=${encodeURIComponent(v)}`)
- .join("&");
- }
- - const response = await Utils.fetch(url);
- + const rawResponse = await fetch(url);
- + const responseDate = new Date().toUTCString();
- +
- + const headers = new Headers();
- + headers.set("Date", responseDate);
- + headers.set("Last-Modified", responseDate);
- + headers.set("Content-Type", "application/json");
- +
- + const responseAttributes = {
- + status: rawResponse.status,
- + statusText: rawResponse.statusText,
- + headers,
- + };
- +
- + const response = new Response(rawResponse.body, responseAttributes);
-
- if (response.status >= 500) {
- throw new Error(`Server error ${response.status} ${response.statusText}`);
- @@ -461,7 +475,15 @@ export var Utils = {
- }
- }
-
- - const { changes = [], timestamp } = payload;
- + const { timestamp } = payload;
- + const { bucket, collection } = filters;
- + if (!bucket || !collection) {
- + throw new Error('Unable to fetch latest change without bucket or collection');
- + }
- + const change = payload.changes.find(
- + change => change.bucket === bucket && change.collection === collection
- + ) ?? { last_modified: 0, bucket, collection };
- + const changes = [change];
-
- let serverTimeMillis = Date.parse(response.headers.get("Date"));
- // Since the response is served via a CDN, the Date header value could have been cached.
- diff --git a/services/settings/dumps/monitor/moz.build b/services/settings/dumps/monitor/moz.build
- new file mode 100644
- index 0000000000..25c53a2eeb
- --- /dev/null
- +++ b/services/settings/dumps/monitor/moz.build
- @@ -0,0 +1,8 @@
- +# 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/.
- +
- +FINAL_TARGET_FILES.defaults.settings.monitor += ["changes"]
- +
- +if CONFIG["MOZ_BUILD_APP"] == "browser":
- + DIST_SUBDIR = "browser"
- diff --git a/services/settings/dumps/moz.build b/services/settings/dumps/moz.build
- index a3e9e9b3f2..b32a8d8691 100644
- --- a/services/settings/dumps/moz.build
- +++ b/services/settings/dumps/moz.build
- @@ -5,6 +5,7 @@
- DIRS += [
- "blocklists",
- "main",
- + "monitor",
- "security-state",
- ]
-
- --
- 2.47.0
- From fe166bca96785e408782eeea77d9083e9b7e599a Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 17:52:10 +0200
- Subject: [PATCH 05/13] Utils: disable offline checking
- Since only local data is read now, it should always return false for the
- current and any future code that relies on it.
- ---
- services/settings/Utils.sys.mjs | 10 ----------
- 1 file changed, 10 deletions(-)
- diff --git a/services/settings/Utils.sys.mjs b/services/settings/Utils.sys.mjs
- index d5dfe84823..7fcb28863d 100644
- --- a/services/settings/Utils.sys.mjs
- +++ b/services/settings/Utils.sys.mjs
- @@ -192,16 +192,6 @@ export var Utils = {
- * @return {bool} Whether network is down or not.
- */
- get isOffline() {
- - try {
- - return (
- - Services.io.offline ||
- - lazy.CaptivePortalService.state ==
- - lazy.CaptivePortalService.LOCKED_PORTAL ||
- - !lazy.gNetworkLinkService.isLinkUp
- - );
- - } catch (ex) {
- - log.warn("Could not determine network status.", ex);
- - }
- return false;
- },
-
- --
- 2.47.0
- From b209bdae1c54577442378773790770dd7c1f4150 Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 17:56:02 +0200
- Subject: [PATCH 06/13] Refactor hashing logic to a separate function
- It is used instead of internal signature validation mechanism, for
- integrity checking of the locally cached data.
- ---
- services/settings/RemoteSettingsWorker.sys.mjs | 4 ++++
- services/settings/SharedUtils.sys.mjs | 9 +++++++--
- 2 files changed, 11 insertions(+), 2 deletions(-)
- diff --git a/services/settings/RemoteSettingsWorker.sys.mjs b/services/settings/RemoteSettingsWorker.sys.mjs
- index 57bfb3f3d5..52a0b7961a 100644
- --- a/services/settings/RemoteSettingsWorker.sys.mjs
- +++ b/services/settings/RemoteSettingsWorker.sys.mjs
- @@ -177,6 +177,10 @@ class Worker {
- // task on the current thread instead of the worker thread.
- return lazy.SharedUtils.checkContentHash(buffer, size, hash);
- }
- +
- + async getContentHash(bytes) {
- + return lazy.SharedUtils.getContentHash(bytes);
- + }
- }
-
- // Now, first add a shutdown blocker. If that fails, we must have
- diff --git a/services/settings/SharedUtils.sys.mjs b/services/settings/SharedUtils.sys.mjs
- index 1eeaf0bed9..d998a2d3b1 100644
- --- a/services/settings/SharedUtils.sys.mjs
- +++ b/services/settings/SharedUtils.sys.mjs
- @@ -21,11 +21,16 @@ export var SharedUtils = {
- return false;
- }
- // Has expected content?
- + const hashStr = await this.getContentHash(bytes);
- + return hashStr == hash;
- + },
- +
- + async getContentHash(bytes) {
- const hashBuffer = await crypto.subtle.digest("SHA-256", bytes);
- const hashBytes = new Uint8Array(hashBuffer);
- const toHex = b => b.toString(16).padStart(2, "0");
- - const hashStr = Array.from(hashBytes, toHex).join("");
- - return hashStr == hash;
- +
- + return Array.from(hashBytes, toHex).join("");
- },
-
- /**
- --
- 2.47.0
- From 0f02e4174404f1b43f3359ab9d630b3d7c78823e Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 18:05:02 +0200
- Subject: [PATCH 07/13] Client: Fetch and hash records from local dump
- Read the records from local dumps. See [1] for details on how to prepare
- custom dumps). Records are cached in the local IndexedDB, and the client
- updates cached records each time there's a change. Also it verifies
- integrity of the data. Then the list of current / created / updated /
- deleted records is generated and emitted to every registered listener.
- Change upstream signature validation mechanism to a simpler one.
- Otherwise, it'd be necessary to sign local records, which is redundant,
- because the application package should be signed already by the distro.
- Instead of signature property from metadata records, json_dump_metadata
- has been introduced. It contains the checksum of the records and size in
- bytes. Also added app_build_id property for version checking and updates
- of cached data.
- Although it's possible to disable integrity checking via preference, it
- seems to be not a good idea, because the logic that detects invalid
- local data relies on it. In the context of local-only setup, data that
- has been received from real Remote Settings server will not contain the
- custom metadata, and thus will be considered invalid and then discarded,
- while the client gets a chance to gracefully inform registered listeners
- about these changes so that they can discard the data received before
- the upgrade to local-only setup.
- [1] https://firefox-source-docs.mozilla.org/services/common/services/RemoteSettings.html#initial-data
- ---
- .../settings/RemoteSettingsClient.sys.mjs | 66 ++++++++-----------
- 1 file changed, 28 insertions(+), 38 deletions(-)
- diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
- index 7e98e6d5b3..64a592e055 100644
- --- a/services/settings/RemoteSettingsClient.sys.mjs
- +++ b/services/settings/RemoteSettingsClient.sys.mjs
- @@ -714,11 +714,9 @@ export class RemoteSettingsClient extends EventEmitter {
-
- // If the data is up-to-date but don't have metadata (records loaded from dump),
- // we fetch them and validate the signature immediately.
- - if (this.verifySignature && lazy.ObjectUtils.isEmpty(localMetadata)) {
- + if (this.verifySignature && lazy.ObjectUtils.isEmpty(localMetadata?.json_dump_metadata)) {
- lazy.console.debug(`${this.identifier} pull collection metadata`);
- - const metadata = await this.httpClient().getData({
- - query: { _expected: expectedTimestamp },
- - });
- + const { metadata } = await this._fetchChangeset(expectedTimestamp);
- await this.db.importChanges(metadata);
- // We don't bother validating the signature if the dump was just loaded. We do
- // if the dump was loaded at some other point (eg. from .get()).
- @@ -995,38 +993,28 @@ export class RemoteSettingsClient extends EventEmitter {
- * @returns {Promise}
- */
- async _validateCollectionSignature(records, timestamp, metadata) {
- - if (!metadata?.signature) {
- + if (!metadata?.json_dump_metadata) {
- throw new MissingSignatureError(this.identifier);
- }
-
- - if (!this._verifier) {
- - this._verifier = Cc[
- - "@mozilla.org/security/contentsignatureverifier;1"
- - ].createInstance(Ci.nsIContentSignatureVerifier);
- - }
- -
- - // This is a content-signature field from an autograph response.
- const {
- - signature: { x5u, signature },
- + json_dump_metadata: { hash, size },
- } = metadata;
- - const certChain = await (await lazy.Utils.fetch(x5u)).text();
- // Merge remote records with local ones and serialize as canonical JSON.
- const serialized = await lazy.RemoteSettingsWorker.canonicalStringify(
- records,
- timestamp
- );
-
- - lazy.console.debug(`${this.identifier} verify signature using ${x5u}`);
- + lazy.console.debug(`${this.identifier} verify signature using size ${size} and hash ${hash}`);
- if (
- - !(await this._verifier.asyncVerifyContentSignature(
- - serialized,
- - "p384ecdsa=" + signature,
- - certChain,
- - this.signerName,
- - lazy.Utils.CERT_CHAIN_ROOT_IDENTIFIER
- + !(await lazy.RemoteSettingsWorker.checkContentHash(
- + new TextEncoder().encode(serialized),
- + size,
- + hash
- ))
- ) {
- - throw new InvalidSignatureError(this.identifier, x5u);
- + throw new InvalidSignatureError(this.identifier);
- }
- }
-
- @@ -1193,24 +1181,26 @@ export class RemoteSettingsClient extends EventEmitter {
- * @param since timestamp of last sync (optional)
- */
- async _fetchChangeset(expectedTimestamp, since) {
- - const client = this.httpClient();
- - const {
- - metadata,
- - timestamp: remoteTimestamp,
- - changes: remoteRecords,
- - } = await client.execute(
- - {
- - path: `/buckets/${this.bucketName}/collections/${this.collectionName}/changeset`,
- - },
- - {
- - query: {
- - _expected: expectedTimestamp,
- - _since: since,
- - },
- - }
- + const { data } = await lazy.SharedUtils.loadJSONDump(
- + this.bucketName,
- + this.collectionName
- );
- + const remoteRecords = data ?? [];
- +
- + const serialized = await lazy.RemoteSettingsWorker.canonicalStringify(
- + remoteRecords,
- + expectedTimestamp
- + );
- + const bytes = new TextEncoder().encode(serialized);
- + const metadata = {
- + app_build_id: Services.appinfo.appBuildID,
- + json_dump_metadata: {
- + hash: await lazy.RemoteSettingsWorker.getContentHash(bytes),
- + size: bytes.length,
- + },
- + }
- return {
- - remoteTimestamp,
- + remoteTimestamp: expectedTimestamp,
- metadata,
- remoteRecords,
- };
- --
- 2.47.0
- From 8b6f8dfd7bf32488e1f17312c483b7f1de55d4c3 Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 18:42:56 +0200
- Subject: [PATCH 08/13] Client: start deferred sync on get() or on()
- The users of the RemoteSettingsClient.sys.mjs can receive records from it in
- two ways: by calling get(), and by subscribing to events by calling
- on().
- So hook a deferred sync whenever something calls these methods. Because
- multiple of those calls can be made quite early and in very short time,
- set up a deferred task that will be armed only when needed and only once
- in a second. When the task is running it first checks if the local data
- came from the dump of the current app build, and no-ops if true. If
- false, it triggers a sync. Then adds a flag if the client has been
- correctly synchronized with the dump, so that no metadata checking
- occurs during the session.
- ---
- .../settings/RemoteSettingsClient.sys.mjs | 27 ++++++++++++++++++-
- 1 file changed, 26 insertions(+), 1 deletion(-)
- diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
- index 64a592e055..371f58bfd4 100644
- --- a/services/settings/RemoteSettingsClient.sys.mjs
- +++ b/services/settings/RemoteSettingsClient.sys.mjs
- @@ -12,6 +12,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
- ClientEnvironmentBase:
- "resource://gre/modules/components-utils/ClientEnvironment.sys.mjs",
- Database: "resource://services-settings/Database.sys.mjs",
- + DeferredTask: "resource://gre/modules/DeferredTask.sys.mjs",
- IDBHelpers: "resource://services-settings/IDBHelpers.sys.mjs",
- KintoHttpClient: "resource://services-common/kinto-http-client.sys.mjs",
- ObjectUtils: "resource://gre/modules/ObjectUtils.sys.mjs",
- @@ -23,6 +24,7 @@ ChromeUtils.defineESModuleGetters(lazy, {
- });
-
- const TELEMETRY_COMPONENT = "Remotesettings";
- +const DEFERRED_SYNC_DELAY_MILLISECONDS = 1000;
-
- ChromeUtils.defineLazyGetter(lazy, "console", () => lazy.Utils.log);
-
- @@ -341,6 +343,11 @@ export class RemoteSettingsClient extends EventEmitter {
- this._lastCheckTimePref = lastCheckTimePref;
- this._verifier = null;
- this._syncRunning = false;
- + this._deferredSync = new lazy.DeferredTask(async () => {
- + if (!this._syncRunning && !(await this._isSynced())) {
- + await this.sync();
- + }
- + }, DEFERRED_SYNC_DELAY_MILLISECONDS);
-
- // This attribute allows signature verification to be disabled, when running tests
- // or when pulling data from a dev server.
- @@ -370,6 +377,11 @@ export class RemoteSettingsClient extends EventEmitter {
- this.db.identifier = this.identifier;
- }
-
- + on(event, callback) {
- + super.on(event, callback);
- + this._deferredSync.arm();
- + }
- +
- get identifier() {
- return `${this.bucketName}/${this.collectionName}`;
- }
- @@ -443,6 +455,10 @@ export class RemoteSettingsClient extends EventEmitter {
- let lastModified = forceSync ? null : await this.db.getLastModified();
- let hasLocalData = lastModified !== null;
-
- + if (!(await this._isSynced())) {
- + throw new MissingSignatureError(this.identifier);
- + }
- +
- if (forceSync) {
- if (!this._importingPromise) {
- this._importingPromise = (async () => {
- @@ -559,7 +575,10 @@ export class RemoteSettingsClient extends EventEmitter {
- // No need to verify signature on JSON dumps.
- // If local DB cannot be read, then we don't even try to do anything,
- // we return results early.
- - return this._filterEntries(data);
- + const filtered = this._filterEntries(data);
- + this._deferredSync.arm();
- +
- + return filtered;
- }
-
- lazy.console.debug(
- @@ -599,6 +618,12 @@ export class RemoteSettingsClient extends EventEmitter {
- return final;
- }
-
- + async _isSynced() {
- + this._synced ||=
- + Services.appinfo.appBuildID === (await this.db?.getMetadata())?.app_build_id;
- + return this._synced;
- + }
- +
- /**
- * Synchronize the local database with the remote server.
- *
- --
- 2.47.0
- From 4346c63a3cd1312424fb79dcbce912b64c97357a Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 18:53:51 +0200
- Subject: [PATCH 09/13] Client: deep compare records if timestamps match
- When the list of current / updated / deleted records is generated, their
- modification timestamps are compared to detect the updates.
- Although in practice this is unlikely to happen, in theory the
- timestamp of some older record received from Remote Settings can match
- with the modified record in the dump. Although JSON processing script
- makes sure to add unique timestamps to each of the modified records,
- it's still possible to update dumps manually and simply forget to update
- timestamps. So serialize the records and compare them as strings to be
- on the safe side. This should happen only once after upgrading to each
- new version of the application, so is not likely to introduce any
- noticeable performance issues.
- ---
- services/settings/RemoteSettingsClient.sys.mjs | 6 +++++-
- 1 file changed, 5 insertions(+), 1 deletion(-)
- diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
- index 371f58bfd4..3119d5b33d 100644
- --- a/services/settings/RemoteSettingsClient.sys.mjs
- +++ b/services/settings/RemoteSettingsClient.sys.mjs
- @@ -9,6 +9,7 @@ import { Downloader } from "resource://services-settings/Attachments.sys.mjs";
- const lazy = {};
-
- ChromeUtils.defineESModuleGetters(lazy, {
- + CanonicalJSON: "resource://gre/modules/CanonicalJSON.sys.mjs",
- ClientEnvironmentBase:
- "resource://gre/modules/components-utils/ClientEnvironment.sys.mjs",
- Database: "resource://services-settings/Database.sys.mjs",
- @@ -1181,7 +1182,10 @@ export class RemoteSettingsClient extends EventEmitter {
- const old = oldById.get(r.id);
- if (old) {
- oldById.delete(r.id);
- - if (r.last_modified != old.last_modified) {
- + if (
- + r.last_modified != old.last_modified ||
- + lazy.CanonicalJSON.stringify(r) != lazy.CanonicalJSON.stringify(old)
- + ) {
- syncResult.updated.push({ old, new: r });
- }
- } else {
- --
- 2.47.0
- From 2c094c83de139f3f0d1ab8e43fc8e5b376286c3f Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 19:01:39 +0200
- Subject: [PATCH 10/13] Client: delete more data on cleanup
- When the client detects the local data is invalid (i.e. it came from
- real Remote Settings and can have unwanted records), delete not only
- the records, but also the attachments that came with them, because they
- too can be problematic. And last check time preference, because it's not
- useful anyway when remote-settings.sys.mjs doesn't do any polling for changes.
- Note that attachments should be deleted before the records, because the
- logic gets the data about the attachments from those records.
- ---
- services/settings/RemoteSettingsClient.sys.mjs | 12 +++++++++---
- 1 file changed, 9 insertions(+), 3 deletions(-)
- diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
- index 3119d5b33d..c26e81ce0a 100644
- --- a/services/settings/RemoteSettingsClient.sys.mjs
- +++ b/services/settings/RemoteSettingsClient.sys.mjs
- @@ -262,7 +262,7 @@ class AttachmentDownloader extends Downloader {
- allRecords
- .filter(r => !!r.attachment)
- .map(r =>
- - Promise.all([this.deleteDownloaded(r), this.deleteFromDisk(r)])
- + Promise.all([this.deleteDownloaded(r), this.deleteFromDisk(r), this.deleteCached(r.id)])
- )
- );
- }
- @@ -1141,7 +1141,7 @@ export class RemoteSettingsClient extends EventEmitter {
- // Signature failed, clear local DB because it contains
- // bad data (local + remote changes).
- lazy.console.debug(`${this.identifier} clear local data`);
- - await this.db.clear();
- + await this._clearAll();
- // Local data was tampered, throw and it will retry from empty DB.
- lazy.console.error(`${this.identifier} local data was corrupted`);
- throw new CorruptedDataError(this.identifier);
- @@ -1163,7 +1163,7 @@ export class RemoteSettingsClient extends EventEmitter {
- // _importJSONDump() only clears DB if dump is available,
- // therefore do it here!
- if (imported < 0) {
- - await this.db.clear();
- + await this._clearAll();
- }
- }
- }
- @@ -1203,6 +1203,12 @@ export class RemoteSettingsClient extends EventEmitter {
- return syncResult;
- }
-
- + async _clearAll() {
- + await this.attachments.deleteAll();
- + await this.db.clear();
- + Services.prefs.clearUserPref(this.lastCheckTimePref);
- + }
- +
- /**
- * Fetch information from changeset endpoint.
- *
- --
- 2.47.0
- From 8330c0202a34df1b2c33ca5cbaacf449e2a29480 Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 19:07:56 +0200
- Subject: [PATCH 11/13] Client: remove comparison of collection timestamps
- In case if the cached data that came from real Remote Settings server
- (before the upgrade to local-only setup) has collection timestamp, that
- is newer than the packaged local dump, then this comparison logic can
- lead to early return of old data, skipping the integrity checking and
- necessary cleanup. So remove the checks.
- ---
- services/settings/RemoteSettingsClient.sys.mjs | 5 -----
- 1 file changed, 5 deletions(-)
- diff --git a/services/settings/RemoteSettingsClient.sys.mjs b/services/settings/RemoteSettingsClient.sys.mjs
- index c26e81ce0a..65b3393946 100644
- --- a/services/settings/RemoteSettingsClient.sys.mjs
- +++ b/services/settings/RemoteSettingsClient.sys.mjs
- @@ -1083,14 +1083,9 @@ export class RemoteSettingsClient extends EventEmitter {
- updated: [],
- deleted: [],
- };
- - // If data wasn't changed, return empty sync result.
- - // This can happen when we update the signature but not the data.
- lazy.console.debug(
- `${this.identifier} local timestamp: ${localTimestamp}, remote: ${remoteTimestamp}`
- );
- - if (localTimestamp && remoteTimestamp < localTimestamp) {
- - return syncResult;
- - }
-
- await this.db.importChanges(metadata, remoteTimestamp, remoteRecords, {
- clear: retry,
- --
- 2.47.0
- From 56ea078c21cd355e9a01c8f901a105c9985b1ebf Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 19:15:44 +0200
- Subject: [PATCH 12/13] Attachments: load only from dump and drop cached
- ---
- services/settings/Attachments.sys.mjs | 44 +++++----------------------
- 1 file changed, 8 insertions(+), 36 deletions(-)
- diff --git a/services/settings/Attachments.sys.mjs b/services/settings/Attachments.sys.mjs
- index 9982c27661..00c1491ea5 100644
- --- a/services/settings/Attachments.sys.mjs
- +++ b/services/settings/Attachments.sys.mjs
- @@ -334,10 +334,11 @@ export class Downloader {
- retries,
- checkHash,
- attachmentId = record?.id,
- - fallbackToCache = false,
- fallbackToDump = false,
- avoidDownload = false,
- } = options || {};
- + const fallbackToCache = false;
- +
- if (!attachmentId) {
- // Check for pre-condition. This should not happen, but it is explicitly
- // checked to avoid mixing up attachments, which could be dangerous.
- @@ -397,6 +398,7 @@ export class Downloader {
- const newBuffer = await this.downloadAsBytes(record, {
- retries,
- checkHash,
- + dumpInfo,
- });
- const blob = new Blob([newBuffer]);
- // Store in cache but don't wait for it before returning.
- @@ -430,7 +432,7 @@ export class Downloader {
- }
-
- try {
- - return { ...(await cacheInfo.getResult()), _source: "cache_fallback" };
- + await this.cacheImpl.delete(attachmentId);
- } catch (e) {
- // Failed to read from cache, e.g. IndexedDB unusable.
- console.error(e);
- @@ -518,7 +520,7 @@ export class Downloader {
- * @returns {String} the absolute file path to the downloaded attachment.
- */
- async downloadToDisk(record, options = {}) {
- - const { retries = 3 } = options;
- + const retries = 0;
- const {
- attachment: { filename, size, hash },
- } = record;
- @@ -573,40 +575,10 @@ export class Downloader {
- */
- async downloadAsBytes(record, options = {}) {
- const {
- - attachment: { location, hash, size },
- - } = record;
- -
- - let baseURL;
- - try {
- - baseURL = await lazy.Utils.baseAttachmentsURL();
- - } catch (error) {
- - throw new Downloader.ServerInfoError(error);
- - }
- -
- - const remoteFileUrl = baseURL + location;
- + dumpInfo = new LazyRecordAndBuffer(() => this._readAttachmentDump(attachmentId))
- + } = options;
-
- - const { retries = 3, checkHash = true } = options;
- - let retried = 0;
- - while (true) {
- - try {
- - const buffer = await this._fetchAttachment(remoteFileUrl);
- - if (!checkHash) {
- - return buffer;
- - }
- - if (
- - await lazy.RemoteSettingsWorker.checkContentHash(buffer, size, hash)
- - ) {
- - return buffer;
- - }
- - // Content is corrupted.
- - throw new Downloader.BadContentError(location);
- - } catch (e) {
- - if (retried >= retries) {
- - throw e;
- - }
- - }
- - retried++;
- - }
- + return (await dumpInfo.getResult()).buffer;
- }
-
- /**
- --
- 2.47.0
- From f93a08be54f24a2cf9a1cf8693e3682288a34564 Mon Sep 17 00:00:00 2001
- From: grizzlyuser <grizzlyuser@protonmail.com>
- Date: Wed, 30 Dec 2020 19:22:20 +0200
- Subject: [PATCH 13/13] Disable CRLite entirely for now
- It's designed to fetch the data from Remote Settings. One of the main
- selling points is that new revocations can be pushed to the clients
- within minutes. That won't work with local-only setup. Although (some?)
- of the JSON dumps for it are in place, obviously the updates won't
- happen that fast.
- Disable the preference right in the source code, so that the patch fails
- to apply when the upstream decides to set it to fully enforcing mode
- by default.
- The solution with CRLite is up for discussion. If necessary, it's
- possible to make clients for blessed collections to communicate to real
- Remote Settings server. For example, for collections related to
- certificate revocations.
- ---
- modules/libpref/init/StaticPrefList.yaml | 2 +-
- security/manager/ssl/nsNSSComponent.cpp | 1 +
- 2 files changed, 2 insertions(+), 1 deletion(-)
- diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
- index 72202ac640..1d9c6f97f7 100644
- --- a/modules/libpref/init/StaticPrefList.yaml
- +++ b/modules/libpref/init/StaticPrefList.yaml
- @@ -15778,7 +15778,7 @@
- # 3: Consult CRLite and enforce "Not Revoked" results, but defer to OCSP for "Revoked".
- - name: security.pki.crlite_mode
- type: RelaxedAtomicUint32
- - value: 3
- + value: 0
- mirror: always
-
- # The CRLite filter channel to which the user is subscribed.
- diff --git a/security/manager/ssl/nsNSSComponent.cpp b/security/manager/ssl/nsNSSComponent.cpp
- index ed15648dae..0ac4762d11 100644
- --- a/security/manager/ssl/nsNSSComponent.cpp
- +++ b/security/manager/ssl/nsNSSComponent.cpp
- @@ -1142,6 +1142,7 @@ void nsNSSComponent::setValidationOptions(
- CRLiteMode defaultCRLiteMode = CRLiteMode::Disabled;
- CRLiteMode crliteMode =
- static_cast<CRLiteMode>(StaticPrefs::security_pki_crlite_mode());
- + // Adding a comment just in case so that the patch breaks as soon as any surrounding lines get changed
- switch (crliteMode) {
- case CRLiteMode::Disabled:
- case CRLiteMode::TelemetryOnly:
- --
- 2.47.0
|