mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:18:28 +00:00
refactor(media): harden localRoots bypass (#16739)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 89dce69f50
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Co-authored-by: steipete <58493+steipete@users.noreply.github.com>
Reviewed-by: @steipete
This commit is contained in:
committed by
GitHub
parent
b607c41a52
commit
683aa09b55
20
src/agents/workspace-dir.ts
Normal file
20
src/agents/workspace-dir.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import path from "node:path";
|
||||
import { resolveUserPath } from "../utils.js";
|
||||
|
||||
export function normalizeWorkspaceDir(workspaceDir?: string): string | null {
|
||||
const trimmed = workspaceDir?.trim();
|
||||
if (!trimmed) {
|
||||
return null;
|
||||
}
|
||||
const expanded = trimmed.startsWith("~") ? resolveUserPath(trimmed) : trimmed;
|
||||
const resolved = path.resolve(expanded);
|
||||
// Refuse filesystem roots as "workspace" (too broad; almost always a bug).
|
||||
if (resolved === path.parse(resolved).root) {
|
||||
return null;
|
||||
}
|
||||
return resolved;
|
||||
}
|
||||
|
||||
export function resolveWorkspaceRoot(workspaceDir?: string): string {
|
||||
return normalizeWorkspaceDir(workspaceDir) ?? process.cwd();
|
||||
}
|
||||
Reference in New Issue
Block a user