security: require explicit address on all server listens

This commit is contained in:
Koushik Dutta
2024-07-25 18:33:16 -07:00
parent e9288bd4a1
commit 7d2df3af42
2 changed files with 4 additions and 4 deletions

View File

@@ -7,13 +7,13 @@ export class ListenZeroSingleClientTimeoutError extends Error {
}
}
export async function listenZero(server: net.Server, hostname?: string) {
export async function listenZero(server: net.Server, hostname: string) {
server.listen(0, hostname);
await once(server, 'listening');
return (server.address() as net.AddressInfo).port;
}
export async function listenZeroSingleClient(hostname?: string, options?: net.ServerOpts, listenTimeout = 30000) {
export async function listenZeroSingleClient(hostname: string, options?: net.ServerOpts, listenTimeout = 30000) {
const server = new net.Server(options);
const port = await listenZero(server, hostname);