From 04a6fd7fdeee32007c122c69bebe52ac113baa43 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Thu, 28 May 2026 15:44:16 -0400 Subject: [PATCH] fix: validate debug proxy connect ports --- src/proxy-capture/proxy-server.test.ts | 2 ++ src/proxy-capture/proxy-server.ts | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/proxy-capture/proxy-server.test.ts b/src/proxy-capture/proxy-server.test.ts index 3dea2f2e887..fc120f527f3 100644 --- a/src/proxy-capture/proxy-server.test.ts +++ b/src/proxy-capture/proxy-server.test.ts @@ -18,5 +18,7 @@ describe("parseConnectTarget", () => { it("rejects invalid CONNECT ports", () => { expect(() => parseConnectTarget("[::1]:99999")).toThrow("Invalid CONNECT target port"); + expect(() => parseConnectTarget("api.openai.com:1e3")).toThrow("Invalid CONNECT target port"); + expect(() => parseConnectTarget("api.openai.com:0x50")).toThrow("Invalid CONNECT target port"); }); }); diff --git a/src/proxy-capture/proxy-server.ts b/src/proxy-capture/proxy-server.ts index b62b1f88673..8542e291acc 100644 --- a/src/proxy-capture/proxy-server.ts +++ b/src/proxy-capture/proxy-server.ts @@ -64,6 +64,9 @@ export function parseConnectTarget(rawTarget: string | undefined): { } const hostname = trimmed.slice(0, lastColon).trim() || "127.0.0.1"; const portText = trimmed.slice(lastColon + 1).trim(); + if (!/^\d+$/.test(portText)) { + throw new Error("Invalid CONNECT target port"); + } const port = Number(portText); if (!Number.isInteger(port) || port < 1 || port > 65535) { throw new Error("Invalid CONNECT target port");