refactor(tools): remove artificial analysis ceilings

This commit is contained in:
morluto
2026-09-29 16:29:23 +08:00
parent 36aeec9586
commit 2f08c7c932
202 changed files with 2314 additions and 3072 deletions
+4 -16
View File
@@ -1,21 +1,10 @@
import { realpath } from "node:fs/promises";
import { realpath, stat } from "node:fs/promises";
import { isAbsolute } from "node:path";
import { fileURLToPath } from "node:url";
import { isPathWithinRoot } from "../domain/localPath.js";
/** Canonicalize operator roots before evaluating any Electron file target. */
export const canonicalElectronRoots = async (
roots: readonly string[],
): Promise<readonly string[]> => {
const canonical: string[] = [];
for (const root of roots) canonical.push(await realpath(root));
return [...new Set(canonical)].sort();
};
/** Resolve one file URL and reject host, encoding, and symlink root escapes. */
/** Resolve one local file URL while rejecting remote hosts and encoded separators. */
export const authorizedElectronFile = async (
value: string,
roots: readonly string[],
): Promise<string | undefined> => {
if (/%(?:2f|5c)/iu.test(value)) return undefined;
let url: URL;
@@ -40,11 +29,10 @@ export const authorizedElectronFile = async (
if (!isAbsolute(path) || path.includes("\0")) return undefined;
let canonical: string;
try {
if (!(await stat(path)).isFile()) return undefined;
canonical = await realpath(path);
} catch {
return undefined;
}
return roots.some((root) => isPathWithinRoot(root, canonical))
? canonical
: undefined;
return canonical;
};