fix(web): disallow workspace-* roots without explicit localRoots

This commit is contained in:
Peter Steinberger
2026-02-15 19:40:07 +00:00
parent 59c0b2bb37
commit 75f33e92bf

View File

@@ -52,6 +52,24 @@ async function assertLocalMediaAllowed(
} catch {
resolved = path.resolve(mediaPath);
}
// Hardening: the default allowlist includes `os.tmpdir()`, and tests/CI may
// override the state dir into tmp. Avoid accidentally allowing per-agent
// `workspace-*` state roots via the tmpdir prefix match; require explicit
// localRoots for those.
if (localRoots === undefined) {
const workspaceRoot = roots.find((root) => path.basename(root) === "workspace");
if (workspaceRoot) {
const stateDir = path.dirname(workspaceRoot);
const rel = path.relative(stateDir, resolved);
if (rel && !rel.startsWith("..") && !path.isAbsolute(rel)) {
const firstSegment = rel.split(path.sep)[0] ?? "";
if (firstSegment.startsWith("workspace-")) {
throw new Error(`Local media path is not under an allowed directory: ${mediaPath}`);
}
}
}
}
for (const root of roots) {
let resolvedRoot: string;
try {