Skip to content

The agent that grows with you

fix(web-access): a missing or out-of-dist page icon is a 404, not the app page

Tekniumdc3923961431
diff --git a/hermes_cli/web_server_static_assets.py b/hermes_cli/web_server_static_assets.py
index 1f8cd678407..809062e047a 100644
--- a/hermes_cli/web_server_static_assets.py
+++ b/hermes_cli/web_server_static_assets.py
@@ -14,12 +14,15 @@ from pathlib import Path
# Requests under these prefixes are files, never client-side routes, so a miss is a 404 rather
# than the SPA shell (a font answered with HTML renders in a fallback face, silently).
STATIC_ASSET_PREFIXES: tuple[str, ...] = ("assets/", "ds-assets/", "fonts/", "fonts-terminal/")
+# Root page icons answer without sign-in, so a missing (or out-of-dist) icon must be a 404, not
+# the SPA shell served anonymously.
+STATIC_ASSET_FILES: frozenset[str] = frozenset({"apple-touch-icon.png", "favicon.ico"})
_PUBLIC_FONT_DIRS: tuple[str, ...] = ("fonts", "fonts-terminal")
_WEB_PUBLIC = Path(__file__).resolve().parent.parent / "web" / "public"
def is_static_asset_path(full_path: str) -> bool:
- return full_path.startswith(STATIC_ASSET_PREFIXES)
+ return full_path in STATIC_ASSET_FILES or full_path.startswith(STATIC_ASSET_PREFIXES)
def public_font_file(dist: Path, dashboard_dist: Path, full_path: str) -> Path | None:
diff --git a/tests/hermes_cli/test_dashboard_auth_page_icons.py b/tests/hermes_cli/test_dashboard_auth_page_icons.py
index 2c67dbb6c23..36fbcec3618 100644
--- a/tests/hermes_cli/test_dashboard_auth_page_icons.py
+++ b/tests/hermes_cli/test_dashboard_auth_page_icons.py
@@ -45,3 +45,28 @@ def test_other_files_still_require_sign_in(gated_webapp, path):
assert response.status_code == 302
assert "/login" in response.headers["location"]
+
+
[email protected]("path", ["/apple-touch-icon.png", "/favicon.ico"])
+def test_missing_page_icon_is_a_404_not_the_page(gated_webapp, path):
+ (web_server.app.state.web_dist / path.lstrip("/")).unlink()
+
+ response = gated_webapp.get(path, follow_redirects=False)
+
+ assert response.status_code == 404
+ assert "html" not in response.headers.get("content-type", "")
+
+
[email protected]("path", ["/apple-touch-icon.png", "/favicon.ico"])
+def test_page_icon_linked_outside_the_dist_is_a_404(gated_webapp, tmp_path, path):
+ outside = tmp_path / "outside.png"
+ outside.write_bytes(b"outside bytes")
+ icon = web_server.app.state.web_dist / path.lstrip("/")
+ icon.unlink()
+ icon.symlink_to(outside)
+
+ response = gated_webapp.get(path, follow_redirects=False)
+
+ assert response.status_code == 404
+ assert b"outside bytes" not in response.content
+ assert "html" not in response.headers.get("content-type", "")