Skip to content

Commit 517491b

Browse files
authored
feat(node, deno, bun): validate server port range (#137)
1 parent 70917bf commit 517491b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/_utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ export function resolvePortAndHost(opts: ServerOptions): {
88
} {
99
const _port = opts.port ?? globalThis.process?.env.PORT ?? 3000;
1010
const port = typeof _port === "number" ? _port : Number.parseInt(_port, 10);
11+
if (port < 0 || port > 65_535) {
12+
throw new RangeError(`Port must be between 0 and 65535 (got "${port}").`);
13+
}
14+
1115
const hostname = opts.hostname ?? globalThis.process?.env.HOST;
1216
return { port, hostname };
1317
}

0 commit comments

Comments
 (0)