Skip to content

The agent that grows with you

fix(desktop): validate WebSocket token before backend ready

atakan gd4221b27365a
diff --git a/apps/desktop/electron/main.ts b/apps/desktop/electron/main.ts
index b9e966067a3..ce2d09c8839 100644
--- a/apps/desktop/electron/main.ts
+++ b/apps/desktop/electron/main.ts
@@ -8023,6 +8023,17 @@ async function spawnPoolBackend(profile, entry) {
entry.token = authToken
+ // Verify the WebSocket session token before declaring backend ready.
+ // HTTP /api/status can pass while WS auth fails (separate transport, separate guards).
+ const wsUrl = `ws://127.0.0.1:${port}/api/ws?token=${encodeURIComponent(authToken)}`
+ const wsProbe = await probeGatewayWebSocket(wsUrl, { WebSocketImpl: globalThis.WebSocket })
+
+ if (!wsProbe.ok) {
+ throw new Error(
+ `Hermes backend for profile "${profile}" is HTTP-reachable but the WebSocket (/api/ws) rejected the session token: ${wsProbe.reason}`
+ )
+ }
+
return {
baseUrl,
mode: 'local',
@@ -8030,7 +8041,7 @@ async function spawnPoolBackend(profile, entry) {
authMode: 'token',
token: authToken,
profile,
- wsUrl: `ws://127.0.0.1:${port}/api/ws?token=${encodeURIComponent(authToken)}`,
+ wsUrl,
logs: hermesLog.slice(-80),
...getWindowState()
}
@@ -8348,6 +8359,16 @@ async function startHermes() {
rememberLog
})
+ // Verify the WebSocket session token before declaring backend ready.
+ const wsUrl = `ws://127.0.0.1:${port}/api/ws?token=${encodeURIComponent(authToken)}`
+ const wsProbe = await probeGatewayWebSocket(wsUrl, { WebSocketImpl: globalThis.WebSocket })
+
+ if (!wsProbe.ok) {
+ throw new Error(
+ `Local Hermes backend is HTTP-reachable but the WebSocket (/api/ws) rejected the session token: ${wsProbe.reason}`
+ )
+ }
+
updateBootProgress({
phase: 'backend.ready',
message: 'Hermes backend is ready. Finalizing desktop startup',
@@ -8362,7 +8383,7 @@ async function startHermes() {
source: 'local',
authMode: 'token',
token: authToken,
- wsUrl: `ws://127.0.0.1:${port}/api/ws?token=${encodeURIComponent(authToken)}`,
+ wsUrl,
logs: hermesLog.slice(-80),
...getWindowState()
}