Bug 1873526: Refactor the restriction override list from a big if statement to a list r=KrisWright

Differential Revision: https://phabricator.services.mozilla.com/D198081
This commit is contained in:
Tom Ritter 2024-01-11 17:10:13 +00:00
parent afe161fa94
commit 04689ca3bc

View file

@ -5951,8 +5951,8 @@ struct PrefListEntry {
// StaticPrefList.yml), a string pref, and it is NOT exempted in // StaticPrefList.yml), a string pref, and it is NOT exempted in
// sDynamicPrefOverrideList // sDynamicPrefOverrideList
// //
// This behavior is codified in ShouldSanitizePreference() below where // This behavior is codified in ShouldSanitizePreference() below.
// exclusions of preferences can be defined. // Exclusions of preferences can be defined in sOverrideRestrictionsList[].
static const PrefListEntry sRestrictFromWebContentProcesses[] = { static const PrefListEntry sRestrictFromWebContentProcesses[] = {
// Remove prefs with user data // Remove prefs with user data
PREF_LIST_ENTRY("datareporting.policy."), PREF_LIST_ENTRY("datareporting.policy."),
@ -6001,6 +6001,19 @@ static const PrefListEntry sRestrictFromWebContentProcesses[] = {
PREF_LIST_ENTRY("toolkit.telemetry.previousBuildID"), PREF_LIST_ENTRY("toolkit.telemetry.previousBuildID"),
}; };
// Allowlist for prefs and branches blocklisted in
// sRestrictFromWebContentProcesses[], including prefs from
// StaticPrefList.yaml and *.js, to let them pass.
static const PrefListEntry sOverrideRestrictionsList[]{
PREF_LIST_ENTRY("services.settings.clock_skew_seconds"),
PREF_LIST_ENTRY("services.settings.last_update_seconds"),
PREF_LIST_ENTRY("services.settings.loglevel"),
// This is really a boolean dynamic pref, but one Nightly user
// has it set as a string...
PREF_LIST_ENTRY("services.settings.preview_enabled"),
PREF_LIST_ENTRY("services.settings.server"),
};
// These prefs are dynamically-named (i.e. not specified in prefs.js or // These prefs are dynamically-named (i.e. not specified in prefs.js or
// StaticPrefList) and would normally by blocklisted but we allow them through // StaticPrefList) and would normally by blocklisted but we allow them through
// anyway, so this override list acts as an allowlist // anyway, so this override list acts as an allowlist
@ -6055,8 +6068,8 @@ static const PrefListEntry sDynamicPrefOverrideList[]{
PREF_LIST_ENTRY("print_printer"), PREF_LIST_ENTRY("print_printer"),
PREF_LIST_ENTRY("places.interactions.customBlocklist"), PREF_LIST_ENTRY("places.interactions.customBlocklist"),
PREF_LIST_ENTRY("remote.log.level"), PREF_LIST_ENTRY("remote.log.level"),
// services.* preferences should be added in ShouldSanitizePreference - the // services.* preferences should be added in sOverrideRestrictionsList[] -
// whole preference branch gets sanitized by default. // the whole preference branch gets sanitized by default.
PREF_LIST_ENTRY("spellchecker.dictionary"), PREF_LIST_ENTRY("spellchecker.dictionary"),
PREF_LIST_ENTRY("test.char"), PREF_LIST_ENTRY("test.char"),
PREF_LIST_ENTRY("Test.IPC."), PREF_LIST_ENTRY("Test.IPC."),
@ -6090,14 +6103,12 @@ static bool ShouldSanitizePreference(const Pref* const aPref) {
// pref through. // pref through.
for (const auto& entry : sRestrictFromWebContentProcesses) { for (const auto& entry : sRestrictFromWebContentProcesses) {
if (strncmp(entry.mPrefBranch, prefName, entry.mLen) == 0) { if (strncmp(entry.mPrefBranch, prefName, entry.mLen) == 0) {
const auto* p = prefName; // This avoids clang-format doing ugly things. for (const auto& pasEnt : sOverrideRestrictionsList) {
return !(strncmp("services.settings.clock_skew_seconds", p, 36) == 0 || if (strncmp(pasEnt.mPrefBranch, prefName, pasEnt.mLen) == 0) {
strncmp("services.settings.last_update_seconds", p, 37) == 0 || return false;
strncmp("services.settings.loglevel", p, 26) == 0 || }
// This is really a boolean dynamic pref, but one Nightly user }
// has it set as a string... return true;
strncmp("services.settings.preview_enabled", p, 33) == 0 ||
strncmp("services.settings.server", p, 24) == 0);
} }
} }