Check cloud trusted proxies (#24395)
This commit is contained in:
1 parent
7887d6d6e4
commit
f77514c6f2
5 files changed
+83
-5
No files matched your search
@@ -38,3 +38,7 @@ DISPATCHER_REMOTE_UPDATE = 'cloud_remote_update'
|
||||
|
||||
class InvalidTrustedNetworks(Exception):
|
||||
"""Raised when invalid trusted networks config."""
|
||||
|
||||
|
||||
class InvalidTrustedProxies(Exception):
|
||||
"""Raised when invalid trusted proxies config."""
|
||||
@@ -18,7 +18,8 @@ from homeassistant.components.google_assistant import helpers as google_helpers
|
||||
|
||||
from .const import (
|
||||
DOMAIN, REQUEST_TIMEOUT, PREF_ENABLE_ALEXA, PREF_ENABLE_GOOGLE,
|
||||
PREF_GOOGLE_SECURE_DEVICES_PIN, InvalidTrustedNetworks)
|
||||
PREF_GOOGLE_SECURE_DEVICES_PIN, InvalidTrustedNetworks,
|
||||
InvalidTrustedProxies)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
@@ -52,7 +53,10 @@ SCHEMA_WS_HOOK_DELETE = websocket_api.BASE_COMMAND_MESSAGE_SCHEMA.extend({
|
||||
_CLOUD_ERRORS = {
|
||||
InvalidTrustedNetworks:
|
||||
(500, 'Remote UI not compatible with 127.0.0.1/::1'
|
||||
' as a trusted network.')
|
||||
' as a trusted network.'),
|
||||
InvalidTrustedProxies:
|
||||
(500, 'Remote UI not compatible with 127.0.0.1/::1'
|
||||
' as trusted proxies.'),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ from .const import (
|
||||
PREF_GOOGLE_SECURE_DEVICES_PIN, PREF_CLOUDHOOKS, PREF_CLOUD_USER,
|
||||
PREF_GOOGLE_ENTITY_CONFIGS, PREF_OVERRIDE_NAME, PREF_DISABLE_2FA,
|
||||
PREF_ALIASES, PREF_SHOULD_EXPOSE,
|
||||
InvalidTrustedNetworks)
|
||||
InvalidTrustedNetworks, InvalidTrustedProxies)
|
||||
|
||||
STORAGE_KEY = DOMAIN
|
||||
STORAGE_VERSION = 1
|
||||
@@ -59,6 +59,9 @@ class CloudPreferences:
|
||||
if remote_enabled is True and self._has_local_trusted_network:
|
||||
raise InvalidTrustedNetworks
|
||||
|
||||
if remote_enabled is True and self._has_local_trusted_proxies:
|
||||
raise InvalidTrustedProxies
|
||||
|
||||
await self._store.async_save(self._prefs)
|
||||
|
||||
async def async_update_google_entity_config(
|
||||
@@ -112,7 +115,7 @@ class CloudPreferences:
|
||||
if not enabled:
|
||||
return False
|
||||
|
||||
if self._has_local_trusted_network:
|
||||
if self._has_local_trusted_network or self._has_local_trusted_proxies:
|
||||
return False
|
||||
|
||||
return True
|
||||
@@ -162,3 +165,18 @@ class CloudPreferences:
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
@property
|
||||
def _has_local_trusted_proxies(self) -> bool:
|
||||
"""Return if we allow localhost to be a proxy and use its data."""
|
||||
if not hasattr(self._hass, 'http'):
|
||||
return False
|
||||
|
||||
local4 = ip_address('127.0.0.1')
|
||||
local6 = ip_address('::1')
|
||||
|
||||
if any(local4 in nwk or local6 in nwk
|
||||
for nwk in self._hass.http.trusted_proxies):
|
||||
return True
|
||||
|
||||
return False
|
||||
Reference in new issue
Block a user