Skip to content

The agent that grows with you

fix(webapp): answer a file: URL with an encoded NUL as an invalid path

unsupportedpastels20ba4b2409e1
diff --git a/hermes_cli/web_routers/files.py b/hermes_cli/web_routers/files.py
index 43a7660cbaa..e1e07bd4f42 100644
--- a/hermes_cli/web_routers/files.py
+++ b/hermes_cli/web_routers/files.py
@@ -350,7 +350,7 @@ def _is_host_file(path: str, profile: Optional[str]) -> bool:
return False
try:
target = Path(path).resolve(strict=True)
- except (OSError, RuntimeError):
+ except (OSError, RuntimeError, ValueError): # ValueError: a decoded NUL (``%00``)
return False # not on this host: the workspace's to answer
with _profile_scope(profile):
home = get_hermes_home()
diff --git a/tests/hermes_cli/test_web_server_ssh_media_stream.py b/tests/hermes_cli/test_web_server_ssh_media_stream.py
index fcbf30f1c0a..cd471ce9bb3 100644
--- a/tests/hermes_cli/test_web_server_ssh_media_stream.py
+++ b/tests/hermes_cli/test_web_server_ssh_media_stream.py
@@ -284,6 +284,28 @@ def test_a_file_url_off_this_hosts_staging_still_goes_to_the_ssh_workspace(clien
assert len(asked) == 2
[email protected]("profile", ["remote-dev", "default"])
+def test_a_file_url_with_an_encoded_nul_is_an_invalid_path(client, ssh, monkeypatch, profile):
+ _profile, workspace = ssh
+
+ def refuse(path, *args, **kwargs): # as the real adapter's path check refuses every file: URL
+ raise ssh_workspace_fs.SshWorkspaceFsError("EINVAL", "Invalid path")
+
+ monkeypatch.setattr(workspace, "read_bytes", refuse)
+ monkeypatch.setattr(workspace, "inspect_file", refuse)
+ query = {"path": "file:///tmp/clip%00.mp4", "profile": profile}
+
+ responses = [
+ client.get("/api/files/stream", params=query),
+ client.get("/api/fs/read-data-url", params=query),
+ client.get("/api/fs/download", params=query),
+ ]
+
+ for response in responses:
+ assert (response.status_code, response.json()) == (400, {"detail": "Invalid path"}), response.request.url
+ assert workspace.reads == []
+
+
def test_a_down_ssh_host_is_unavailable_to_the_stream(client, ssh, monkeypatch):
from tools.environments.base import EnvironmentConnectionError