mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:48:28 +00:00
refactor: harden safe-bin trusted dir diagnostics
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
isInterpreterLikeSafeBin,
|
||||
listInterpreterLikeSafeBins,
|
||||
@@ -103,4 +105,34 @@ describe("exec safe-bin runtime policy", () => {
|
||||
expect(optedIn.trustedSafeBinDirs.has(path.resolve("/opt/homebrew/bin"))).toBe(true);
|
||||
expect(optedIn.trustedSafeBinDirs.has(path.resolve("/usr/local/bin"))).toBe(true);
|
||||
});
|
||||
|
||||
it("emits runtime warning when explicitly trusted dir is writable", async () => {
|
||||
if (process.platform === "win32") {
|
||||
return;
|
||||
}
|
||||
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-safe-bin-runtime-"));
|
||||
try {
|
||||
await fs.chmod(dir, 0o777);
|
||||
const onWarning = vi.fn();
|
||||
const policy = resolveExecSafeBinRuntimePolicy({
|
||||
global: {
|
||||
safeBinTrustedDirs: [dir],
|
||||
},
|
||||
onWarning,
|
||||
});
|
||||
|
||||
expect(policy.writableTrustedSafeBinDirs).toEqual([
|
||||
{
|
||||
dir: path.resolve(dir),
|
||||
groupWritable: true,
|
||||
worldWritable: true,
|
||||
},
|
||||
]);
|
||||
expect(onWarning).toHaveBeenCalledWith(expect.stringContaining(path.resolve(dir)));
|
||||
expect(onWarning).toHaveBeenCalledWith(expect.stringContaining("world-writable"));
|
||||
} finally {
|
||||
await fs.chmod(dir, 0o755).catch(() => undefined);
|
||||
await fs.rm(dir, { recursive: true, force: true }).catch(() => undefined);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user