#3351·CowAgent

[Bug] read-only permission mode lets git writes through (\git tag v1\, \git branch topic\, \git remote add\, \git symbolic-ref\)

Author: aniruddhaadak80Created Sep 29, 2026Updated Sep 29, 2026

English is recommended so global developers can help. 推荐使用英文提交,谢谢 ❤️

  • I'm on the latest version and searched existing issues (incl. closed) — no duplicate.

Environment

Version: current master (commit 08f64f7) OS: any — agent/permission/policy.py is platform-independent Python: 3.11 / 3.13 (CI matrix) Install: any Mode: session permission mode read-only (agent_permission_mode: "read-only", or a per-session override)

What happened?

read-only mode lets several git writes through. The allowlist holds sub-commands that only read in their list form, and the guard only inspects flags — but creating a ref is done with a bare operand, so it is invisible to it.

The allowlist already handles this shape for stash / worktree / notes via _GIT_LIST_ONLY, but four members were missed:

Command What it does Verdict today
git tag v1.0.0 creates a tag allowed
git tag -a v1 -m msg creates an annotated tag allowed
git branch topic creates a branch allowed
git branch new old renames via create + delete allowed
git remote add origin <url> writes .git/config allowed
git remote set-url / remove / rm / rename / prune / set-head / update change or delete remotes allowed
git symbolic-ref HEAD refs/heads/main sets the ref (repoints HEAD) allowed

Only the flag-driven forms were caught, because _GIT_WRITE_FLAGS contains -d, -m, -f, --prune and friends:

$ git branch -d topic      # refused -- "-d" is a write flag
$ git branch topic         # allowed -- the name is a bare operand
$ git tag -d v1.0.0        # refused
$ git tag v1.0.0           # allowed

git symbolic-ref is a read in its one-operand form and a write in its two-operand form, and the guard does not look at operands at all.

Steps to reproduce

python
>>> from agent.permission.policy import READ_ONLY, check_tool_call
>>> check_tool_call(READ_ONLY, "bash", {"command": "git tag v1.0.0"}).allowed
True
>>> check_tool_call(READ_ONLY, "bash", {"command": "git branch topic"}).allowed
True
>>> check_tool_call(READ_ONLY, "bash", {"command": "git remote add origin https://example.com/x.git"}).allowed
True
>>> check_tool_call(READ_ONLY, "bash", {"command": "git symbolic-ref HEAD refs/heads/main"}).allowed
True

Expected: every one of these is refused, the same way git branch -d topic and git commit -m x already are. read-only is documented as "Look, don't touch", and the module's own stated policy is that read-only fails closed.

Actual: all allowed, so a read-only session can create branches and tags, rewrite .git/config, delete remote-tracking refs, and repoint HEAD.

Why the write-flag list cannot catch these

_GIT_WRITE_FLAGS is the right mechanism for git branch -d / git tag -f, where the destructive part is a flag. A create is git <sub> <name>: the name is a positional operand, so the guard has to inspect operands the way _GIT_LIST_ONLY already does for stash / worktree / notes.

The one wrinkle is that -a is ambiguous across the two sub-commands — it is --all for git branch (a listing) but --annotate for git tag (a create) — so listing flags have to be scoped per sub-command rather than shared.

Suggested fix

  • branch / tag: allow when there is no operand, or when a listing flag is present (-l, --list, --contains, --merged, ...); refuse otherwise.
  • remote: refuse when an operand names a write verb; git remote and git remote show / get-url stay allowed.
  • symbolic-ref: allow with one operand, refuse with two.

agent/permission/policy.py currently has no test coverage at all — nothing in tests/ imports it — so a regression test covering the git classifier's allow/deny boundary would be worth adding alongside the fix.

Logs

Not applicable — reproducible directly through check_tool_call as shown above; the decision is returned as Decision(allowed=True, reason='').