{"record":{"id":"94a527dd69b79af9","repo":"copy/v86","slug":"unknown-port-for-localhost-s","errorCode":null,"errorMessage":"Unknown port for localhost: \"%s\"","messagePattern":"Unknown port for localhost: \"(.+?)\"","errorType":"console","errorClass":null,"httpStatus":400,"severity":"warning","filePath":"src/browser/fetch_network.js","lineNumber":193,"sourceCode":"            return;\n        }\n        if(header.key.toLowerCase() === \"host\") target.host = header.value;\n        else req_headers.append(header.key, header.value);\n    }\n\n    if(!this.net.cors_proxy && /^\\d+\\.external$/.test(target.hostname))\n    {\n        dbg_log(\"Request to localhost: \" + target.href, LOG_FETCH);\n        const localport = parseInt(target.hostname.split(\".\")[0], 10);\n        if(!isNaN(localport) && localport > 0 && localport < 65536)\n        {\n            target.protocol = \"http:\";\n            target.hostname = \"localhost\";\n            target.port = localport.toString(10);\n        }\n        else\n        {\n            console.warn('Unknown port for localhost: \"%s\"', target.href);\n            this.net.respond_text_and_close(this, 400, \"Bad Request\", `Unknown port for localhost: ${target.href}`);\n            return;\n        }\n    }\n\n    dbg_log(\"HTTP Dispatch: \" + target.href, LOG_FETCH);\n    this.name = target.href;\n\n    const opts = {\n        method: first_line[0],\n        headers: req_headers,\n    };\n\n    const fetch_url = this.net.cors_proxy\n        ? this.net.cors_proxy + encodeURIComponent(target.href)\n        : target.href;\n\n    if([\"put\", \"post\"].indexOf(opts.method.toLowerCase()) !== -1)","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/copy/v86/blob/180830d539dcc87db1a191febf6c914f516d102f/src/browser/fetch_network.js#L175-L211","documentation":"v86's fetch-based networking maps guest HTTP requests to the special hostname '<port>.external' back to real localhost:<port> on the host machine. In on_data_http (src/browser/fetch_network.js:193), when no CORS proxy is configured and the target hostname matches /^\\d+\\.external$/, the numeric label is parsed as a local port; if parsing fails, the number is 0, or it exceeds 65535, the library logs this warning and answers the guest's request with HTTP 400 Bad Request instead of proxying it.","triggerScenarios":"A program inside the emulated guest OS sends an HTTP request to a hostname like '99999.external', '0.external', 'abc.external', or any '*.external' name whose first label is not a valid port number (1-65535), while running without a cors_proxy configured.","commonSituations":"Guest software with hardcoded or misconfigured proxy/host settings producing malformed .external hostnames; tools that substitute the port into the wrong position of the hostname; port 0 from an unset environment variable or failed port lookup inside the guest; a non-numeric value leaking into the hostname slot.","solutions":["Fix the guest-side URL so the hostname is exactly '<port>.external' with port in 1-65535 (e.g. '8080.external'), not e.g. 'localhost.external' or '99999.external'","Check the guest application's proxy/server configuration or environment variable that supplies the port, ensuring it is numeric and in range","Verify no cors_proxy option was intended: if you route through a CORS proxy, .external mapping is skipped entirely, so set FetchNetworkAdapter's cors_proxy if you want normal proxying instead","Inspect the logged target.href in the warning to see the exact malformed hostname the guest sent and trace which guest process produced it"],"exampleFix":"// before (inside guest OS)\ncurl http://myserver.external/api\n// after\ncurl http://8080.external/api  # 8080 = port of the host service","handlingStrategy":"validation","validationCode":"// repeat: guard guest-side URLs before dispatch\nif(!/^\\d+\\.external$/.test(host)) throw new Error('guest host must be <port>.external');\nconst port = parseInt(host.split('.')[0], 10);\nif(!(port > 0 && port < 65536)) throw new Error('port out of range in ' + host);","typeGuard":null,"tryCatchPattern":"// The warning surfaces as HTTP 400 from the proxy — handle on the guest side\nconst resp = await guestFetch(url);\nif(resp.status === 400)\n{\n    const body = await resp.text();\n    if(body.startsWith('Unknown port for localhost'))\n        throw new Error('malformed .external hostname: ' + body);\n}","preventionTips":["Format host service URLs inside the guest as '<port>.external' strictly","Validate ports are 1-65535 before substituting into hostnames","Enable v86 debug logging (LOG_FETCH) in dev to trace guest HTTP dispatches","Do not mix cors_proxy and .external conventions — pick one mapping strategy"],"tags":["network","http","v86","guest-networking","localhost-proxy"],"backgroundTag":"invalid-hostname-or-port","analyzedSha":"180830d539dcc87db1a191febf6c914f516d102f","analyzedAt":"2026-08-31T22:39:37.599Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}