Skip to content

Commit e26fc17

Browse files
authored
fix(security): report canonical agents.entries paths in audit and diagnostics (#113603)
Audit findings, dangerous-flag labels, exec-approval provenance, filesystem policy drift, and the skill-workshop tool diagnostic printed agents.list.* paths users cannot paste into openclaw.json: dotted agents.list.<id> is valid in no shape, and index-keyed agents.list.<n> only names the internal validation projection. All display surfaces now emit agents.entries.<id>; the summary agent-id extractor regex follows the new labels. Roster-aware builders keep an indexed fallback only for id-less malformed legacy rows, and validation/doctor/legacy-migration paths intentionally keep the legacy form because they point into the user's actual file. Follow-up deferred from #113160.
1 parent faaab9b commit e26fc17

19 files changed

Lines changed: 197 additions & 92 deletions

‎src/infra/exec-approvals-effective.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ export function collectExecPolicyScopeSnapshots(params: {
333333
approvals: params.approvals,
334334
scopeExecConfig: agentConfig?.tools?.exec,
335335
globalExecConfig,
336-
configPath: `agents.list.${agentId}.tools.exec`,
336+
configPath: `agents.entries.${agentId}.tools.exec`,
337337
hostPath: params.hostPath,
338338
hostDefaults: params.hostDefaults,
339339
hostDefaultSource: params.hostDefaultSource,

‎src/infra/exec-approvals-policy.test.ts‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ describe("exec approvals policy helpers", () => {
829829
},
830830
},
831831
agents: {
832-
list: [{ id: "runner", default: true }],
832+
entries: { runner: { default: true } },
833833
},
834834
} satisfies OpenClawConfig,
835835
approvals: {
@@ -869,7 +869,7 @@ describe("exec approvals policy helpers", () => {
869869
ask: "off",
870870
},
871871
},
872-
agents: { list: [{ id: DEFAULT_AGENT_ID, default: true }] },
872+
agents: { entries: { [DEFAULT_AGENT_ID]: { default: true } } },
873873
} satisfies OpenClawConfig,
874874
approvals: {
875875
version: 1,
@@ -903,17 +903,16 @@ describe("exec approvals policy helpers", () => {
903903
},
904904
},
905905
agents: {
906-
list: [
907-
{
908-
id: DEFAULT_AGENT_ID,
906+
entries: {
907+
[DEFAULT_AGENT_ID]: {
909908
default: true,
910909
tools: {
911910
exec: {
912911
ask: "always",
913912
},
914913
},
915914
},
916-
],
915+
},
917916
},
918917
} satisfies OpenClawConfig,
919918
approvals: {
@@ -924,7 +923,7 @@ describe("exec approvals policy helpers", () => {
924923
expect(snapshots.map((snapshot) => snapshot.scopeLabel)).toEqual(["tools.exec", "agent:main"]);
925924
expectFields(snapshots[1]?.ask, {
926925
requested: "always",
927-
requestedSource: "agents.list.main.tools.exec.ask",
926+
requestedSource: "agents.entries.main.tools.exec.ask",
928927
});
929928
});
930929

@@ -947,7 +946,7 @@ describe("exec approvals policy helpers", () => {
947946
]);
948947
expectFields(snapshots[1]?.ask, {
949948
requested: "always",
950-
requestedSource: "agents.list.runner.tools.exec.ask",
949+
requestedSource: "agents.entries.runner.tools.exec.ask",
951950
});
952951
});
953952
});

‎src/security/audit-config-basics.test.ts‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,17 @@ describe("security audit config basics", () => {
4949
profile: "minimal",
5050
},
5151
agents: {
52-
list: [
53-
{
54-
id: "owner",
52+
entries: {
53+
owner: {
5554
tools: { profile: "full" },
5655
},
57-
],
56+
},
5857
},
5958
});
6059

61-
expect(
62-
findings.some(
63-
(finding) =>
64-
finding.checkId === "tools.profile_minimal_overridden" && finding.severity === "warn",
65-
),
66-
).toBe(true);
60+
const finding = findings.find((entry) => entry.checkId === "tools.profile_minimal_overridden");
61+
expect(finding?.severity).toBe("warn");
62+
expect(finding?.detail).toContain("agents.entries.owner=full");
6763
});
6864

6965
it("flags tools.elevated allowFrom wildcard as critical", async () => {

‎src/security/audit-exec-safe-bins.test.ts‎

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,16 @@ describe("security audit exec safe-bin findings", () => {
3636
},
3737
},
3838
agents: {
39-
list: [
40-
{
41-
id: "ops",
39+
entries: {
40+
ops: {
4241
default: true,
4342
tools: {
4443
exec: {
4544
safeBins: ["node"],
4645
},
4746
},
4847
},
49-
],
48+
},
5049
},
5150
} satisfies OpenClawConfig,
5251
expected: true,
@@ -65,9 +64,8 @@ describe("security audit exec safe-bin findings", () => {
6564
},
6665
},
6766
agents: {
68-
list: [
69-
{
70-
id: "ops",
67+
entries: {
68+
ops: {
7169
default: true,
7270
tools: {
7371
exec: {
@@ -80,7 +78,7 @@ describe("security audit exec safe-bin findings", () => {
8078
},
8179
},
8280
},
83-
],
81+
},
8482
},
8583
} satisfies OpenClawConfig,
8684
expected: false,
@@ -101,7 +99,7 @@ describe("security audit exec safe-bin findings", () => {
10199
{
102100
name: "jq configured globally",
103101
cfg: {
104-
agents: { list: [{ id: "main", default: true }] },
102+
agents: { entries: { main: { default: true } } },
105103
tools: {
106104
exec: {
107105
safeBins: ["jq"],
@@ -113,7 +111,7 @@ describe("security audit exec safe-bin findings", () => {
113111
{
114112
name: "jq not configured",
115113
cfg: {
116-
agents: { list: [{ id: "main", default: true }] },
114+
agents: { entries: { main: { default: true } } },
117115
tools: {
118116
exec: {
119117
safeBins: ["cut"],
@@ -143,33 +141,32 @@ describe("security audit exec safe-bin findings", () => {
143141
},
144142
},
145143
agents: {
146-
list: [
147-
{
148-
id: "ops",
144+
entries: {
145+
ops: {
149146
default: true,
150147
tools: {
151148
exec: {
152149
safeBinTrustedDirs: ["./relative-bin-dir"],
153150
},
154151
},
155152
},
156-
],
153+
},
157154
},
158155
} satisfies OpenClawConfig);
159156

160157
const riskyFinding = requireFinding("tools.exec.safe_bin_trusted_dirs_risky", findings);
161158
expect(riskyFinding.severity).toBe("warn");
162159
expect(riskyFinding.detail).toContain(riskyGlobalTrustedDirs[0]);
163160
expect(riskyFinding.detail).toContain(riskyGlobalTrustedDirs[1]);
164-
expect(riskyFinding.detail).toContain("agents.list.ops.tools.exec");
161+
expect(riskyFinding.detail).toContain("agents.entries.ops.tools.exec");
165162
});
166163

167164
it("ignores non-risky absolute dirs", async () => {
168165
expect(
169166
hasFinding(
170167
"tools.exec.safe_bin_trusted_dirs_risky",
171168
await collectSecurityAuditFindings({
172-
agents: { list: [{ id: "main", default: true }] },
169+
agents: { entries: { main: { default: true } } },
173170
tools: {
174171
exec: {
175172
safeBinTrustedDirs: ["/usr/libexec"],

‎src/security/audit-exec-surface.test.ts‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe("security audit exec surface findings", () => {
108108
"warn",
109109
await collectSecurityAuditFindings({
110110
agents: {
111-
list: [{ id: "ops" }],
111+
entries: { ops: {} },
112112
},
113113
} satisfies OpenClawConfig),
114114
),
@@ -253,6 +253,25 @@ describe("security audit exec surface findings", () => {
253253
expect(finding.remediation).toContain("deny exec and process");
254254
});
255255

256+
it("reports canonical agent paths for filesystem policy drift", async () => {
257+
const findings = await collectSecurityAuditFindings({
258+
agents: {
259+
entries: {
260+
ops: {
261+
default: true,
262+
tools: {
263+
allow: ["read", "exec", "process"],
264+
deny: ["write", "edit", "apply_patch"],
265+
},
266+
},
267+
},
268+
},
269+
} satisfies OpenClawConfig);
270+
271+
const finding = requireFinding("tools.exec.fs_tools_disabled_but_exec_enabled", findings);
272+
expect(finding.detail).toContain("agents.entries.ops.tools");
273+
});
274+
256275
it("does not warn when sandbox filesystem policy constrains exec", async () => {
257276
const findings = await collectSecurityAuditFindings({
258277
agents: {

‎src/security/audit-extra.summary.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ function summarizeGroupPolicy(cfg: OpenClawConfig): {
5959
}
6060

6161
function extractAgentIdFromSource(source: string): string | null {
62-
const match = source.match(/^agents\.list\.([^.]*)\./);
62+
const match = source.match(/^agents\.entries\.([^.]*)\./);
6363
return match?.[1] ?? null;
6464
}
6565

‎src/security/audit-extra.sync.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,7 @@ function listAuditAgentToolContexts(cfg: OpenClawConfig): AuditAgentToolContext[
487487
continue;
488488
}
489489
contexts.push({
490-
label: `agents.list.${agent.id}`,
490+
label: `agents.entries.${agent.id}`,
491491
agentId: agent.id,
492492
tools: agent.tools,
493493
});
@@ -824,7 +824,7 @@ export function collectSandboxDockerNoopFindings(cfg: OpenClawConfig): SecurityA
824824
continue;
825825
}
826826
if (resolveSandboxConfigForAgent(cfg, entry.id).mode === "off") {
827-
configuredPaths.push(`agents.list.${entry.id}.sandbox.docker`);
827+
configuredPaths.push(`agents.entries.${entry.id}.sandbox.docker`);
828828
}
829829
}
830830

@@ -865,7 +865,7 @@ export function collectSandboxDangerousConfigFindings(cfg: OpenClawConfig): Secu
865865
const agentDocker = entry.sandbox?.docker;
866866
if (agentDocker && typeof agentDocker === "object") {
867867
configs.push({
868-
source: `agents.list.${entry.id}.sandbox.docker`,
868+
source: `agents.entries.${entry.id}.sandbox.docker`,
869869
docker: agentDocker as Record<string, unknown>,
870870
});
871871
}
@@ -1083,7 +1083,7 @@ export function collectMinimalProfileOverrideFindings(cfg: OpenClawConfig): Secu
10831083
title: "Global tools.profile=minimal is overridden by agent profiles",
10841084
detail:
10851085
"Global minimal profile is set, but these agent profiles take precedence:\n" +
1086-
overrides.map((entry) => `- agents.list.${entry}`).join("\n"),
1086+
overrides.map((entry) => `- agents.entries.${entry}`).join("\n"),
10871087
remediation:
10881088
'Set those agents to `tools.profile="minimal"` (or remove the agent override) if you want minimal tools enforced globally.',
10891089
});

‎src/security/audit-model-refs.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ export function collectAuditModelRefs(cfg: OpenClawConfig): AuditModelRef[] {
8888
typeof (agent as { id?: unknown }).id === "string" ? (agent as { id: string }).id : "";
8989
const model = (agent as { model?: unknown }).model;
9090
if (typeof model === "string") {
91-
add(model, `agents.list.${id}.model`);
91+
add(model, `agents.entries.${id}.model`);
9292
} else if (model && typeof model === "object") {
93-
add((model as { primary?: unknown }).primary, `agents.list.${id}.model.primary`);
93+
add((model as { primary?: unknown }).primary, `agents.entries.${id}.model.primary`);
9494
const fallbacks = (model as { fallbacks?: unknown }).fallbacks;
9595
if (Array.isArray(fallbacks)) {
9696
for (const fallback of fallbacks) {
97-
add(fallback, `agents.list.${id}.model.fallbacks`);
97+
add(fallback, `agents.entries.${id}.model.fallbacks`);
9898
}
9999
}
100100
}

‎src/security/audit-plugins-trust.test.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,19 @@ describe("security audit extension tool reachability findings", () => {
544544
).toBe(true);
545545
},
546546
},
547+
{
548+
name: "reports canonical agent paths for permissive tool policy",
549+
cfg: {
550+
plugins: { allow: ["some-plugin"] },
551+
agents: { entries: { ops: { tools: { profile: "full" } } } },
552+
} satisfies OpenClawConfig,
553+
assert: (findings: Awaited<ReturnType<typeof runSharedExtensionsAudit>>) => {
554+
const finding = findings.find(
555+
(entry) => entry.checkId === "plugins.tools_reachable_permissive_policy",
556+
);
557+
expect(finding?.detail).toContain("- agents.entries.ops");
558+
},
559+
},
547560
{
548561
name: "does not flag plugin tool reachability when profile is restrictive",
549562
cfg: {

‎src/security/audit-plugins-trust.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ export async function collectPluginsTrustFindings(params: {
363363
continue;
364364
}
365365
contexts.push({
366-
label: `agents.list.${entry.id}`,
366+
label: `agents.entries.${entry.id}`,
367367
agentId: entry.id,
368368
tools: entry.tools,
369369
});

0 commit comments

Comments
 (0)