fix(setup): preserve native configuration path traversal

This commit is contained in:
morluto committed 2026-10-26 02:33:31 +08:00
1 parent d69a54d592
commit 14dd18a7fd
4 files changed
+84 -5

No files matched your search

+6 -3
View File
@@ -1,5 +1,6 @@
import { lstat, realpath } from "node:fs/promises";
import { basename, dirname, join, resolve } from "node:path";
import { basename, dirname, join } from "node:path";
import { absoluteCallerPath } from "../filesystem/callerPath.js";
interface ClientConfigPathStats {
readonly uid?: number;
@@ -70,9 +71,9 @@ const resolveOwnedConfigSymlink = async (
const canonicalRegularConfigPath = async (
requestedPath: string,
fileSystem: ClientConfigPathFileSystem,
): Promise<string> => {
): Promise<string | undefined> => {
if (fileSystem.realpath === undefined) return requestedPath;
let ancestor = resolve(requestedPath);
let ancestor = absoluteCallerPath(requestedPath);
const missing: string[] = [];
while (true) {
try {
@@ -80,6 +81,8 @@ const canonicalRegularConfigPath = async (
} catch (cause: unknown) {
if (!isAbsentPath(cause) || dirname(ancestor) === ancestor)
return requestedPath;
// An absent directory before '..' cannot establish the selected parent.
if (basename(ancestor) === "..") return undefined;
missing.unshift(basename(ancestor));
ancestor = dirname(ancestor);
}