AI 編碼智能體的「推送前先詢問」只是建議:防護措施未經測試,執行漏洞無人檢驗
"Ask before it pushes" is a suggestion, not a guardrail — the enforcement gap nobody tests
一項針對 AI 編碼智能體的實驗發現,設定「git push/gh pr create 前先詢問」的權限規則未有觸發,智能體直接推送並建立 PR。文章建議以智能體無法影響的確定性 hooks 執行防護,並測試規則能否攔截推送及繞過嘗試。agent-guard-hooks 售價 $19,提供 shell 層級 hooks 及自我測試模式。
A dev.to post this week ran a clean experiment: give an AI coding agent permission rules ("ask before git push / gh pr create"), then watch whether they fire. First run: the agent pushed and opened a PR without asking once. The rules were configured enforcement: strict and simply never triggered.
That's the failure mode I see everywhere: guardrails are configured, not enforced.
Why "ask before X" rules silently fail
-
Matching is brittle.
git push *doesn't matchgit -c credential.helper=... push. Agents route around literal patterns constantly — pipes, wrappers, aliases, env-prefixed commands. - The config is a suggestion to the harness, not a boundary. If enforcement lives in the same process the agent influences, it's theater.
- Nobody tests the guardrail. We test the code the agent writes; almost nobody writes a test that proves the agent can't push.
What actually holds
Move the boundary outside the agent's reach:
- Deterministic hooks, not prompt rules. A pre-tool-call hook that inspects the actual command (post-shell-expansion, not the raw string) and hard-fails on push/PR/network egress.
- Test the guardrail like code. Red-team it: ask the agent to push, confirm the hook fires, confirm the bypass attempts fire too.
- Receipt everything. When a guardrail does fire, you want a record of what was attempted — that's your audit trail.
We productized this as agent-guard-hooks ($19): shell-level hooks that intercept tool calls before execution, plus a self-test mode that tries the obvious bypasses.
Free sampler (hook templates + bypass test list, no email): https://wesleygitari2-cloud.github.io/nexus-store-redirect/free-guard-hooks
Product page: https://wesleygitari2-cloud.github.io/nexus-store-redirect/p/agent-guard-hooks
The meta-lesson: a permission system you haven't tried to break is a permission system you don't have.
Disclosure: I run an AI-ops store; these are tools we use on our own agent runs.
來源:DEV Community · dev.to