mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 01:40:23 +00:00
* fix(policy): preserve restrictive tool allowlists
Co-authored-by: David Silva <david.silva@gendigital.com>
* fix(policy): address review follow-ups
* fix(policy): restore additive alsoAllow semantics
* fix(policy): preserve optional tool opt-ins for allow-all configs
* fix(policy): narrow plugin-only allowlist warnings
* fix(policy): add changelog entry
* Revert "fix(policy): add changelog entry"
This reverts commit 4a996bf4ca.
* chore: add changelog for restrictive tool allowlists
---------
Co-authored-by: David Silva <david.silva@gendigital.com>
Co-authored-by: Devin Robison <drobison@nvidia.com>
39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import type { SandboxToolPolicy } from "./sandbox/types.js";
|
|
|
|
type SandboxToolPolicyConfig = {
|
|
allow?: string[];
|
|
alsoAllow?: string[];
|
|
deny?: string[];
|
|
};
|
|
|
|
function unionAllow(base?: string[], extra?: string[]): string[] | undefined {
|
|
if (!Array.isArray(extra) || extra.length === 0) {
|
|
return base;
|
|
}
|
|
if (!Array.isArray(base)) {
|
|
return Array.from(new Set(["*", ...extra]));
|
|
}
|
|
if (base.length === 0) {
|
|
return Array.from(new Set(["*", ...extra]));
|
|
}
|
|
return Array.from(new Set([...base, ...extra]));
|
|
}
|
|
|
|
export function pickSandboxToolPolicy(
|
|
config?: SandboxToolPolicyConfig,
|
|
): SandboxToolPolicy | undefined {
|
|
if (!config) {
|
|
return undefined;
|
|
}
|
|
const allow = Array.isArray(config.allow)
|
|
? unionAllow(config.allow, config.alsoAllow)
|
|
: Array.isArray(config.alsoAllow) && config.alsoAllow.length > 0
|
|
? unionAllow(undefined, config.alsoAllow)
|
|
: undefined;
|
|
const deny = Array.isArray(config.deny) ? config.deny : undefined;
|
|
if (!allow && !deny) {
|
|
return undefined;
|
|
}
|
|
return { allow, deny };
|
|
}
|