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.`); }