diff --git a/src/backend/ssh/terminal.ts b/src/backend/ssh/terminal.ts index 405afabb..0f0b7a0b 100644 --- a/src/backend/ssh/terminal.ts +++ b/src/backend/ssh/terminal.ts @@ -427,7 +427,18 @@ wss.on("connection", async (ws: WebSocket, req) => { sshStream = stream; stream.on("data", (data: Buffer) => { - ws.send(JSON.stringify({ type: "data", data: data.toString() })); + let decoded = data.toString("utf-8"); + + // Defensive fallback: if UTF-8 decode produces replacement characters + // and buffer contains high bytes, try latin1 (for legacy servers without UTF-8 locale) + if ( + decoded.includes("\uFFFD") && + data.some((byte) => byte >= 0x80 && byte <= 0xff) + ) { + decoded = data.toString("latin1"); + } + + ws.send(JSON.stringify({ type: "data", data: decoded })); }); stream.on("close", () => {