Skip to content

Commit

Permalink
Bug 1598562 - Prevent Remote Settings server URL to be modified in re…
Browse files Browse the repository at this point in the history
…lease r=Gijs

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

--HG--
extra : source : 0e4aef99fe4b85e8d9fb6d568830c638b8c4cd73
  • Loading branch information
leplatrem committed Dec 9, 2019
1 parent 2efd34c commit 4bce641
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
11 changes: 3 additions & 8 deletions services/settings/RemoteSettingsClient.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ const DB_NAME = "remote-settings";
const TELEMETRY_COMPONENT = "remotesettings";

XPCOMUtils.defineLazyGetter(this, "console", () => Utils.log);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gServerURL",
"services.settings.server"
);

/**
* cacheProxy returns an object Proxy that will memoize properties of the target.
Expand Down Expand Up @@ -277,7 +272,7 @@ class RemoteSettingsClient extends EventEmitter {
}

httpClient() {
const api = new KintoHttpClient(gServerURL);
const api = new KintoHttpClient(Utils.SERVER_URL);
return api.bucket(this.bucketName).collection(this.collectionName);
}

Expand Down Expand Up @@ -398,7 +393,7 @@ class RemoteSettingsClient extends EventEmitter {
async sync(options) {
// We want to know which timestamp we are expected to obtain in order to leverage
// cache busting. We don't provide ETag because we don't want a 304.
const { changes } = await Utils.fetchLatestChanges(gServerURL, {
const { changes } = await Utils.fetchLatestChanges(Utils.SERVER_URL, {
filters: {
collection: this.collectionName,
bucket: this.bucketName,
Expand Down Expand Up @@ -547,7 +542,7 @@ class RemoteSettingsClient extends EventEmitter {
// Fetch changes from server, and make sure we overwrite local data.
const strategy = Kinto.syncStrategy.PULL_ONLY;
syncResult = await kintoCollection.sync({
remote: gServerURL,
remote: Utils.SERVER_URL,
strategy,
expectedTimestamp,
});
Expand Down
21 changes: 21 additions & 0 deletions services/settings/Utils.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
ChromeUtils.defineModuleGetter(
this,
"AppConstants",
"resource://gre/modules/AppConstants.jsm"
);

XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);

Expand All @@ -25,7 +30,23 @@ XPCOMUtils.defineLazyGetter(this, "log", () => {
});
});

XPCOMUtils.defineLazyPreferenceGetter(
this,
"gServerURL",
"services.settings.server"
);

var Utils = {
get SERVER_URL() {
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const isXpcshell = env.exists("XPCSHELL_TEST_PROFILE_DIR");
return AppConstants.RELEASE_OR_BETA && !Cu.isInAutomation && !isXpcshell
? "https://firefox.settings.services.mozilla.com/v1"
: gServerURL;
},

CHANGES_PATH: "/buckets/monitor/collections/changes/records",

/**
Expand Down
14 changes: 4 additions & 10 deletions services/settings/remote-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);

const PREF_SETTINGS_DEFAULT_BUCKET = "services.settings.default_bucket";
const PREF_SETTINGS_BRANCH = "services.settings.";
const PREF_SETTINGS_SERVER = "server";
const PREF_SETTINGS_DEFAULT_SIGNER = "default_signer";
const PREF_SETTINGS_SERVER_BACKOFF = "server.backoff";
const PREF_SETTINGS_LAST_UPDATE = "last_update_seconds";
Expand All @@ -70,11 +69,6 @@ XPCOMUtils.defineLazyGetter(this, "gPrefs", () => {
return Services.prefs.getBranch(PREF_SETTINGS_BRANCH);
});
XPCOMUtils.defineLazyGetter(this, "console", () => Utils.log);
XPCOMUtils.defineLazyPreferenceGetter(
this,
"gServerURL",
PREF_SETTINGS_BRANCH + PREF_SETTINGS_SERVER
);

/**
* Default entry filtering function, in charge of excluding remote settings entries
Expand Down Expand Up @@ -228,7 +222,7 @@ function remoteSettingsFunction() {

let pollResult;
try {
pollResult = await Utils.fetchLatestChanges(gServerURL, {
pollResult = await Utils.fetchLatestChanges(Utils.SERVER_URL, {
expectedTimestamp,
lastEtag,
});
Expand Down Expand Up @@ -375,7 +369,7 @@ function remoteSettingsFunction() {
const {
changes,
currentEtag: serverTimestamp,
} = await Utils.fetchLatestChanges(gServerURL);
} = await Utils.fetchLatestChanges(Utils.SERVER_URL);

const collections = await Promise.all(
changes.map(async change => {
Expand All @@ -402,8 +396,8 @@ function remoteSettingsFunction() {
);

return {
serverURL: gServerURL,
pollingEndpoint: gServerURL + Utils.CHANGES_PATH,
serverURL: Utils.SERVER_URL,
pollingEndpoint: Utils.SERVER_URL + Utils.CHANGES_PATH,
serverTimestamp,
localTimestamp: gPrefs.getCharPref(PREF_SETTINGS_LAST_ETAG, null),
lastCheck: gPrefs.getIntPref(PREF_SETTINGS_LAST_UPDATE, 0),
Expand Down

0 comments on commit 4bce641

Please sign in to comment.