diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py index 247da3e1b6d2..a56a6d5699ba 100644 --- a/homeassistant/components/http/__init__.py +++ b/homeassistant/components/http/__init__.py @@ -725,8 +725,11 @@ async def start_http_server_and_save_config( ) if CONF_TRUSTED_PROXIES in conf: + # Store the full network (address and prefix) so the recovery config + # round-trips losslessly; ``network_address`` alone drops the netmask + # and would narrow e.g. 10.0.0.0/24 to a single host. conf[CONF_TRUSTED_PROXIES] = [ - str(cast(IPv4Network | IPv6Network, ip).network_address) + str(cast(IPv4Network | IPv6Network, ip)) for ip in conf[CONF_TRUSTED_PROXIES] ] diff --git a/tests/components/http/test_init.py b/tests/components/http/test_init.py index 5b231c8c3687..63ace3f5eb3c 100644 --- a/tests/components/http/test_init.py +++ b/tests/components/http/test_init.py @@ -490,7 +490,7 @@ async def test_storing_config( config = { http.CONF_SERVER_PORT: unused_tcp_port_factory(), "use_x_forwarded_for": True, - "trusted_proxies": ["192.168.1.100"], + "trusted_proxies": ["192.168.1.100", "10.0.0.0/24"], } assert await async_setup_component(hass, http.DOMAIN, {http.DOMAIN: config}) @@ -501,7 +501,9 @@ async def test_storing_config( await hass.async_block_till_done() restored = await http.async_get_last_config(hass) - restored["trusted_proxies"][0] = ip_network(restored["trusted_proxies"][0]) + restored["trusted_proxies"] = [ + ip_network(proxy) for proxy in restored["trusted_proxies"] + ] assert restored == http.HTTP_SCHEMA(config)