{"record":{"id":"06d468b39ec2e674","repo":"golang/go","slug":"file-url-specifies-non-local-host","errorCode":null,"errorMessage":"file URL specifies non-local host","messagePattern":"file URL specifies non-local host","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/web/url_other.go","lineNumber":18,"sourceCode":"// Copyright 2019 The Go Authors. All rights reserved.\n// Use of this source code is governed by a BSD-style\n// license that can be found in the LICENSE file.\n\n//go:build !windows\n\npackage web\n\nimport (\n\t\"errors\"\n\t\"path/filepath\"\n)\n\nfunc convertFileURLPath(host, path string) (string, error) {\n\tswitch host {\n\tcase \"\", \"localhost\":\n\tdefault:\n\t\treturn \"\", errors.New(\"file URL specifies non-local host\")\n\t}\n\treturn filepath.FromSlash(path), nil\n}\n","sourceCodeStart":1,"sourceCodeEnd":22,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/web/url_other.go#L1-L22","documentation":"Thrown by convertFileURLPath on non-Windows (Plan 9, Unix, etc.) when a file: URL carries a host component that is neither empty nor \"localhost\". On Unix a file URL is local-only — an authority field names a remote machine, and the go command does not fetch files over the network by host. RFC 8089 allows file://localhost/ but treats any other host as remote and unsupported here.","triggerScenarios":"Parsing \"file://fileserver/share/x\" or \"file://192.168.1.5/data/y\" on a Unix/Plan9 host. Manually setting u.Host to a machine name and then calling URLToFilePath. Reusing a Windows-style file://host/share URL on a Linux build machine without remapping.","commonSituations":"Cross-platform build scripts that hardcode file://UNC paths and are run on Linux/macOS CI. Misconfigured GOPATH/GOMODCACHE pointing at a network share via a file URL rather than a mounted path. Documentation copy-pasted from a Windows context into a Unix toolchain invocation.","solutions":["Mount the remote share locally and reference it by absolute filesystem path (e.g. /mnt/share/...) instead of a file://host URL.","Strip the host: if the file is actually local, use file:///path (three slashes → empty host) or file://localhost/path.","Route remote file acquisition through a real download step (http(s) or ssh) and pass the local cached path to the go command.","In cross-platform tooling, branch on runtime.GOOS and only emit host-bearing file URLs on windows."],"exampleFix":"// before (on Linux)\nu, _ := url.Parse(\"file://fileserver/builds/m.zip\")\np, err := web.URLToFilePath(u) // -> \"non-local host\"\n\n// after\nu, _ := url.Parse(\"file:///mnt/fileserver/builds/m.zip\")\np, err := web.URLToFilePath(u)","handlingStrategy":"validation","validationCode":"if u.Host != \"\" && u.Host != \"localhost\" {\n    return fmt.Errorf(\"file URL host %q is not local; mount the share and use a local path\", u.Host)\n}","typeGuard":"func isLocalFileURL(u *url.URL) bool {\n    return u.Scheme == \"file\" && (u.Host == \"\" || u.Host == \"localhost\")\n}","tryCatchPattern":null,"preventionTips":["On Unix, prefer mounted paths (e.g. /mnt/share) over file://host URLs.","Cross-platform tooling should branch on runtime.GOOS before emitting host-bearing file URLs.","Lint config files for file://<hostname> patterns when targeting Unix."],"tags":["go-toolchain","url","file-url","cross-platform","network"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}