projectdiscovery/nuclei · error
invalid host or port
Error message
invalid host or port
What it means
Thrown by the nuclei vnc JavaScript library's connect() when host is an empty string or port is <= 0 — the pre-flight check before any network policy lookup or dialing happens. It exists so callers fail fast on obviously invalid arguments instead of producing confusing dial errors from net.JoinHostPort or the fastdialer.
Source
Thrown at pkg/js/libs/vnc/vnc.go:59
// Connect connects to VNC server using given password.
// If connection and authentication is successful, it returns true.
// If connection or authentication is unsuccessful, it returns false and error.
// The connection is closed after the function returns.
// @example
// ```javascript
// const vnc = require('nuclei/vnc');
// const client = new vnc.VNCClient();
// const connected = client.Connect('acme.com', 5900, 'password');
// ```
func (c *VNCClient) Connect(ctx context.Context, host string, port int, password string) (bool, error) {
executionId := ctx.Value("executionId").(string)
return connect(ctx, executionId, host, port, password)
}
// connect attempts to authenticate with a VNC server using the given password
func connect(ctx context.Context, executionId string, host string, port int, password string) (bool, error) {
if host == "" || port <= 0 {
return false, fmt.Errorf("invalid host or port")
}
if !protocolstate.IsHostAllowed(executionId, host) {
// host is not valid according to network policy
return false, protocolstate.ErrHostDenied.Msgf(host)
}
dialer := protocolstate.GetDialersWithId(executionId)
if dialer == nil {
return false, fmt.Errorf("dialers not initialized for %s", executionId)
}
conn, err := dialer.Fastdialer.Dial(ctx, "tcp", net.JoinHostPort(host, strconv.Itoa(port)))
if err != nil {
return false, err
}
defer func() {
_ = conn.Close()
}()View on GitHub (pinned to 265b3a3dec)
Solutions
- Validate host is a non-empty string and port is a positive integer before calling Connect
- Default the port to 5900 when your template leaves it dynamic
- Log/skip the target when the connection parameters cannot be resolved
Example fix
// before
const ok = client.Connect(target, parsedPort, password); // parsedPort may be NaN
// after
const port = Number.isInteger(parsedPort) && parsedPort > 0 ? parsedPort : 5900;
if (target) {
const ok = client.Connect(target, port, password);
} Defensive patterns
Strategy: validation
Validate before calling
function isValidVncTarget(host, port) { return typeof host === 'string' && host.length > 0 && Number.isInteger(port) && port > 0 && port < 65536; }
if (isValidVncTarget(host, port)) { client.Connect(host, port, password); } Type guard
function isValidVncTarget(host, port) { return typeof host === 'string' && host.length > 0 && Number.isInteger(port) && port > 0; } Try / catch
try { client.Connect(host, port, password) } catch (e) { if (String(e) === 'invalid host or port') { /* fix inputs */ } else { throw e; } } Prevention
- Coerce and validate port with parseInt/Number.isInteger before use
- Default the port (5900) when templates leave it dynamic
- Skip targets whose host variable failed to populate
When it happens
Trigger: Calling client.Connect('', 5900, 'pass') or client.Connect('host', 0, 'pass'); passing a port parsed from a string with parseInt that returned NaN/0; host variables left empty because an extractor or template variable did not populate.
Common situations: Templates building host/port from dynamic variables that can be empty; JS type coercion surprises (port passed as string or undefined arithmetic); reused boilerplate where the port constant was removed.
Related errors
- file path cannot be empty
- invalid number of recipients: required 1, got %d
- parse target: %w
- invalid host or port
- invalid host or port
AI-assisted analysis of projectdiscovery/nuclei@265b3a3dec (2026-08-15).
Data as JSON: /api/errors/5cf4fa7855fe8eb1.
Report an issue: GitHub.