Skip to content

Commit 8da9d8c

Browse files
HCLclaude
authored andcommitted
fix(tool-policy): deny write no longer silently hides apply_patch (#76749)
Removing deny coupling between write and apply_patch in makeToolPolicyMatcher. Previously deny: ["write"] would also block apply_patch, contradicting the documented allow coupling (apply_patch inherits write allow). Allow inheritance is preserved; deny must be stated explicitly. Adds regression tests verifying: - deny: ["write"] leaves apply_patch accessible - deny: ["apply_patch"] still denies directly - allow: ["write"] still grants apply_patch - deny: ["write", "apply_patch"] still denies when both explicit Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
1 parent 9185e50 commit 8da9d8c

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

‎src/agents/tool-policy-match.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ function makeToolPolicyMatcher(policy: SandboxToolPolicy) {
1616
if (matchesAnyGlobPattern(normalized, deny)) {
1717
return false;
1818
}
19-
if (normalized === "apply_patch" && matchesAnyGlobPattern("write", deny)) {
20-
return false;
21-
}
2219
if (allow.length === 0) {
2320
return true;
2421
}

‎src/agents/tool-policy.test.ts‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { OpenClawConfig } from "../config/config.js";
33
import { DEFAULT_GATEWAY_HTTP_TOOL_DENY } from "../security/dangerous-tools.js";
44
import { isToolAllowed, resolveSandboxToolPolicyForAgent } from "./sandbox/tool-policy.js";
55
import type { SandboxToolPolicy } from "./sandbox/types.js";
6+
import { isToolAllowedByPolicyName } from "./tool-policy-match.js";
67
import { TOOL_POLICY_CONFORMANCE } from "./tool-policy.conformance.js";
78
import {
89
applyOwnerOnlyToolPolicy,
@@ -264,3 +265,23 @@ describe("resolveSandboxToolPolicyForAgent", () => {
264265
expect(resolved.deny).toEqual(["image"]);
265266
});
266267
});
268+
269+
describe("isToolAllowedByPolicyName — apply_patch / write deny decoupling (#76749)", () => {
270+
it("does not deny apply_patch when write is denied", () => {
271+
expect(isToolAllowedByPolicyName("apply_patch", { deny: ["write"] })).toBe(true);
272+
});
273+
274+
it("still denies apply_patch when apply_patch is explicitly denied", () => {
275+
expect(isToolAllowedByPolicyName("apply_patch", { deny: ["apply_patch"] })).toBe(false);
276+
});
277+
278+
it("still allows apply_patch via write in the allow list", () => {
279+
expect(isToolAllowedByPolicyName("apply_patch", { allow: ["write"], deny: [] })).toBe(true);
280+
});
281+
282+
it("denies apply_patch when both write and apply_patch are denied", () => {
283+
expect(isToolAllowedByPolicyName("apply_patch", { deny: ["write", "apply_patch"] })).toBe(
284+
false,
285+
);
286+
});
287+
});

0 commit comments

Comments
 (0)