fix(environment): refuse UNC pathname in file:// URI before fileURLToPath (#6272)

When a file:// URI contains leading slashes representing a UNC path (such as file:////remote.example.test/share/state.json), Node's fileURLToPath on Windows throws ERR_INVALID_FILE_URL_PATH because it expects a drive letter or Windows UNC format. This was caught and misreported as 'a file:// uri names a local absolute path' instead of the intended 'a file:// uri names a path on this host, not a network share'.

Testing UNC_PATH against url.pathname before calling fileURLToPath ensures that UNC paths are consistently recognized and refused as network shares across platforms.

Co-authored-by: ithis0623-png <ithis0623-png@users.noreply.github.com>
This commit is contained in:
ithis0623-pngandithis0623-png authored and GitHub committed 2026-10-22 17:50:25 +08:00
1 parent 2d91e2d578
commit aff5e23ecf
1 file changed
+1
+1
View File
@@ -299,6 +299,7 @@ const UNC_PATH = /^[\\/]{2}/u;
/** The local path a `file://` uri names; another host or a UNC path would open a network share, so neither is opened. */
const localFilePath = (url: URL): Result<string, RpcError> => {
if (url.host !== "" && url.host !== "localhost") return err(NETWORK_SHARE);
if (UNC_PATH.test(url.pathname)) return err(NETWORK_SHARE);
let path: string;
try {
path = fileURLToPath(url);