diff --git a/apps/t3/src/runtimeApiServer.test.ts b/apps/t3/src/runtimeApiServer.test.ts index bf1d23e211..6726ead552 100644 --- a/apps/t3/src/runtimeApiServer.test.ts +++ b/apps/t3/src/runtimeApiServer.test.ts @@ -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, diff --git a/apps/t3/src/runtimeApiServer.ts b/apps/t3/src/runtimeApiServer.ts index fd73bbbd2c..8f18763d5b 100644 --- a/apps/t3/src/runtimeApiServer.ts +++ b/apps/t3/src/runtimeApiServer.ts @@ -332,6 +332,9 @@ async function runTerminalCommand( export async function startRuntimeApiServer( options: RuntimeApiServerOptions, ): Promise { + 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 {