The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(webapp): a one-use launch link is refused where no peer check protects it
emozilla9a3ca73f3e19
diff --git a/gateway/webapp_listener.py b/gateway/webapp_listener.pyindex ffb9cb6a100..d327218a610 100644--- a/gateway/webapp_listener.py+++ b/gateway/webapp_listener.py@@ -222,9 +222,10 @@ def _close_to_other_users(folder: Path) -> None:def _one_use_links_work() -> bool:"""Whether a browser can redeem a one-use launch link here. Redemption needs proof that the- browser's connection belongs to the gateway's OS user (``web_routers.webapp._peer_is_server_user``),- which macOS cannot give, and a browser launcher's arguments are not private to the user there."""- return sys.platform != "darwin"+ browser's connection belongs to the gateway's OS user (``web_routers.webapp._peer_is_server_user``)+ on Linux, or a browser launcher whose arguments other users cannot read (Windows). macOS and the+ BSDs offer neither."""+ return sys.platform in ("linux", "win32")#: How every missing-bundle reason starts; ``hermes webapp --status`` asks for no restart after it.diff --git a/hermes_cli/web_routers/webapp.py b/hermes_cli/web_routers/webapp.pyindex a70443f16b1..e35656e43de 100644--- a/hermes_cli/web_routers/webapp.py+++ b/hermes_cli/web_routers/webapp.py@@ -124,14 +124,16 @@ def _loopback_peer_uid(client: tuple[str, int], server: tuple[str, int]) -> intdef _peer_is_server_user(request: Request) -> bool:"""Whether this request's connection belongs to the OS user running the server.- Linux authenticates the connection owner. macOS has no authenticated- launch handoff here, so an argv-carried launch ticket cannot be redeemed.- Authenticated child-window tickets do not use this launcher channel.+ Linux authenticates the connection owner. Windows needs no check: a process's command line,+ where the launch ticket travels, is readable only by its own user, SYSTEM and elevated+ administrators. Elsewhere (macOS, the BSDs) every local user can read the launcher's argv+ and nothing here identifies the connection's owner, so an argv-carried launch ticket cannot+ be redeemed. Authenticated child-window tickets do not use this launcher channel."""- if sys.platform == "darwin":- return False- if sys.platform != "linux":+ if sys.platform == "win32":return True+ if sys.platform != "linux":+ return Falseclient, server = request.client, request.scope.get("server")if client is None or not server:return Falsediff --git a/hermes_cli/webapp_launcher.py b/hermes_cli/webapp_launcher.pyindex 8d8e264cdf5..368b0ecfb7f 100644--- a/hermes_cli/webapp_launcher.py+++ b/hermes_cli/webapp_launcher.py@@ -3,8 +3,8 @@The gateway serves the Webapp on its own listener when its home's config sets ``webapp.enabled``(``gateway.webapp_listener``). This command builds the bundle when it is stale, starts the gateway thatserves the current profile, asks it for a one-use launch link over the control socket (same OS user-only) and opens that link, so the credential appears in no argv, output or link. On macOS, where a-one-use link cannot be redeemed, it prints the gateway's private link for the user to open instead.+only) and opens that link, so the credential appears in no argv, output or link. On macOS and the+BSDs, where a one-use link cannot be redeemed, it prints the gateway's private link for the user to open instead.``--status`` and ``--sign-out`` talk to a running gateway and never start one."""from __future__ import annotations@@ -249,7 +249,7 @@ def cmd_webapp(args) -> int:print(f"Open the Webapp and sign in with your dashboard account: {link['url']}")return 0if link.get("private"):- # The gateway's own credential (macOS, where a one-use link cannot be redeemed): for the user+ # The gateway's own credential (macOS, the BSDs: a one-use link cannot be redeemed): for the user# to open, never for a browser launcher whose arguments other processes can read.print("Open this link in your browser. It signs the browser in as you, so keep it private:")print(f" {link['url']}")diff --git a/tests/hermes_cli/test_webapp_launch.py b/tests/hermes_cli/test_webapp_launch.pyindex 1c4a0a8aef6..1146141181d 100644--- a/tests/hermes_cli/test_webapp_launch.py+++ b/tests/hermes_cli/test_webapp_launch.py@@ -68,3 +68,38 @@ def test_macos_launch_handoff_fails_closed_without_consuming_child_window_authorassert client.post("/webapp/window-session", headers=headers).status_code == 403finally:client.close()+++def _loopback_request():+ from types import SimpleNamespace+ return SimpleNamespace(client=SimpleNamespace(host="127.0.0.1", port=50123),+ scope={"server": ("127.0.0.1", 9120)})++[email protected]("platform", ["freebsd14", "openbsd7", "sunos5"])+def test_where_no_peer_check_exists_a_launch_ticket_is_never_spent(monkeypatch, platform):+ """Other Unixes show every process's argv to all local users by default and Hermes cannot tell+ who owns a loopback connection there. As on macOS, the launcher hands out the private+ credential link rather than a launch ticket, and a launch ticket is never spent."""+ import sys++ from gateway import webapp_listener+ from hermes_cli.web_routers import webapp++ monkeypatch.setattr(sys, "platform", platform)+ assert webapp._peer_is_server_user(_loopback_request()) is False+ assert webapp_listener._one_use_links_work() is False+++def test_windows_spends_a_launch_ticket_without_a_peer_check(monkeypatch):+ """Windows does not show a process's command line to other standard users (reading it needs a+ handle the process's DACL grants only its own user, SYSTEM and elevated administrators), so the+ ticket in the browser launcher's argv stays the user's own, as the stored credential does."""+ import sys++ from gateway import webapp_listener+ from hermes_cli.web_routers import webapp++ monkeypatch.setattr(sys, "platform", "win32")+ assert webapp._peer_is_server_user(_loopback_request()) is True+ assert webapp_listener._one_use_links_work() is True