From 659735d2159926c17c4615231864004997cfbdbc Mon Sep 17 00:00:00 2001 From: Stefan Agner Date: Wed, 4 Mar 2026 21:54:21 +0100 Subject: [PATCH] Guard _migrate validator against non-dict add-on configs (#6611) The _migrate function in addons/validate.py is the first validator in the SCHEMA_ADDON_CONFIG All() chain and was called directly with raw config data. If a malformed add-on config file contained a non-dict value (e.g. a string), config.get() would raise an AttributeError instead of a proper voluptuous Invalid error, causing an unhandled exception. Add an isinstance check at the top of _migrate to raise vol.Invalid for non-dict inputs, letting validation fail gracefully. Fixes SUPERVISOR-HMP Co-authored-by: Claude Sonnet 4.6 --- supervisor/addons/validate.py | 2 ++ tests/addons/test_config.py | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/supervisor/addons/validate.py b/supervisor/addons/validate.py index c56df63f4..6a8e84b50 100644 --- a/supervisor/addons/validate.py +++ b/supervisor/addons/validate.py @@ -244,6 +244,8 @@ def _migrate_addon_config(protocol=False): """Migrate addon config.""" def _migrate(config: dict[str, Any]): + if not isinstance(config, dict): + raise vol.Invalid("Add-on config must be a dictionary!") name = config.get(ATTR_NAME) if not name: raise vol.Invalid("Invalid Add-on config!") diff --git a/tests/addons/test_config.py b/tests/addons/test_config.py index d7ac00a77..f55666f8b 100644 --- a/tests/addons/test_config.py +++ b/tests/addons/test_config.py @@ -532,3 +532,12 @@ def test_ulimits_invalid_values(): config["ulimits"] = {"nofile": {}} with pytest.raises(vol.Invalid): vd.SCHEMA_ADDON_CONFIG(config) + + +def test_non_dict_config_raises_invalid(): + """Test that a non-dict config raises vol.Invalid, not AttributeError.""" + with pytest.raises(vol.Invalid): + vd.SCHEMA_ADDON_CONFIG("not a dict") + + with pytest.raises(vol.Invalid): + vd.SCHEMA_ADDON_CONFIG(["list", "not", "dict"])