Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: if host is specified check whether it is valid #14013

Merged
merged 6 commits into from
Aug 22, 2023
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 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,16 @@ 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 (
optionsHost !== 'localhost' &&
!wildcardHosts.has(optionsHost) &&
!net.isIP(optionsHost)
btea marked this conversation as resolved.
Show resolved Hide resolved
) {
throw new Error(
`The address passed to --host is not a valid IP address: ${optionsHost}`,
)
}
host = optionsHost
}

Expand Down