Validate runtime server port range on startup

Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
Cursor AgentandTheo Browne committed 2026-02-10 01:11:29 +00:00
1 parent 5326137670
commit c0becc4431
2 files changed
+21

No files matched your search

+18
View File
@@ -158,6 +158,24 @@ describe("runtimeApiServer", () => {
}
});
it("rejects startup when runtime port is negative", async () => {
await expect(
startRuntimeApiServer({
port: -1,
launchCwd: process.cwd(),
}),
).rejects.toThrow("Invalid runtime port");
});
it("rejects startup when runtime port exceeds max range", async () => {
await expect(
startRuntimeApiServer({
port: 70_000,
launchCwd: process.cwd(),
}),
).rejects.toThrow("Invalid runtime port");
});
it("allows runtime server close to be called multiple times", async () => {
const server = await startRuntimeApiServer({
port: 0,
+3
View File
@@ -332,6 +332,9 @@ async function runTerminalCommand(
export async function startRuntimeApiServer(
options: RuntimeApiServerOptions,
): Promise<RuntimeApiServer> {
if (!Number.isInteger(options.port) || options.port < 0 || options.port > 65_535) {
throw new Error("Invalid runtime port: expected integer between 0 and 65535.");
}
const launchCwd = path.resolve(options.launchCwd);
let launchCwdStats: fs.Stats;
try {