Skip to content

Commit bc37968

Browse files
author
clap [bot]
committed
fix: close git force-push bypass vectors in openclaw.yaml
Two bypass vectors caught in Opus code review: 1. 'git push origin main -f' (trailing -f with no space after) was not caught by the command_not_matches pattern 'git push *-f *' 2. Compound commands ('echo x && git push --force') bypass command_not_matches exclusions which only check the raw/full command Fix: add dedicated block-force-push policy using command_matches patterns prefixed with '*' to catch compound command segments. Add '-f' end-of-string pattern for trailing flag variant. Update tests: 39/39 pass, 45/45 e2e.
1 parent e465ea2 commit bc37968

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

policies/openclaw.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ policies:
265265
# Never allow force-push or branch deletion via git push
266266
- "git push *--force*"
267267
- "git push *-f *"
268+
- "git push *-f"
268269
- "git push *--delete*"
269270
- "git push *:*"
270271
message: "Safe exec command allowed"
@@ -296,6 +297,27 @@ policies:
296297
- "curl*http://localhost:9090/v1/*"
297298
message: "External curl/wget blocked — use web_fetch tool for external requests (policy-aware)"
298299

300+
# ── Block force-push ───────────────────────────────────────────────────
301+
# Dedicated deny for force-push variants so compound commands
302+
# (e.g. "echo x && git push --force") can't bypass allow-rule exclusions.
303+
- name: block-force-push
304+
description: "Block git force-push and branch deletion regardless of command context"
305+
match:
306+
tool: ["exec"]
307+
rules:
308+
- action: deny
309+
when:
310+
command_matches:
311+
- "git push *--force*"
312+
- "git push *-f *"
313+
- "git push *-f"
314+
- "git push *--delete*"
315+
- "*git push *--force*"
316+
- "*git push *-f *"
317+
- "*git push *-f"
318+
- "*git push *--delete*"
319+
message: "Git force-push and branch deletion blocked — run manually if intentional"
320+
299321
# ── Block destructive exec ─────────────────────────────────────────────
300322
- name: block-destructive-exec
301323
description: "Block destructive filesystem and system commands"

policies/openclaw_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,10 @@ func TestOpenClawPolicyDecisions(t *testing.T) {
6060
// ── exec: dangerous docker/kubectl surface for approval ────────
6161
{name: "ask: docker run privileged not in safe list", tool: "exec", command: "docker run --privileged ubuntu", expected: engine.ActionAsk},
6262
{name: "ask: kubectl delete namespace", tool: "exec", command: "kubectl delete namespace production", expected: engine.ActionAsk},
63-
{name: "ask: git push force", tool: "exec", command: "git push --force origin main", expected: engine.ActionAsk},
64-
{name: "ask: git push delete branch", tool: "exec", command: "git push origin --delete main", expected: engine.ActionAsk},
63+
{name: "deny: git push force", tool: "exec", command: "git push --force origin main", expected: engine.ActionDeny},
64+
{name: "deny: git push -f trailing", tool: "exec", command: "git push origin main -f", expected: engine.ActionDeny},
65+
{name: "deny: git push delete branch", tool: "exec", command: "git push origin --delete main", expected: engine.ActionDeny},
66+
{name: "deny: compound git force push", tool: "exec", command: "echo x && git push origin --force main", expected: engine.ActionDeny},
6567

6668
// ── read: credential files require approval ────────────────────
6769
{name: "ask: .env file", tool: "read", path: "/home/user/project/.env", expected: engine.ActionAsk},

0 commit comments

Comments
 (0)