The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix: restarting the gateway heals a world-readable control pointer
Teknium086801b82b00
diff --git a/gateway/control_socket.py b/gateway/control_socket.pyindex d001237e72b..fa30b7df515 100644--- a/gateway/control_socket.py+++ b/gateway/control_socket.py@@ -182,6 +182,9 @@ class GatewayControlServer:self._file_identities[bind_path] = (info.st_dev, info.st_ino)if pointer_file is not None:fd = os.open(pointer_file, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o600)+ # O_CREAT's mode only applies to a NEW file; an older gateway's leftover pointer is 0644+ # and clients refuse it, so restarting must heal the mode.+ os.fchmod(fd, 0o600)with os.fdopen(fd, "w", encoding="utf-8") as pointer:pointer.write(str(bind_path))self._pointer_file = pointer_filediff --git a/tests/gateway/test_control_socket_peer_security.py b/tests/gateway/test_control_socket_peer_security.pyindex 34faf270dc5..011e9645593 100644--- a/tests/gateway/test_control_socket_peer_security.py+++ b/tests/gateway/test_control_socket_peer_security.py@@ -18,3 +18,23 @@ def test_symlinked_home_still_authenticates_same_uid_peers(tmp_path):def get_extra_info(self, _key):return oursassert GatewayControlServer(tmp_path / "link")._posix_peer_subject(Writer()) == f"uid:{os.getuid()}"+++def test_restart_heals_a_world_readable_pointer_left_by_an_older_gateway(tmp_path):+ import asyncio+ from gateway.control_socket import GatewayControlServer+ from hermes_cli.gateway_runtime_discovery import _socket_path+ home = tmp_path / ("p" * 90) / ".hermes"+ home.mkdir(parents=True, mode=0o700)+ pointer = home / "gateway.sock.path"+ pointer.write_text("/old/control.sock")+ pointer.chmod(0o644) # main wrote it with write_text under umask 022; a crash leaves it++ async def run():+ server = GatewayControlServer(home)+ assert await server.start()+ try:+ assert _socket_path(home).name == "control.sock"+ finally:+ await server.stop()+ asyncio.run(run())