From 216d3a9fafc949ddeae1ca2115d1ce0217d8e8ce Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 18 Jul 2024 10:00:19 +0200 Subject: [PATCH] Add more validation when setting `AppOptions` (PR 18413 follow-up) After the changes in PR 18413 we're now relying even more on `AppOptions` and it thus seems like a good idea to ensure that no invalid values can be added. Hence the `AppOptions.{set, setAll}` methods will now *unconditionally* validate that the type of the values agree with the default-options. --- web/app_options.js | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/web/app_options.js b/web/app_options.js index d61aa0bb7..250573674 100644 --- a/web/app_options.js +++ b/web/app_options.js @@ -511,6 +511,11 @@ class AppOptions { } static set(name, value) { + const defaultOption = defaultOptions[name]; + + if (!defaultOption || typeof value !== typeof defaultOption.value) { + return; + } userOptions[name] = value; } @@ -518,22 +523,18 @@ class AppOptions { let events; for (const name in options) { - const userOption = options[name]; + const defaultOption = defaultOptions[name], + userOption = options[name]; + if (!defaultOption || typeof userOption !== typeof defaultOption.value) { + continue; + } if (prefs) { - const defaultOption = defaultOptions[name]; - - if (!defaultOption) { - continue; - } - const { kind, value } = defaultOption; + const { kind } = defaultOption; if (!(kind & OptionKind.BROWSER || kind & OptionKind.PREFERENCE)) { continue; } - if (typeof userOption !== typeof value) { - continue; - } if (this.eventBus && kind & OptionKind.EVENT_DISPATCH) { (events ||= new Map()).set(name, userOption); }