Verified Commit b5b6d436 authored by Tom Ritter's avatar Tom Ritter Committed by Pier Angelo Vendrame
Browse files

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

parent 31018d1b
Loading
Loading
Loading
Loading
+17 −5
Original line number Original line Diff line number Diff line
@@ -6024,7 +6024,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
// This behavior is codified in ShouldSanitizePreference() below.
// 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."),
@@ -6073,6 +6074,15 @@ 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.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
@@ -6168,10 +6178,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.server", p, 24) == 0);
        }
      }
      return true;
    }
    }
  }
  }