{"record":{"id":"5cf4fa7855fe8eb1","repo":"projectdiscovery/nuclei","slug":"invalid-host-or-port-5cf4fa","errorCode":null,"errorMessage":"invalid host or port","messagePattern":"invalid host or port","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/js/libs/vnc/vnc.go","lineNumber":59,"sourceCode":"// Connect connects to VNC server using given password.\n// If connection and authentication is successful, it returns true.\n// If connection or authentication is unsuccessful, it returns false and error.\n// The connection is closed after the function returns.\n// @example\n// ```javascript\n// const vnc = require('nuclei/vnc');\n// const client = new vnc.VNCClient();\n// const connected = client.Connect('acme.com', 5900, 'password');\n// ```\nfunc (c *VNCClient) Connect(ctx context.Context, host string, port int, password string) (bool, error) {\n\texecutionId := ctx.Value(\"executionId\").(string)\n\treturn connect(ctx, executionId, host, port, password)\n}\n\n// connect attempts to authenticate with a VNC server using the given password\nfunc connect(ctx context.Context, executionId string, host string, port int, password string) (bool, error) {\n\tif host == \"\" || port <= 0 {\n\t\treturn false, fmt.Errorf(\"invalid host or port\")\n\t}\n\tif !protocolstate.IsHostAllowed(executionId, host) {\n\t\t// host is not valid according to network policy\n\t\treturn false, protocolstate.ErrHostDenied.Msgf(host)\n\t}\n\n\tdialer := protocolstate.GetDialersWithId(executionId)\n\tif dialer == nil {\n\t\treturn false, fmt.Errorf(\"dialers not initialized for %s\", executionId)\n\t}\n\n\tconn, err := dialer.Fastdialer.Dial(ctx, \"tcp\", net.JoinHostPort(host, strconv.Itoa(port)))\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tdefer func() {\n\t\t_ = conn.Close()\n\t}()","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/projectdiscovery/nuclei/blob/265b3a3dec374741614e342f813c10f8b38d2bb7/pkg/js/libs/vnc/vnc.go#L41-L77","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nconst ok = client.Connect(target, parsedPort, password); // parsedPort may be NaN\n\n// after\nconst port = Number.isInteger(parsedPort) && parsedPort > 0 ? parsedPort : 5900;\nif (target) {\n  const ok = client.Connect(target, port, password);\n}","handlingStrategy":"validation","validationCode":"function isValidVncTarget(host, port) { return typeof host === 'string' && host.length > 0 && Number.isInteger(port) && port > 0 && port < 65536; }\nif (isValidVncTarget(host, port)) { client.Connect(host, port, password); }","typeGuard":"function isValidVncTarget(host, port) { return typeof host === 'string' && host.length > 0 && Number.isInteger(port) && port > 0; }","tryCatchPattern":"try { client.Connect(host, port, password) } catch (e) { if (String(e) === 'invalid host or port') { /* fix inputs */ } else { throw e; } }","preventionTips":["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"],"tags":["vnc","javascript","nuclei","input-validation"],"backgroundTag":null,"analyzedSha":"265b3a3dec374741614e342f813c10f8b38d2bb7","analyzedAt":"2026-08-15T20:05:51.855Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}