diff --git a/supervisor/utils/__init__.py b/supervisor/utils/__init__.py index 6b5907a6e..29986f31c 100644 --- a/supervisor/utils/__init__.py +++ b/supervisor/utils/__init__.py @@ -2,10 +2,11 @@ import asyncio from ipaddress import IPv4Address import logging +import os from pathlib import Path import re import socket -from typing import Any +from typing import Any, Dict _LOGGER: logging.Logger = logging.getLogger(__name__) @@ -96,3 +97,12 @@ async def remove_folder(folder: Path, content_only: bool = False) -> None: return _LOGGER.error("Can't remove folder %s: %s", folder, error_msg) + + +def clean_env() -> Dict[str, str]: + """Return a clean env from system.""" + new_env = {} + for key in ("HOME", "PATH", "PWD", "CWD", "SHLVL"): + if value := os.environ.get(key): + new_env[key] = value + return new_env diff --git a/supervisor/utils/codenotary.py b/supervisor/utils/codenotary.py index 49ea921b7..652a24f72 100644 --- a/supervisor/utils/codenotary.py +++ b/supervisor/utils/codenotary.py @@ -9,6 +9,7 @@ from typing import Optional, Set, Tuple, Union import async_timeout +from . import clean_env from ..exceptions import CodeNotaryBackendError, CodeNotaryError, CodeNotaryUntrusted _LOGGER: logging.Logger = logging.getLogger(__name__) @@ -64,6 +65,7 @@ async def vcn_validate( stdin=asyncio.subprocess.DEVNULL, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.DEVNULL, + env=clean_env(), ) async with async_timeout.timeout(10): diff --git a/supervisor/utils/gdbus.py b/supervisor/utils/gdbus.py index d6c291cc3..d900a21b1 100644 --- a/supervisor/utils/gdbus.py +++ b/supervisor/utils/gdbus.py @@ -12,6 +12,7 @@ import xml.etree.ElementTree as ET import sentry_sdk +from . import clean_env from ..exceptions import ( DBusFatalError, DBusInterfaceError, @@ -234,6 +235,7 @@ class DBus: stdin=asyncio.subprocess.DEVNULL, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, + env=clean_env(), ) data, error = await proc.communicate() @@ -320,6 +322,7 @@ class DBusSignalWrapper: stdin=asyncio.subprocess.DEVNULL, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE, + env=clean_env(), ) return self