Answer security round 3: 0 🔴, 0 🟡; the answer holds

This commit is contained in:
2026-10-16 20:53:27 +02:00
parent 4625b805eb
commit cf4072f69f
5 changed files with 85 additions and 13 deletions
+8 -10
View File
@@ -23,6 +23,7 @@ import sys
import time
BENCH = pathlib.Path(__file__).resolve().parent
REVIEW_GIT = BENCH / "review-git.py"
SOURCES = pathlib.Path(os.environ["BENCH_SOURCES"])
CASES = {
"cjk": ("151bf38^", "6c49912"),
@@ -37,19 +38,16 @@ 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}/**")
commands = ("log", "diff", "show", "status", "ls-files", "add", "commit -m", "commit -am", "commit -a -m")
# git can reach outside the clone through an argument, an option or a hook, and a quote or redirect can
# smuggle one past a text pattern. So the run gets no bare git: review-git.py is its one shell command
# and confines git to the clone (see its docstring). The clone's own .git and .claude stay unwritable,
# lest an edit plant a hook or widen the run's tools; the user's settings would add ~/code to the trees.
allowed = [
"Agent", "Skill(security-review)", f"Edit(/{clone}/**)", f"Edit(/{report})",
*(f"Bash(git {command} *)" for command in commands),
f"Bash(python3 {REVIEW_GIT} *)",
*(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees),
]
# 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. A run
# cannot widen the clone's settings either: Claude Code refuses its edit to them, as a probe showed.
denied = ["Bash(git *)", f"Edit(/{clone}/.git/**)", f"Edit(/{clone}/.claude/**)"]
return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none",
"--allowedTools", *allowed, "--disallowedTools", *denied]
@@ -96,7 +94,7 @@ def run(name):
base, head = fresh_clone(case, clone)
version_dir = BENCH / "versions" / version
prompt = (BENCH / "run-prompt.md").read_text().format(
version_dir=version_dir, base=base, head=head, case=case, report=report)
version_dir=version_dir, base=base, head=head, case=case, report=report, review_git=REVIEW_GIT)
log = BENCH / "logs" / f"{name}.{attempt}.jsonl"
log.parent.mkdir(exist_ok=True)
with log.open("w") as out: