From a73b95ae73c82db41d16c85f38baaed03feddf89 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 9 Feb 2026 23:12:40 +0000 Subject: [PATCH] Ensure unauthorized websocket clients cannot evict active session Co-authored-by: Theo Browne --- apps/t3/src/runtimeApiServer.test.ts | 39 ++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 16b569f5f1..615a597651 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -221,6 +221,45 @@ describe("runtimeApiServer", () => { authorizedClient.socket.close(); }); + it("does not evict authorized client when unauthorized client connects", async () => { + const server = await startRuntimeApiServer({ + port: 0, + launchCwd: process.cwd(), + authToken: "secret-token", + }); + servers.push(server); + + const authorizedClient = await connectClient(server.wsUrl); + await authorizedClient.nextMessage(); + + const authorizedClose = new Promise<{ code: number }>((resolve) => { + authorizedClient.socket.once("close", (code) => resolve({ code })); + }); + + const authorizedUrl = new URL(server.wsUrl); + const unauthorizedUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}`; + const unauthorizedClient = new WebSocket(unauthorizedUrl); + const unauthorizedClose = await withTimeout( + new Promise<{ code: number }>((resolve, reject) => { + unauthorizedClient.once("close", (code) => resolve({ code })); + unauthorizedClient.once("error", (error) => reject(error)); + }), + ); + expect(unauthorizedClose.code).toBe(4001); + + const response = await sendRequest( + authorizedClient.socket, + authorizedClient.nextMessage, + "todos-auth-1", + "todos.list", + ); + expect(response.ok).toBe(true); + + authorizedClient.socket.close(); + const closed = await withTimeout(authorizedClose); + expect([1000, 1005]).toContain(closed.code); + }); + it("returns a bootstrap payload even when codex cannot initialize", async () => { const originalPath = process.env.PATH; process.env.PATH = "";