Validate CLI ports are within TCP range

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 00:42:22 +00:00
1 parent 6ab19a1970
commit e0d34cd373
2 files changed
+14 -2

No files matched your search

+12
View File
@@ -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",
+2 -2
View File
@@ -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;