mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-07 22:41:25 +00:00
fix: harden ACP secret handling and exec preflight boundaries
This commit is contained in:
@@ -235,6 +235,58 @@ describe("security audit", () => {
|
||||
expect(hasFinding(res, "gateway.auth_no_rate_limit")).toBe(false);
|
||||
});
|
||||
|
||||
it("warns when exec host is explicitly sandbox while sandbox mode is off", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
exec: {
|
||||
host: "sandbox",
|
||||
},
|
||||
},
|
||||
agents: {
|
||||
defaults: {
|
||||
sandbox: {
|
||||
mode: "off",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const res = await audit(cfg);
|
||||
|
||||
expect(hasFinding(res, "tools.exec.host_sandbox_no_sandbox_defaults", "warn")).toBe(true);
|
||||
});
|
||||
|
||||
it("warns when an agent sets exec host=sandbox with sandbox mode off", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
exec: {
|
||||
host: "gateway",
|
||||
},
|
||||
},
|
||||
agents: {
|
||||
defaults: {
|
||||
sandbox: {
|
||||
mode: "off",
|
||||
},
|
||||
},
|
||||
list: [
|
||||
{
|
||||
id: "ops",
|
||||
tools: {
|
||||
exec: {
|
||||
host: "sandbox",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const res = await audit(cfg);
|
||||
|
||||
expect(hasFinding(res, "tools.exec.host_sandbox_no_sandbox_agents", "warn")).toBe(true);
|
||||
});
|
||||
|
||||
it("warns when loopback control UI lacks trusted proxies", async () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
gateway: {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import type { ExecFn } from "./windows-acl.js";
|
||||
import { resolveSandboxConfigForAgent } from "../agents/sandbox.js";
|
||||
import { resolveBrowserConfig, resolveProfile } from "../browser/config.js";
|
||||
import { resolveBrowserControlAuth } from "../browser/control-auth.js";
|
||||
import { listChannelPlugins } from "../channels/plugins/index.js";
|
||||
import { formatCliCommand } from "../cli/command-format.js";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
import { resolveConfigPath, resolveStateDir } from "../config/paths.js";
|
||||
import { resolveGatewayAuth } from "../gateway/auth.js";
|
||||
import { buildGatewayConnectionDetails } from "../gateway/call.js";
|
||||
@@ -36,7 +38,6 @@ import {
|
||||
inspectPathPermissions,
|
||||
} from "./audit-fs.js";
|
||||
import { DEFAULT_GATEWAY_HTTP_TOOL_DENY } from "./dangerous-tools.js";
|
||||
import type { ExecFn } from "./windows-acl.js";
|
||||
|
||||
export type SecurityAuditSeverity = "info" | "warn" | "critical";
|
||||
|
||||
@@ -566,6 +567,54 @@ function collectElevatedFindings(cfg: OpenClawConfig): SecurityAuditFinding[] {
|
||||
return findings;
|
||||
}
|
||||
|
||||
function collectExecRuntimeFindings(cfg: OpenClawConfig): SecurityAuditFinding[] {
|
||||
const findings: SecurityAuditFinding[] = [];
|
||||
const globalExecHost = cfg.tools?.exec?.host;
|
||||
const defaultSandboxMode = resolveSandboxConfigForAgent(cfg).mode;
|
||||
const defaultHostIsExplicitSandbox = globalExecHost === "sandbox";
|
||||
|
||||
if (defaultHostIsExplicitSandbox && defaultSandboxMode === "off") {
|
||||
findings.push({
|
||||
checkId: "tools.exec.host_sandbox_no_sandbox_defaults",
|
||||
severity: "warn",
|
||||
title: "Exec host is sandbox but sandbox mode is off",
|
||||
detail:
|
||||
"tools.exec.host is explicitly set to sandbox while agents.defaults.sandbox.mode=off. " +
|
||||
"In this mode, exec runs directly on the gateway host.",
|
||||
remediation:
|
||||
'Enable sandbox mode (`agents.defaults.sandbox.mode="non-main"` or `"all"`) or set tools.exec.host to "gateway" with approvals.',
|
||||
});
|
||||
}
|
||||
|
||||
const agents = Array.isArray(cfg.agents?.list) ? cfg.agents.list : [];
|
||||
const riskyAgents = agents
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry &&
|
||||
typeof entry === "object" &&
|
||||
typeof entry.id === "string" &&
|
||||
entry.tools?.exec?.host === "sandbox" &&
|
||||
resolveSandboxConfigForAgent(cfg, entry.id).mode === "off",
|
||||
)
|
||||
.map((entry) => entry.id)
|
||||
.slice(0, 5);
|
||||
|
||||
if (riskyAgents.length > 0) {
|
||||
findings.push({
|
||||
checkId: "tools.exec.host_sandbox_no_sandbox_agents",
|
||||
severity: "warn",
|
||||
title: "Agent exec host uses sandbox while sandbox mode is off",
|
||||
detail:
|
||||
`agents.list.*.tools.exec.host is set to sandbox for: ${riskyAgents.join(", ")}. ` +
|
||||
"With sandbox mode off, exec runs directly on the gateway host.",
|
||||
remediation:
|
||||
'Enable sandbox mode for these agents (`agents.list[].sandbox.mode`) or set their tools.exec.host to "gateway".',
|
||||
});
|
||||
}
|
||||
|
||||
return findings;
|
||||
}
|
||||
|
||||
async function maybeProbeGateway(params: {
|
||||
cfg: OpenClawConfig;
|
||||
timeoutMs: number;
|
||||
@@ -621,6 +670,7 @@ export async function runSecurityAudit(opts: SecurityAuditOptions): Promise<Secu
|
||||
findings.push(...collectBrowserControlFindings(cfg, env));
|
||||
findings.push(...collectLoggingFindings(cfg));
|
||||
findings.push(...collectElevatedFindings(cfg));
|
||||
findings.push(...collectExecRuntimeFindings(cfg));
|
||||
findings.push(...collectHooksHardeningFindings(cfg, env));
|
||||
findings.push(...collectGatewayHttpNoAuthFindings(cfg, env));
|
||||
findings.push(...collectGatewayHttpSessionKeyOverrideFindings(cfg));
|
||||
|
||||
Reference in New Issue
Block a user