#131271·hermes-agent

Desktop remote connection to a gated serve fails: WS Origin guard rejects the loopback renderer origin

Author: wweic-codeCreated Oct 2, 2026Updated Oct 2, 2026
Labelstype/bugcomp/clicomp/gatewayarea/authP1sweeper:risk-security-boundarycomp/desktop

Bug Description

Hermes Desktop, run on a machine with no local Hermes install (remote-only mode), cannot connect to a gated hermes serve bound to a non-loopback interface (e.g. a Tailscale IP). The main-process HTTP probe (GET /api/status) succeeds ("Remote Hermes backend is ready"), but the renderer's WebSocket upgrade to /api/ws fails with "Could not connect to Hermes gateway (WebSocket error before open)". Browsers accessing the same URL work fine.

Steps to Reproduce

  1. Run hermes serve --host <non-loopback IP> --port 9119 with dashboard auth enabled (auth_required=true, basic provider).
  2. On a separate user account / machine with no Hermes install, run Hermes Desktop and point it at http://<non-loopback IP>:9119 (remote backend).
  3. Complete the login window.
  4. Observe: HTTP probe OK, but the boot overlay fails with "Could not connect to Hermes gateway (WebSocket error before open)".

Root Cause

hermes_cli/web_server_chat.py::_ws_host_origin_reason() enforces the DNS-rebinding Origin guard for WebSocket upgrades: the request's Origin must match the bound host. The packaged Desktop loads its renderer from a random loopback port (http://127.0.0.1:<random>), so the browser-standard WebSocket it opens to the remote backend carries Origin: http://127.0.0.1:<random>, which never matches a non-loopback bound host → handshake rejected with HTTP 403 (Starlette converts a pre-accept ws.close(4403) into a 403). The rejection happens before accept, so the server logs nothing — no accepted, no refused line — which makes this very hard to diagnose.

Browsers are unaffected because they are same-origin (Origin == bound host).

Proposed Fix

Exempt loopback origins in _ws_host_origin_reason(): a WebSocket whose Origin hostname is in _LOOPBACK_HOSTS ({"127.0.0.1","::1","localhost","testclient"}, already defined in the same module) should pass the Origin check. This is safe because browsers cannot forge the Origin header (it is set automatically and unscriptable), so a malicious site's upgrade still carries its own origin and is rejected; the token/ticket auth remains the real boundary.

diff
     parsed = urllib.parse.urlparse(origin)
     if parsed.scheme not in {"http", "https"}:
         return None
+    if parsed.hostname and parsed.hostname.lower() in _LOOPBACK_HOSTS:
+        return None
     if not parsed.netloc or not _is_accepted_host(parsed.netloc, bound_host, trusted_public_hosts):
         return f"origin_mismatch origin={origin} bound={bound_host}"
     return None

Source: NousResearch/hermes-agent