mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:21:23 +00:00
refactor: dedupe core config and runtime helpers
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import path from "node:path";
|
||||
import { isPathInside } from "./path-guards.js";
|
||||
|
||||
export function resolveSafeBaseDir(rootDir: string): string {
|
||||
const resolved = path.resolve(rootDir);
|
||||
@@ -6,15 +7,5 @@ export function resolveSafeBaseDir(rootDir: string): string {
|
||||
}
|
||||
|
||||
export function isWithinDir(rootDir: string, targetPath: string): boolean {
|
||||
const resolvedRoot = path.resolve(rootDir);
|
||||
const resolvedTarget = path.resolve(targetPath);
|
||||
|
||||
// Windows paths are effectively case-insensitive; normalize to avoid false negatives.
|
||||
if (process.platform === "win32") {
|
||||
const relative = path.win32.relative(resolvedRoot.toLowerCase(), resolvedTarget.toLowerCase());
|
||||
return relative === "" || (!relative.startsWith("..") && !path.win32.isAbsolute(relative));
|
||||
}
|
||||
|
||||
const relative = path.relative(resolvedRoot, resolvedTarget);
|
||||
return relative === "" || (!relative.startsWith("..") && !path.isAbsolute(relative));
|
||||
return isPathInside(rootDir, targetPath);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user