Skip to content

agent-guard: git guards are bypassed by an ordinary global flag before the subcommand #1329

Closed

Description

@AmirF194

What's broken

guard_commit_trailer and guard_empty_rebase (the two bundled git guards) check seg.argv[:2] == ["git", "commit"] / ["git", "push"]. Any ordinary global git option before the subcommand shifts it to argv[2], so the check is never true and the guard denies nothing. The dispatcher's own command_kinds pre-filter has the same shape (seg.argv[1]), and the bundled example contributed guard guards.d/no_verify_commit.py copies the same argv[:2] check, so all three fail the same way.

Which layer

tools/agent-guard/src/agent_guard/__init__.py: guard_commit_trailer (~line 354), guard_empty_rebase (~line 369), command_kinds (~line 542). tools/agent-guard/src/agent_guard/guards.d/no_verify_commit.py: guard (~line 42).

How to reproduce

from agent_guard import dispatch

dispatch('git commit -m "x\n\nCo-Authored-By: a"')          # denied
dispatch('git -C /tmp commit -m "x\n\nCo-Authored-By: a"')  # None -- bypassed
dispatch('git -c core.editor=true commit -m "x\n\nCo-Authored-By: a"')  # None
dispatch('git --no-pager commit -m "x\n\nCo-Authored-By: a"')           # None

Same shape for guard_empty_rebase (git -C <dir> push --force ...) and for the bundled no-verify guard (git -C <dir> commit --no-verify, which also silently skips guard() entirely because command_kinds never adds the git:commit tag the guard's TRIGGERS filters on).

Expected vs actual

Expected: all three deny regardless of a global flag before the subcommand, the same way gh_subcommand already walks past gh's global flags (gh --repo o/r pr create is still caught).

Actual: git -C <dir> commit ..., git -c <k>=<v> commit ..., and git --no-pager commit ... bypass guard_commit_trailer; the equivalent push forms bypass guard_empty_rebase; and git -C <dir> commit --no-verify bypasses the bundled no-verify guard both at the TRIGGERS pre-filter and inside guard() itself. git -C <dir> in particular is an everyday pattern, not a crafted input: it is how this framework's own multi-clone tooling invokes git from outside the target checkout.

Surface area (optional)

Any future skill-contributed guard that declares TRIGGERS = ["git:commit"] / ["git:push"] inherits the command_kinds bug at the dispatch pre-filter, before its own guard(ctx) ever runs.

Activity

  1. added a commit that references this issue on Sep 22, 2026
    ddfef27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions