Answer security round 2: 1 🔴, 0 🟡; deny a git argument that names a path outside the clone, in place of listing options

This commit is contained in:
2026-10-16 20:32:36 +02:00
parent 8ab8c09c89
commit 95aa2b3477
2 changed files with 8 additions and 5 deletions
+7 -4
View File
@@ -37,14 +37,17 @@ def permission_flags(clone, version_dir, report):
"""The tools a review needs, each limited to what it may touch; the run denies every other call."""
# A permission rule writes an absolute path as "//<path>"; a trailing "/**" matches everything under it.
trees = (f"/{clone}/**", f"/{version_dir}/**")
git = ("log", "diff", "show", "status", "ls-files", "add", "commit -m", "commit -am")
commands = ("log", "diff", "show", "status", "ls-files", "add", "commit -m", "commit -am", "commit -a -m")
allowed = [
"Agent", "Skill(security-review)", f"Edit(/{clone}/**)", f"Edit(/{report})",
*(f"Bash(git {command} *)" for command in git),
*(f"Bash(git {command} *)" for command in commands),
*(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees),
]
# git reads or writes any path through these options, and runs any command through a hook or config.
denied = [f"Edit(/{clone}/.git/**)", *(f"Bash(git * {option}*)" for option in ("--no-index", "--output", "-F", "--file", "-t", "--template"))]
# git reaches a path outside the clone only through an argument that names one: absolute, from ~, up
# through "..", through a variable, or glued to -O or -X. With -m, git refuses -F and ignores -t
# before reading either file. An edit to .git/ could add a hook, which runs any command.
outside = (" /", "=/", " ~", "=~", "../", " ..", "$", "O/", "X/")
denied = [f"Edit(/{clone}/.git/**)", *(f"Bash(git *{shape}*)" for shape in outside)]
# Only the clone's own settings: the user's add every checkout under ~/code to the readable trees.
return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none",
"--allowedTools", *allowed, "--disallowedTools", *denied]