From e0d34cd37384c4b11f2ec6500b3647f863055ba6 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 00:42:22 +0000 Subject: [PATCH] Validate CLI ports are within TCP range Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 12 ++++++++++++ apps/t3/src/cli.ts | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index b0aed0f6f8..3507612f82 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -180,6 +180,12 @@ describe("parseCliOptions", () => { ); }); + it("throws for out-of-range explicit port values", () => { + expect(() => parseCliOptions(["--backend-port", "65536"], {}, "/workspace")).toThrow( + "Invalid value for --backend-port", + ); + }); + it("throws for empty equals-style backend port values", () => { expect(() => parseCliOptions(["--backend-port="], {}, "/workspace")).toThrow( "Invalid value for --backend-port", @@ -210,6 +216,12 @@ describe("parseCliOptions", () => { ); }); + it("throws for out-of-range environment port values", () => { + expect(() => parseCliOptions([], { T3_WEB_PORT: "65536" }, "/workspace")).toThrow( + "Invalid value for T3_WEB_PORT", + ); + }); + it("throws for invalid backend environment port values", () => { expect(() => parseCliOptions([], { T3_BACKEND_PORT: "nope" }, "/workspace")).toThrow( "Invalid value for T3_BACKEND_PORT", diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index df50a85a2c..0602d540b4 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -14,8 +14,8 @@ const DEFAULT_CLI_VERSION = "0.1.0"; function parseExplicitPort(value: string, key: string): number { const parsed = Number(value); - if (!Number.isInteger(parsed) || parsed <= 0) { - throw new Error(`Invalid value for ${key}: '${value}'. Expected a positive integer.`); + if (!Number.isInteger(parsed) || parsed <= 0 || parsed > 65_535) { + throw new Error(`Invalid value for ${key}: '${value}'. Expected an integer between 1 and 65535.`); } return parsed;