mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
refactor(security): reuse shared scan path containment helper
This commit is contained in:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user