Skip to content

Commit

Permalink
fix: if host is specified check whether it is valid
Browse files Browse the repository at this point in the history
  • Loading branch information
btea committed Aug 3, 2023
1 parent 8272ef5 commit f94960f
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import fs from 'node:fs'
import os from 'node:os'
import path from 'node:path'
import net from 'node:net'
import { exec } from 'node:child_process'
import { createHash } from 'node:crypto'
import { URL, URLSearchParams, fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -865,6 +866,12 @@ export async function resolveHostname(
// If passed --host in the CLI without arguments
host = undefined // undefined typically means 0.0.0.0 or :: (listen on all IPs)
} else {
// check if the host is valid
if (!net.isIP(optionsHost)) {
throw new Error(
`The address passed to --host is not a valid IP address: ${optionsHost}`,
)
}
host = optionsHost
}

Expand Down

0 comments on commit f94960f

Please sign in to comment.