From 7f29e39d9d253caa8d61138c8f66e853cead7a0c Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 05:12:56 +0000 Subject: [PATCH] Reject duplicate websocket token parameters Co-authored-by: Theo Browne --- apps/t3/scripts/smoke-test.mjs | 7 +++++++ apps/t3/src/runtimeApiServer.test.ts | 15 +++++++++++++++ apps/t3/src/runtimeApiServer.ts | 3 ++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/apps/t3/scripts/smoke-test.mjs b/apps/t3/scripts/smoke-test.mjs index b3bb4ed0b1..2233111677 100644 --- a/apps/t3/scripts/smoke-test.mjs +++ b/apps/t3/scripts/smoke-test.mjs @@ -1365,6 +1365,13 @@ async function main() { ); await waitForUnauthorizedCloseWithoutMessages(whitespaceTokenWs); + const duplicateTokenWs = new WebSocket( + `${parsedWsUrl.origin}${parsedWsUrl.pathname}?token=${encodeURIComponent( + parsedWsUrl.searchParams.get("token") ?? "", + )}&token=wrong-token`, + ); + await waitForUnauthorizedCloseWithoutMessages(duplicateTokenWs); + const ws = new WebSocket(wsUrl); await new Promise((resolve, reject) => { let sawHello = false; diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index 61ebc98efb..bb641fc536 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -1016,6 +1016,21 @@ describe("runtimeApiServer", () => { expect(whitespaceTokenClose.code).toBe(4001); expect(whitespaceTokenMessageCount).toBe(0); + const duplicateTokenUrl = `${authorizedUrl.origin}${authorizedUrl.pathname}?token=secret-token&token=wrong-token`; + const duplicateTokenClient = new WebSocket(duplicateTokenUrl); + let duplicateTokenMessageCount = 0; + duplicateTokenClient.on("message", () => { + duplicateTokenMessageCount += 1; + }); + const duplicateTokenClose = await withTimeout( + new Promise<{ code: number }>((resolve, reject) => { + duplicateTokenClient.once("close", (code) => resolve({ code })); + duplicateTokenClient.once("error", (error) => reject(error)); + }), + ); + expect(duplicateTokenClose.code).toBe(4001); + expect(duplicateTokenMessageCount).toBe(0); + const authorizedClient = await connectClient(server.wsUrl); const hello = await authorizedClient.nextMessage(); expect(hello.type).toBe("hello"); diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index 09a3232a73..d2cad5406d 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -495,7 +495,8 @@ export async function startRuntimeApiServer( try { const request = new URL(requestUrl, "ws://127.0.0.1"); - return request.searchParams.get("token") === authToken; + const tokens = request.searchParams.getAll("token"); + return tokens.length === 1 && tokens[0] === authToken; } catch { return false; }