mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 12:44:59 +00:00
fix(sandbox): block @-prefixed workspace path bypass
This commit is contained in:
@@ -2,6 +2,7 @@ import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { createOpenClawCodingTools } from "./pi-tools.js";
|
||||
import { createHostSandboxFsBridge } from "./test-helpers/host-sandbox-fs-bridge.js";
|
||||
import { expectReadWriteEditTools, getTextContent } from "./test-helpers/pi-tools-fs-helpers.js";
|
||||
@@ -137,6 +138,19 @@ describe("workspace path resolution", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it("rejects @-prefixed absolute paths outside workspace when workspaceOnly is enabled", async () => {
|
||||
await withTempDir("openclaw-ws-", async (workspaceDir) => {
|
||||
const cfg: OpenClawConfig = { tools: { fs: { workspaceOnly: true } } };
|
||||
const tools = createOpenClawCodingTools({ workspaceDir, config: cfg });
|
||||
const { readTool } = expectReadWriteEditTools(tools);
|
||||
|
||||
const outsideAbsolute = path.resolve(path.parse(workspaceDir).root, "outside-openclaw.txt");
|
||||
await expect(
|
||||
readTool.execute("ws-read-at-prefix", { path: `@${outsideAbsolute}` }),
|
||||
).rejects.toThrow(/Path escapes sandbox root/i);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("sandboxed workspace paths", () => {
|
||||
|
||||
Reference in New Issue
Block a user