diff --git a/homeassistant/components/websocket_api/commands.py b/homeassistant/components/websocket_api/commands.py index 4302949f10b..e66da17170f 100644 --- a/homeassistant/components/websocket_api/commands.py +++ b/homeassistant/components/websocket_api/commands.py @@ -14,6 +14,7 @@ from homeassistant.auth.models import User from homeassistant.auth.permissions.const import POLICY_READ from homeassistant.auth.permissions.events import SUBSCRIBE_ALLOWLIST from homeassistant.const import ( + CONF_EXTERNAL_URL, EVENT_STATE_CHANGED, MATCH_ALL, SIGNAL_BOOTSTRAP_INTEGRATIONS, @@ -650,7 +651,12 @@ def handle_get_config( hass: HomeAssistant, connection: ActiveConnection, msg: dict[str, Any] ) -> None: """Handle get config command.""" - connection.send_result(msg["id"], hass.config.as_dict()) + config = hass.config.as_dict() + + if connection.user.local_only: + config.pop(CONF_EXTERNAL_URL) + + connection.send_result(msg["id"], config) @decorators.websocket_command( diff --git a/tests/components/websocket_api/test_commands.py b/tests/components/websocket_api/test_commands.py index 66c528a1271..0cc82183bd6 100644 --- a/tests/components/websocket_api/test_commands.py +++ b/tests/components/websocket_api/test_commands.py @@ -34,7 +34,7 @@ from homeassistant.components.websocket_api.commands import ( ) from homeassistant.components.websocket_api.const import FEATURE_COALESCE_MESSAGES, URL from homeassistant.config_entries import ConfigEntryState -from homeassistant.const import SIGNAL_BOOTSTRAP_INTEGRATIONS +from homeassistant.const import CONF_EXTERNAL_URL, SIGNAL_BOOTSTRAP_INTEGRATIONS from homeassistant.core import Context, HomeAssistant, State, SupportsResponse, callback from homeassistant.exceptions import HomeAssistantError, ServiceValidationError from homeassistant.helpers import ( @@ -1139,10 +1139,18 @@ async def test_subscribe_triggers( assert hass.data[ALL_TRIGGER_DESCRIPTIONS_JSON_CACHE] is old_cache +@pytest.mark.parametrize( + ("local_only_user", "forbidden_keys"), [(False, []), (True, [CONF_EXTERNAL_URL])] +) async def test_get_config( - hass: HomeAssistant, websocket_client: MockHAClientWebSocket + hass: HomeAssistant, + websocket_client: MockHAClientWebSocket, + hass_admin_user: MockUser, + local_only_user: bool, + forbidden_keys: list[str], ) -> None: """Test get_config command.""" + hass_admin_user.local_only = local_only_user await websocket_client.send_json_auto_id({"type": "get_config"}) msg = await websocket_client.receive_json() @@ -1163,6 +1171,10 @@ async def test_get_config( result[key] = set(result[key]) config[key] = set(config[key]) + for key in forbidden_keys: + assert key in config + config.pop(key) + assert result == config