The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: explain unsafe gateway control paths
KoNit-Ka738f521fc1c
diff --git a/hermes_cli/gateway_runtime_discovery.py b/hermes_cli/gateway_runtime_discovery.pyindex 0af76eb2519..688c8a3ed14 100644--- a/hermes_cli/gateway_runtime_discovery.py+++ b/hermes_cli/gateway_runtime_discovery.py@@ -15,8 +15,8 @@ import timeclass DiscoveryError(ValueError):- def __init__(self, reason: str):- super().__init__(reason)+ def __init__(self, reason: str, detail: str | None = None):+ super().__init__(f"{reason}: {detail}" if detail else reason)self.reason = reason@@ -63,8 +63,18 @@ def home_mode_unsafe(node: os.stat_result, path: Path) -> bool:def _private_node(path: Path, *, kind: str, home: bool = False) -> os.stat_result:node = path.lstat()predicates = {"socket": stat.S_ISSOCK, "file": stat.S_ISREG, "directory": stat.S_ISDIR}- if not predicates[kind](node.st_mode) or node.st_uid != os.getuid(): # windows-footgun: ok — POSIX socket path only- raise DiscoveryError("unsafe_control_path")+ if not predicates[kind](node.st_mode):+ raise DiscoveryError(+ "unsafe_control_path",+ f"{path} is {stat.filemode(node.st_mode)}, expected {kind}",+ )+ expected_uid = os.getuid()+ if node.st_uid != expected_uid: # windows-footgun: ok — POSIX socket path only+ raise DiscoveryError(+ "unsafe_control_path",+ f"{path} is owned by uid {node.st_uid}, expected uid {expected_uid} (gateway user); "+ "chown it to the gateway user",+ )if home_mode_unsafe(node, path) if home else stat.S_IMODE(node.st_mode) & 0o077:raise DiscoveryError("unsafe_control_permissions")return nodediff --git a/tests/hermes_cli/test_gateway_runtime_discovery.py b/tests/hermes_cli/test_gateway_runtime_discovery.pyindex cb62a994e19..8f8f885e287 100644--- a/tests/hermes_cli/test_gateway_runtime_discovery.py+++ b/tests/hermes_cli/test_gateway_runtime_discovery.py@@ -132,6 +132,28 @@ def test_fallback_pointer_uses_owner_location_and_keeps_identity_checks(tmp_pathquery_identify(home, timeout=2)[email protected]("linux", "macos")+def test_private_node_reports_path_kind_and_owner_recovery_hint(tmp_path, monkeypatch):+ from hermes_cli.gateway_runtime_discovery import _private_node++ control = tmp_path / "control"+ control.write_text("not a socket", encoding="utf-8")+ with pytest.raises(DiscoveryError, match="unsafe_control_path") as kind_error:+ _private_node(control, kind="socket")+ assert str(control) in str(kind_error.value)+ assert "expected socket" in str(kind_error.value)+ assert "-rw" in str(kind_error.value)++ node_uid = control.lstat().st_uid+ monkeypatch.setattr("hermes_cli.gateway_runtime_discovery.os.getuid", lambda: node_uid + 1)+ with pytest.raises(DiscoveryError, match="unsafe_control_path") as owner_error:+ _private_node(control, kind="file")+ assert f"owned by uid {node_uid}" in str(owner_error.value)+ assert f"expected uid {node_uid + 1}" in str(owner_error.value)+ assert "chown it to the gateway user" in str(owner_error.value)+ assert owner_error.value.reason == "unsafe_control_path"++@pytest.mark.platforms("linux", "macos")def test_home_mode_refuses_only_writes_another_user_can_make(tmp_path, monkeypatch):import grp