From 65d67e6f79283b358aa19b107033f221134c935d Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Mon, 18 May 2026 05:17:10 +0800 Subject: [PATCH] fix: host connections failing with "Authentication failed" (#791) Co-authored-by: LukeGus --- src/backend/ssh/docker-console.ts | 6 ++++++ src/backend/ssh/terminal.ts | 6 ++++++ src/ui/features/terminal/Terminal.tsx | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/src/backend/ssh/docker-console.ts b/src/backend/ssh/docker-console.ts index 6c93afaf..2532c69a 100644 --- a/src/backend/ssh/docker-console.ts +++ b/src/backend/ssh/docker-console.ts @@ -257,6 +257,12 @@ wss.on("connection", async (ws: WebSocket, req) => { } } + if (!token) { + const urlObj = new URL(req.url || "", "http://localhost"); + const qp = urlObj.searchParams.get("token"); + if (qp) token = qp; + } + if (!token) { ws.close(1008, "Authentication required"); return; diff --git a/src/backend/ssh/terminal.ts b/src/backend/ssh/terminal.ts index 10582603..050b1ef5 100644 --- a/src/backend/ssh/terminal.ts +++ b/src/backend/ssh/terminal.ts @@ -505,6 +505,12 @@ wss.on("connection", async (ws: WebSocket, req) => { } } + if (!token) { + const urlObj = new URL(req.url || "", "http://localhost"); + const qp = urlObj.searchParams.get("token"); + if (qp) token = qp; + } + if (!token) { ws.close(1008, "Authentication required"); return; diff --git a/src/ui/features/terminal/Terminal.tsx b/src/ui/features/terminal/Terminal.tsx index 04e3eb06..9768721c 100644 --- a/src/ui/features/terminal/Terminal.tsx +++ b/src/ui/features/terminal/Terminal.tsx @@ -884,6 +884,10 @@ const TerminalInner = forwardRef( .replace(/^https?:\/\//, "") .replace(/\/$/, ""); baseWsUrl = `${wsProtocol}${wsHost}/ssh/websocket/`; + const storedJwt = localStorage.getItem("jwt"); + if (storedJwt) { + baseWsUrl += `?token=${encodeURIComponent(storedJwt)}`; + } } } else { baseWsUrl = `${getBasePath()}/ssh/websocket/`;