openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
85 lines (84 loc) • 2.83 kB
JavaScript
import { c as resolveSafeBinProfiles, d as normalizeSafeBinName, i as normalizeTrustedSafeBinDirs, r as listWritableExplicitTrustedSafeBinDirs, s as normalizeSafeBinProfileFixtures, t as getTrustedSafeBinDirs } from "./exec-safe-bin-trust-DOHJJ8Cr.mjs";
import { i as resolveSafeBins } from "./exec-approvals-allowlist-f3-u9Y6p.mjs";
//#region src/infra/exec-safe-bin-runtime-policy.ts
const INTERPRETER_LIKE_SAFE_BINS = /* @__PURE__ */ new Set([
"ash",
"awk",
"bash",
"busybox",
"bun",
"cmd",
"cmd.exe",
"cscript",
"dash",
"deno",
"fish",
"gawk",
"gsed",
"ksh",
"lua",
"mawk",
"nawk",
"node",
"nodejs",
"perl",
"php",
"powershell",
"powershell.exe",
"pypy",
"pwsh",
"pwsh.exe",
"python",
"python2",
"python3",
"ruby",
"sed",
"sh",
"toybox",
"wscript",
"zsh"
]);
const VERSIONED_INTERPRETER_PATTERN = /^(?:python|ruby|perl|php|node)\d+(?:\.\d+)?$/;
/** Returns true for safeBins that can interpret scripts or execute broad embedded programs. */
function isInterpreterLikeSafeBin(e) {
const t = normalizeSafeBinName(e);
if (!t) return false;
if (INTERPRETER_LIKE_SAFE_BINS.has(t)) return true;
return VERSIONED_INTERPRETER_PATTERN.test(t);
}
function listInterpreterLikeSafeBins(e) {
return Array.from(e).map((e) => normalizeSafeBinName(e)).filter((e) => e.length > 0 && isInterpreterLikeSafeBin(e)).toSorted();
}
/** Merges global and local safe-bin profile fixtures, with local definitions winning. */
function resolveMergedSafeBinProfileFixtures(e) {
const t = normalizeSafeBinProfileFixtures(e.global?.safeBinProfiles);
const n = normalizeSafeBinProfileFixtures(e.local?.safeBinProfiles);
if (Object.keys(t).length === 0 && Object.keys(n).length === 0) return;
return {
...t,
...n
};
}
function resolveExecSafeBinRuntimePolicy(e) {
const t = resolveSafeBins(e.local?.safeBins ?? e.global?.safeBins);
const n = resolveSafeBinProfiles(resolveMergedSafeBinProfileFixtures(e));
const r = Array.from(t).filter((e) => !n[e]).toSorted();
const i = [...normalizeTrustedSafeBinDirs(e.global?.safeBinTrustedDirs), ...normalizeTrustedSafeBinDirs(e.local?.safeBinTrustedDirs)];
const a = getTrustedSafeBinDirs({
extraDirs: i,
safeBins: Array.from(t)
});
if (e.onWarning) for (const t of listWritableExplicitTrustedSafeBinDirs(i)) {
const n = t.worldWritable ? "world-writable" : "group-writable";
e.onWarning(`exec: safeBinTrustedDirs includes ${n} directory '${t.dir}'; remove trust or tighten permissions (for example chmod 755).`);
}
return {
safeBins: t,
safeBinProfiles: n,
trustedSafeBinDirs: a,
unprofiledSafeBins: r,
unprofiledInterpreterSafeBins: listInterpreterLikeSafeBins(r)
};
}
//#endregion
export { resolveMergedSafeBinProfileFixtures as i, listInterpreterLikeSafeBins as n, resolveExecSafeBinRuntimePolicy as r, isInterpreterLikeSafeBin as t };