Skip to content

Commit 6584c7b

Browse files
byapparovclaude
andcommitted
docs(permission): close git -c hook bypass in the bash deny example (#161 review)
- Add "git -c *": "deny" to the documented permission.bash example, since git -c core.hooksPath=/dev/null skips hooks without --no-verify. - Note that --force-with-lease is denied on purpose, that -c rules block harmless uses, and that text patterns fail closed on false positives. - Wire the test's ask through the agent and session rulesets merged as in session/prompt.ts, and deny the -c bypass in the test. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent db644d1 commit 6584c7b

3 files changed

Lines changed: 34 additions & 13 deletions

File tree

‎README.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ Set `AICTRL_HEADLESS=true` in your environment to force headless behavior even i
7878

7979
Tool descriptions describe tools; they are not a security boundary. Block
8080
dangerous commands with `permission.bash` rules, for example denying force
81-
pushes, hook skipping and git config changes. See the
81+
pushes, hook skipping, git config changes and `git -c` overrides (`"git -c *": "deny"`,
82+
which also blocks harmless `-c` uses). The CLI ships no such rules by default. See the
8283
[configuration reference](packages/cli/README.md#restricting-dangerous-commands)
8384
for an example.
8485

‎packages/cli/README.md‎

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,27 @@ carry git policy or a commit/PR procedure. Block dangerous commands with
151151
"git push -f*": "deny",
152152
"git push * -f*": "deny",
153153
"git * --no-verify*": "deny",
154-
"git config *": "deny"
154+
"git config *": "deny",
155+
"git -c *": "deny"
155156
}
156157
}
157158
}
158159
```
159160

161+
- `git push *--force*` also denies `--force-with-lease`, on purpose.
162+
- `git -c *` closes overrides such as `git -c core.hooksPath=/dev/null commit`,
163+
which would otherwise skip hooks without `--no-verify`. It also blocks harmless
164+
`-c` uses.
165+
160166
Each command in a bash call (including each part of `a && b`) is matched against
161167
the patterns. `*` matches any text, and a trailing ` *` also matches the bare
162168
command (`git config *` matches `git config`). When several rules match, the last
163169
one in the config wins. Commands that match no rule keep the agent's default
164-
(`allow` for `bash` in the default `build` agent). Patterns match the command text, so they cannot catch every
165-
spelling (for example `git -c ... push` or a script that runs git).
170+
(`allow` for `bash` in the default `build` agent).
171+
172+
Patterns match the command text. They fail closed on false positives, so
173+
`git commit -m "remove --no-verify"` is denied too. They also cannot catch every
174+
spelling, for example a script that runs git.
166175

167176
If your agents should commit or open PRs, supply your own procedure through a
168177
skill, `AGENTS.md` or the `instructions` config, and run the CLI in an isolated

‎packages/cli/test/tool/bash.test.ts‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Filesystem } from "../../src/util/filesystem"
77
import { tmpdir } from "../fixture/fixture"
88
import { PermissionNext } from "../../src/permission/next"
99
import { Agent } from "../../src/agent/agent"
10+
import { Session } from "../../src/session"
1011
import type { Config } from "../../src/config/config"
1112
import { Truncate } from "../../src/tool/truncation"
1213

@@ -85,22 +86,32 @@ describe("tool.bash dangerous git commands", () => {
8586
"git push * -f*": "deny",
8687
"git * --no-verify*": "deny",
8788
"git config *": "deny",
89+
"git -c *": "deny",
8890
},
8991
} satisfies Config.Info["permission"]
9092

91-
async function withBuildAgent(fn: (run: (command: string) => Promise<unknown>) => Promise<void>) {
93+
type Guarded = {
94+
run: (command: string) => Promise<unknown>
95+
ruleset: PermissionNext.Ruleset
96+
}
97+
98+
// Wires `ask` the way session/prompt.ts does: the agent's rules merged with the session's.
99+
async function withBuildAgent(fn: (guarded: Guarded) => Promise<void>) {
92100
await using tmp = await tmpdir({ git: true, config: { permission } })
93101
await Instance.provide({
94102
directory: tmp.path,
95103
fn: async () => {
96104
const agent = await Agent.get("build")
105+
const session = await Session.create({ title: "Dangerous git commands" })
106+
const ruleset = PermissionNext.merge(agent.permission, session.permission ?? [])
97107
const bash = await BashTool.init()
98108
const guarded = {
99109
...ctx,
110+
sessionID: session.id,
100111
ask: (req: Omit<PermissionNext.Request, "id" | "sessionID" | "tool">) =>
101-
PermissionNext.ask({ ...req, sessionID: "session_test", ruleset: agent.permission }),
112+
PermissionNext.ask({ ...req, sessionID: session.id, ruleset }),
102113
}
103-
await fn((command) => bash.execute({ command, description: "Run git" }, guarded))
114+
await fn({ run: (command) => bash.execute({ command, description: "Run git" }, guarded), ruleset })
104115
},
105116
})
106117
}
@@ -115,20 +126,20 @@ describe("tool.bash dangerous git commands", () => {
115126
"git push --no-verify",
116127
"git config user.name someone",
117128
"git config --global core.hooksPath /dev/null",
129+
"git -c core.hooksPath=/dev/null commit -m wip",
118130
"git status && git push --force",
119131
])("denies %s", async (command) => {
120-
await withBuildAgent(async (run) => {
121-
await expect(run(command)).rejects.toBeInstanceOf(PermissionNext.DeniedError)
132+
await withBuildAgent(async (guarded) => {
133+
await expect(guarded.run(command)).rejects.toBeInstanceOf(PermissionNext.DeniedError)
122134
})
123135
})
124136

125137
test("allows other git commands", async () => {
126-
await withBuildAgent(async (run) => {
127-
const result = (await run("git status")) as { metadata: { exit: number } }
138+
await withBuildAgent(async (guarded) => {
139+
const result = (await guarded.run("git status")) as { metadata: { exit: number } }
128140
expect(result.metadata.exit).toBe(0)
129-
const agent = await Agent.get("build")
130141
for (const command of ["git push origin feature-fix", "git commit -m wip", "git log --oneline"]) {
131-
expect(PermissionNext.evaluate("bash", command, agent.permission).action).toBe("allow")
142+
expect(PermissionNext.evaluate("bash", command, guarded.ruleset).action).toBe("allow")
132143
}
133144
})
134145
})

0 commit comments

Comments
 (0)