From 0a1a0c0a27097d0f90ede6190892ced1fb7c0508 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Tue, 10 Feb 2026 01:30:53 +0000 Subject: [PATCH] Require decimal-only CLI port values Co-authored-by: Theo Browne --- apps/t3/src/cli.test.ts | 12 ++++++++++++ apps/t3/src/cli.ts | 6 +++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/apps/t3/src/cli.test.ts b/apps/t3/src/cli.test.ts index 13df12dbb2..09b43d5e65 100644 --- a/apps/t3/src/cli.test.ts +++ b/apps/t3/src/cli.test.ts @@ -224,6 +224,12 @@ describe("parseCliOptions", () => { ); }); + it("rejects non-decimal explicit port values", () => { + expect(() => parseCliOptions(["--backend-port", "0x10"], {}, "/workspace")).toThrow( + "Invalid value for --backend-port", + ); + }); + it("throws for out-of-range explicit port values", () => { expect(() => parseCliOptions(["--backend-port", "65536"], {}, "/workspace")).toThrow( "Invalid value for --backend-port", @@ -284,6 +290,12 @@ describe("parseCliOptions", () => { ); }); + it("rejects non-decimal environment port values", () => { + expect(() => parseCliOptions([], { T3_WEB_PORT: "1e3" }, "/workspace")).toThrow( + "Invalid value for T3_WEB_PORT", + ); + }); + it("throws for empty environment port values", () => { expect(() => parseCliOptions([], { T3_WEB_PORT: "" }, "/workspace")).toThrow( "Invalid value for T3_WEB_PORT", diff --git a/apps/t3/src/cli.ts b/apps/t3/src/cli.ts index 0328b75bac..3738b1b23e 100644 --- a/apps/t3/src/cli.ts +++ b/apps/t3/src/cli.ts @@ -13,7 +13,11 @@ const DEFAULT_WEB_PORT = 4318; const DEFAULT_CLI_VERSION = "0.1.0"; function parseExplicitPort(value: string, key: string): number { - const parsed = Number(value); + if (!/^\d+$/.test(value)) { + throw new Error(`Invalid value for ${key}: '${value}'. Expected an integer between 1 and 65535.`); + } + + const parsed = Number.parseInt(value, 10); if (!Number.isInteger(parsed) || parsed <= 0 || parsed > 65_535) { throw new Error(`Invalid value for ${key}: '${value}'. Expected an integer between 1 and 65535.`); }