Repository navigation
Description
Bug Description
Summary
Hermes Desktop in Remote gateway mode connects to the remote backend's REST layer but the WebSocket leg (/api/ws) is always rejected, so the UI sits
on "Could not connect to Hermes gateway." As far as I can tell, there is no bind configuration where a packaged Electron desktop on machine B can
satisfy the WS admission gates on a gateway running on machine A.
Environment
- Desktop (client): macOS, Hermes 0.15.1
- Gateway (remote): Linux, Hermes 0.15.1 (release 2026.5.29), reached over Tailscale at http://:9119
- HERMES_AUTH_REQUIRED=false on the gateway
Suggested fix
Allow the Desktop's remote WS handshake to authenticate on the session token alone for non-loopback binds, or explicitly permit the Electron desktop's
non-web Origin when the request carries a valid _SESSION_TOKEN (decouple the Origin/peer DNS-rebinding guards from the token-authenticated desktop
path).
Steps to Reproduce
Repro
- On machine A, run the dashboard/gateway and expose port 9119 to machine B.
- On machine B, set Desktop → Remote gateway, URL http://:9119, token = the dashboard session token.
- Launch Desktop.
Expected Behavior
Expected
Desktop connects and the chat UI loads against the remote gateway.
Actual
- desktop.log: Connecting to remote Hermes backend at http://:9119 → Remote Hermes backend is ready (the /api/status boot probe passes).
- UI then shows "Hermes couldn't start / Could not connect to Hermes gateway."
- A direct handshake to ws://:9119/api/ws?token=<session_token> returns HTTP 403 regardless of token or Origin.
Analysis
REST works (_is_accepted_host passes by hostname) and auth is fine (verified the ?token= value equals the server's _SESSION_TOKEN injected into the
HTML). The 403 comes from _ws_request_is_allowed in hermes_cli/web_server.py, and the two sub-checks appear mutually exclusive for a remote Electron
client:
- _ws_client_is_allowed — with a loopback bind, only loopback peers are allowed, so a remote desktop peer is rejected.
- _ws_host_origin_is_allowed — the packaged Electron renderer sends a non-web Origin (file:///null), which is only accepted when the bind is loopback
(bound_host in _LOOPBACK_HOST_VALUES). With a non-loopback bind it's rejected.
So binding loopback fails the client/peer check, and binding non-loopback fails the origin check — leaving no configuration where a remote
packaged-Electron desktop passes both. This makes the documented "Remote gateway" feature unusable for the intended cross-machine case (it only works
when the client is effectively loopback to the gateway).
Actual Behavior
Hermes Desktop in Remote gateway mode connects to the remote backend's REST layer but the WebSocket leg (/api/ws) is always rejected, so the UI sits
on "Could not connect to Hermes gateway." As far as I can tell, there is no bind configuration where a packaged Electron desktop on machine B can
satisfy the WS admission gates on a gateway running on machine A.
Environment
- Desktop (client): macOS, Hermes 0.15.1
- Gateway (remote): Linux, Hermes 0.15.1 (release 2026.5.29), reached over Tailscale at http://:9119
- HERMES_AUTH_REQUIRED=false on the gateway
Affected Component
Other
Messaging Platform (if gateway-related)
N/A (CLI only)
Debug Report
Already attachedOperating System
Mac
Python Version
No response
Hermes Version
No response
Additional Logs / Traceback (optional)
Root Cause Analysis (optional)
No response
Proposed Fix (optional)
No response
Are you willing to submit a PR for this?
- I'd like to fix this myself and submit a PR
Activity
katiL-UI commentedon Jun 5, 2026
Approach: API Server as WebSocket/REST proxy to Dashboard
We hit the same problem (Desktop remote gateway unusable) and worked around it with a different architectural approach: instead of having the Desktop connect directly to the Dashboard (port 9119), we route through the API Server (port 8642), which proxies both WebSocket and REST
/api/*traffic to the Dashboard internally on loopback.This sidesteps the
file:///nullorigin check entirely — the API server talks to the Dashboard on127.0.0.1, where loopback origin checks pass. The Desktop only ever talks to the API server.What we added to
api_server.py1. Import additions (line ~49)
2. Auth: accept
X-Hermes-Session-Tokenheader (in_check_auth)The Desktop sends
X-Hermes-Session-Tokeninstead ofAuthorization: Bearer. Added a second check after the Bearer block:3.
/api/statusendpointThe Desktop probes this to detect auth mode. Simple public endpoint:
Route:
self._app.router.add_get("/api/status", self._handle_api_status)4. Dashboard token helper
Fetches and caches the dashboard session token from the dashboard root HTML:
5. WebSocket proxy (
/api/ws)Validates
?token=againstAPI_SERVER_KEY, fetches dashboard token, opens client WS tows://127.0.0.1:9119/api/ws?token=<dash_token>, bidirectionally proxies messages.6. Catch-all REST proxy (
/api/{tail:.*})Forwards unmatched
/api/*requests tohttp://127.0.0.1:9119/api/{tail}, translatingX-Hermes-Session-Token→Authorization: Bearer <dash_token>.7. CORS
Why this works
The Desktop connects to
http://<host>:8642(API server). All requests go through the API server's aiohttp stack, where thefile:///nullorigin from Electron is handled by the CORS middleware (not the WebSocket admission gates inweb_server.py). The actual Dashboard WebSocket connection happens on loopback, where origin checks pass normally.Trade-offs vs. fixing
_ws_request_is_alloweddirectly__HERMES_SESSION_TOKEN__appears stable).aiohttpon the API server side (already a gateway dependency).Happy to turn this into a PR if there's interest. The code is tested and working with Hermes Desktop 0.15.1 against a remote Linux gateway.
govtech42 commentedon Jun 6, 2026
Hit the same failure on macOS 0.15.1, and after digging through the WebSocket admission gates I think the most common cause for "the desktop reaches the backend but the WS always 403s" is token mismatch, not the loopback/origin conflict described above. Two distinct failure modes, two distinct fixes, easy to confuse.
My repro (macOS 0.15.1, both ends on the same LAN, no proxy):
hermes dashboardrunning under alaunchdLaunchAgent(~/Library/LaunchAgents/ai.hermes.dashboard.plist) with--host 0.0.0.0 --port 9119 --insecure.http://<lan-ip>:9119with a static token pasted intoconnection.json.Symptom (identical to this issue):
Remote Hermes backend is ready→WebSocket connection failed→ restart loop, exactly as the reporter describes.probeGatewayWebSocketreturns"WebSocket connection failed"with the generic fallback reason.Where the 403 actually comes from (in my case):
The reporter's analysis attributes the rejection to
_ws_request_is_allowedinhermes_cli/web_server.py(host/origin/peer-IP gates). For a remote Electron desktop over a non-loopback bind with--insecure, the_ws_host_origin_is_allowedshort-circuits via thebound_host in {"0.0.0.0", "::"}branch (line ~270) and_ws_client_is_allowedshort-circuits via the non-loopback-bind branch (line ~7642) — both should let the upgrade through. So the 403 is not from those gates in my repro.In my case the rejection is in
gateway_ws(line ~8121) calling_ws_auth_ok, which failshmac.compare_digestbecause the?token=value carried by the Desktop doesn't match the server's_SESSION_TOKEN. With a--insecurelaunchd service and noHERMES_DASHBOARD_SESSION_TOKENin the env,web_server.py:139falls back tosecrets.token_urlsafe(32)at process start, generating a fresh per-process random token that's only injected into the SPA<script>window.__HERMES_SESSION_TOKEN__="..."</script>block. The Desktop never scrapes the SPA, so any value the user types inconnection.jsonis a guess and will never match — the server returns 403 on the upgrade, Node'sWebSocketfiresonerror(notonopen+ earlyonclose), and the probe reports the generic"WebSocket connection failed"instead of a useful "credential rejected" reason.Verified empirically with a raw socket:
GET /api/ws(no token) →HTTP/1.1 403 Forbidden(closes connection)GET /api/ws?token=WRONG→HTTP/1.1 403 Forbidden(closes connection)GET /api/ws?token=<token scraped from /__session__ HTML>→HTTP/1.1 101 Switching Protocols✓The 403 is sent before the 101, which is why the probe's grace window never engages.
Two working fixes:
Pin the server-side token (smallest change, no client work). Set
HERMES_DASHBOARD_SESSION_TOKEN=<a-token-you-also-paste-into-connection.json>in the LaunchAgent'sEnvironmentVariables, reload, paste the same value into the Desktop'sconnection.jsonremote.token. Works for--insecureand for OAuth-gated mode alike (loopback binds ignore the token, non-loopback binds still verify it). Confirmed working on my setup.Use the OAuth gate (the path the Hermes team has been steering users toward). Drop
--insecure, configureBasicAuthProvider(or the Nous OAuth provider) viaHERMES_DASHBOARD_BASIC_AUTH_USERNAME/_PASSWORD/_SECRET, the login page renders a credential form, the Desktop's existing OAuth flow mints a single-use?ticket=viaPOST /api/auth/ws-ticket, the WS upgrade accepts it. No static token to keep in sync. End-to-end verified on my setup (login → cookies → ws-ticket → 101 Switching Protocols).Two small follow-ups I think would help everyone:
probeGatewayWebSocketinapps/desktop/electron/gateway-ws-probe.cjsdoesn't distinguish "server rejected the upgrade" (e.g. 401/403 with a body) from "TCP RST / no response". The current generic "WebSocket connection failed" string is what hides the token-mismatch case fromtestDesktopConnectionConfigusers. Surfacing the HTTP status + body when the upgrade is rejected pre-101 would unblock a lot of debugging.testDesktopConnectionConfiginapps/desktop/electron/main.cjsvalidates only the HTTP leg against the documented "ws-ticket/token auth" path. If theauthMode === 'oauth'branch were actually exercised in the test, users on--insecurewould get a clear "this remote is using legacy token auth, not OAuth — your token does not match the server's_SESSION_TOKEN" message instead of a generic failure.Happy to file either as a separate PR if there's interest, or to bundle the workaround in a skill so other LAN setups can find it. Filing as a tracking comment here first so the duplicate-issues pile (#38115, #38332, #40083) can be linked.
logancyang commentedon Jun 6, 2026
Confirming this over an SSH tunnel (
ssh -L 9119:localhost:9119), which isolates the root cause more cleanly than the Tailscale/LAN repros above — and a no-code-change workaround.SSH-tunnel case removes the peer-IP variable. Over
ssh -L, the dashboard sees the peer as127.0.0.1, so_ws_client_is_allowedpasses and the bind stays loopback. It still 403s — purely because the packaged Electron renderer (loaded fromfile://) sendsOrigin: null, which trips_ws_host_origin_is_allowed(scheme not in{http,https}→ reject). So the Origin guard alone is sufficient to break it, independent of the peer/host checks. Empirically, against a loopback-bound--tuidashboard with a valid?token=:Origin: null→403Origin: file://→403Originheader →101 Switching ProtocolsThis also explains the "ready, then connecting forever" split. The boot probe (
apps/desktop/electron/gateway-ws-probe.cjs) runs in the Node main process viaglobalThis.WebSocket, which sends no Origin →101→ "Remote backend is ready". The real chat socket (HermesGatewayinapps/desktop/src/store/gateway.ts) runs in thefile://renderer →Origin: null→403. Same URL+token, different Origin, opposite outcomes.Prerequisite worth flagging:
/api/wsalso 4403s for everyone (even loopback/no-origin) unless the dashboard runs with--tui/HERMES_DASHBOARD_TUI=1— theif not _DASHBOARD_EMBEDDED_CHAT_ENABLEDguard at the top ofgateway_ws. Easy to mistake for the Origin bug.Workaround (no code changes to app or server): a tiny localhost TCP proxy that strips the
Originheader from the upgrade request, in front of the tunnel —desktop → proxy:9119 (strip Origin) → ssh -L :9129 → dashboard :9119. The dashboard then hitsif not origin: return Trueand accepts;Origin: null/file://→101confirmed end-to-end, chat works. Core of it:This validates the suggested fix direction: in loopback/token mode the
_SESSION_TOKEN+ loopback bind are already the trust boundary, so the Origin/DNS-rebinding guard could be decoupled from the token-authenticated desktop path (accept opaque/null/file://origins when a valid_SESSION_TOKENis presented). Env: desktop 0.15.1, gateway 0.16.0.Gmatrix2022 commentedon Jun 7, 2026
复测确认 — Hermes 0.16.0 (release_date 2026.6.5) 仍未修复
环境:
100.91.207.5:9800)HERMES_DASHBOARD_SESSION_TOKEN注入容器(Mac keychain 不可用,旧版 token 输入框已禁用)服务端实测(0.16.0)
同一 token
vKCsw4jBPR0QuU6rDHS5dfzwPsTigufpxUUe9ihVFHE(43 字符):GET /api/status带X-Hermes-Session-TokenheaderGET /api/ws?token=...带 query 升级 WSgateway.ready事件GET /api/ws无 query 升级 WScompare_digest两边一致。关键观察
?token=立刻 101 + 正常推送gateway.ready事件;不带才 403。?token=(只走 header 走不通 WS,HTTP/api/status和 WS/api/ws的鉴权通道不是同一套)。期望修复
Desktop 客户端在拼
ws://gateway/api/wsURL 时,如果用户配置了 token(env 或 keystore),应自动 append?token=<value>。当前 macOS keychain 不可用、env 是唯一注入通道,这条路径不能断。相关 issue
~/.hermes/.env覆盖HERMES_DASHBOARD_SESSION_TOKEN,可能是同根因的不同表现d3faulter commentedon Jun 7, 2026
Same here on windows. Backend seems to be fine.
0xTimepunk commentedon Jun 26, 2026
Confirming this on macOS (Apple Silicon) with the official
nousresearch/hermes-agent:latestimage under OrbStack — and I think there are two distinct root causes here, plus a docs bug. Source refs are from the published image.Setup
127.0.0.1only (9119dashboard,8642API).host.docker.internal:11434(fine).HERMES_DESKTOP_REMOTE_URL=http://127.0.0.1:9119+HERMES_DESKTOP_REMOTE_TOKEN=….Root cause 1 — token-mode auth is structurally impossible once the gate engages
Desktop token mode (
buildRemoteConnection(..., 'token', token)inapps/desktop/electron/main.cjs) sends the token asX-Hermes-Session-Token(REST) and?token=(WS). Both are validated against_SESSION_TOKENinhermes_cli/web_server.py:…but the comments state
_SESSION_TOKENis loopback-only and disabled once the gate engages (web_server.py~486 and ~11390: "_SESSION_TOKENmust not grant WS access once the gate is engaged"). A Docker port-publish requires a non-loopback bind, which mandates the auth gate — so token-mode auth can never succeed. Verified: bothuser:passwordand a freshly mintedhermes_session_atreturn 401 viaX-Hermes-Session-Token.Root cause 2 — WS gate rejects the packaged-Electron origin (this issue)
_ws_request_is_allowed → _ws_host_origin_is_allowed, with a hardcoded policy:The packaged Electron renderer sends
Origin: file:///null→ fails the regex →/api/ws4403. No env var allowlists it, so even OAuth mode hits this.Docs bug
docs/user-guide/dockerrecommendsHERMES_DESKTOP_REMOTE_TOKEN=admin:yourpasswordwith basic auth. Per #1 this cannot work — the token routes to the gate-disabled_SESSION_TOKENpath. The example should be corrected.Net
With the official image + a non-loopback bind (required to publish the port), the native Desktop cannot connect via token mode at all, and the WS leg is blocked by the origin gate regardless of auth mode. The API-server-proxy approach proposed above sidesteps both gates (auth via
API_SERVER_KEY, dashboard reached on loopback) and is the most practical fix today. Happy to test a patch against this exact setup (official image + OrbStack + host Ollama).kshitijk4poor commentedon Jun 28, 2026
Verified fixed on current
main— closing.The non-web WebSocket Origin rejection (packaged Electron desktop connecting to
/api/wsin remote-gateway mode getting 4403/403 despite a valid session token) was introduced by2e66eefbcand fixed by the desktop-remote work:6ed9a2de8— allow desktop websocket origins on remote bindsdd28f2ac9— trust non-web WS origins on OAuth-gated binds after ticket authOn current
main,_ws_host_origin_reasoninhermes_cli/web_server.py(≈L11407–11415) returnsNone(allowed) for empty or non-http(s)origins (file://,null,app://), deferring to the real credential check (_ws_auth_reason,hmac.compare_digestagainst the session token). A valid-token desktop client with a non-web Origin now completes the WS upgrade (101) instead of being rejected.This issue never auto-closed only because the fixing commits didn't reference #38412 in their messages — the bug class itself is resolved. (Open PR #40408, which does name #38412, is a now-redundant re-fix of an already-fixed path.)
Fix gateway connection loss after app reinstall (session token mismatch)