1
0
mirror of https://github.com/home-assistant/supervisor.git synced 2026-04-02 00:07:16 +01:00

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 <noreply@anthropic.com>
This commit is contained in:
Stefan Agner
2026-03-04 21:54:21 +01:00
committed by GitHub
parent 0ef71d1dd1
commit 659735d215
2 changed files with 11 additions and 0 deletions

View File

@@ -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!")

View File

@@ -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"])