mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 23:41:24 +00:00
fix(security): restrict default safe-bin trusted dirs
This commit is contained in:
@@ -89,4 +89,18 @@ describe("exec safe-bin runtime policy", () => {
|
||||
expect(policy.trustedSafeBinDirs.has(path.resolve(customDir))).toBe(true);
|
||||
expect(policy.trustedSafeBinDirs.has(path.resolve(agentDir))).toBe(true);
|
||||
});
|
||||
|
||||
it("does not trust package-manager bin dirs unless explicitly configured", () => {
|
||||
const defaultPolicy = resolveExecSafeBinRuntimePolicy({});
|
||||
expect(defaultPolicy.trustedSafeBinDirs.has(path.resolve("/opt/homebrew/bin"))).toBe(false);
|
||||
expect(defaultPolicy.trustedSafeBinDirs.has(path.resolve("/usr/local/bin"))).toBe(false);
|
||||
|
||||
const optedIn = resolveExecSafeBinRuntimePolicy({
|
||||
global: {
|
||||
safeBinTrustedDirs: ["/opt/homebrew/bin", "/usr/local/bin"],
|
||||
},
|
||||
});
|
||||
expect(optedIn.trustedSafeBinDirs.has(path.resolve("/opt/homebrew/bin"))).toBe(true);
|
||||
expect(optedIn.trustedSafeBinDirs.has(path.resolve("/usr/local/bin"))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,6 +8,15 @@ import {
|
||||
} from "./exec-safe-bin-trust.js";
|
||||
|
||||
describe("exec safe bin trust", () => {
|
||||
it("keeps default trusted dirs limited to immutable system paths", () => {
|
||||
const dirs = getTrustedSafeBinDirs({ refresh: true });
|
||||
|
||||
expect(dirs.has(path.resolve("/bin"))).toBe(true);
|
||||
expect(dirs.has(path.resolve("/usr/bin"))).toBe(true);
|
||||
expect(dirs.has(path.resolve("/usr/local/bin"))).toBe(false);
|
||||
expect(dirs.has(path.resolve("/opt/homebrew/bin"))).toBe(false);
|
||||
});
|
||||
|
||||
it("builds trusted dirs from defaults and explicit extra dirs", () => {
|
||||
const dirs = buildTrustedSafeBinDirs({
|
||||
baseDirs: ["/usr/bin"],
|
||||
|
||||
@@ -1,14 +1,8 @@
|
||||
import path from "node:path";
|
||||
|
||||
const DEFAULT_SAFE_BIN_TRUSTED_DIRS = [
|
||||
"/bin",
|
||||
"/usr/bin",
|
||||
"/usr/local/bin",
|
||||
"/opt/homebrew/bin",
|
||||
"/opt/local/bin",
|
||||
"/snap/bin",
|
||||
"/run/current-system/sw/bin",
|
||||
];
|
||||
// Keep defaults to OS-managed immutable bins only.
|
||||
// User/package-manager bins must be opted in via tools.exec.safeBinTrustedDirs.
|
||||
const DEFAULT_SAFE_BIN_TRUSTED_DIRS = ["/bin", "/usr/bin"];
|
||||
|
||||
type TrustedSafeBinDirsParams = {
|
||||
baseDirs?: readonly string[];
|
||||
|
||||
Reference in New Issue
Block a user