home-assistant: update patch to follow symlinks in static dir

This commit is contained in:
Martin Weinelt 2024-02-11 03:54:28 +01:00
parent e72d6a1d3f
commit ad719a4503
No known key found for this signature in database
GPG Key ID: 87C1E9888F856759
3 changed files with 13 additions and 38 deletions

View File

@ -485,7 +485,7 @@ in python.pkgs.buildPythonApplication rec {
# leave this in, so users don't have to constantly update their downstream patch handling
patches = [
# Follow symlinks in /var/lib/hass/www
./patches/static-symlinks.patch
./patches/static-follow-symlinks.patch
# Patch path to ffmpeg binary
(substituteAll {

View File

@ -0,0 +1,12 @@
diff --git a/homeassistant/components/http/static.py b/homeassistant/components/http/static.py
index e6e773d4c0..b53e0b4a11 100644
--- a/homeassistant/components/http/static.py
+++ b/homeassistant/components/http/static.py
@@ -31,7 +31,6 @@ def _get_file_path(rel_url: str, directory: Path) -> Path | None:
# where the static dir is totally different
raise HTTPForbidden
filepath: Path = directory.joinpath(filename).resolve()
- filepath.relative_to(directory)
# on opening a dir, load its contents if allowed
if filepath.is_dir():
return None

View File

@ -1,37 +0,0 @@
diff --git a/homeassistant/components/frontend/__init__.py b/homeassistant/components/frontend/__init__.py
index 2ec991750f..9a937006ce 100644
--- a/homeassistant/components/frontend/__init__.py
+++ b/homeassistant/components/frontend/__init__.py
@@ -383,7 +383,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
local = hass.config.path("www")
if os.path.isdir(local):
- hass.http.register_static_path("/local", local, not is_dev)
+ hass.http.register_static_path("/local", local, not is_dev, follow_symlinks=True)
# Can be removed in 2023
hass.http.register_redirect("/config/server_control", "/developer-tools/yaml")
diff --git a/homeassistant/components/http/__init__.py b/homeassistant/components/http/__init__.py
index 122b7b79ce..3cf2b7e0db 100644
--- a/homeassistant/components/http/__init__.py
+++ b/homeassistant/components/http/__init__.py
@@ -411,16 +411,16 @@ class HomeAssistantHTTP:
)
def register_static_path(
- self, url_path: str, path: str, cache_headers: bool = True
+ self, url_path: str, path: str, cache_headers: bool = True, follow_symlinks: bool = False
) -> None:
"""Register a folder or file to serve as a static path."""
if os.path.isdir(path):
if cache_headers:
resource: CachingStaticResource | web.StaticResource = (
- CachingStaticResource(url_path, path)
+ CachingStaticResource(url_path, path, follow_symlinks=follow_symlinks)
)
else:
- resource = web.StaticResource(url_path, path)
+ resource = web.StaticResource(url_path, path, follow_symlinks=follow_symlinks)
self.app.router.register_resource(resource)
self.app["allow_configured_cors"](resource)
return