refactor(security): reuse shared scan path containment helper

This commit is contained in:
Peter Steinberger
2026-02-19 00:20:15 +00:00
parent ae2e6896da
commit c8bdefd8b4

View File

@@ -1,6 +1,7 @@
import fs from "node:fs/promises";
import path from "node:path";
import { hasErrnoCode } from "../infra/errors.js";
import { isPathInside } from "./scan-paths.js";
// ---------------------------------------------------------------------------
// Types
@@ -252,13 +253,6 @@ function normalizeScanOptions(opts?: SkillScanOptions): Required<SkillScanOption
};
}
function isPathInside(basePath: string, candidatePath: string): boolean {
const base = path.resolve(basePath);
const candidate = path.resolve(candidatePath);
const rel = path.relative(base, candidate);
return rel === "" || (!rel.startsWith(`..${path.sep}`) && rel !== ".." && !path.isAbsolute(rel));
}
async function walkDirWithLimit(dirPath: string, maxFiles: number): Promise<string[]> {
const files: string[] = [];
const stack: string[] = [dirPath];