Answer security round 1: 1 🔴, 1 🟡; allow only the git commands a review needs, deny the options that name a path, and load no user settings
This commit is contained in:
+15
-10
@@ -33,15 +33,21 @@ CASES = {
|
||||
ATTEMPTS = 4
|
||||
|
||||
|
||||
def allowed_tools(clone, version_dir, report):
|
||||
"""The tools a review needs and the paths each reaches; anything else is denied, not asked."""
|
||||
agents = pathlib.Path.home() / ".claude" / "agents"
|
||||
# A rule names an absolute path as "//<path>", and "/**" takes a whole tree.
|
||||
reads = [f"/{root}/**" for root in (clone, version_dir, agents)]
|
||||
return [
|
||||
"Agent", "Skill(security-review)", "Bash(git *)", f"Edit(/{clone}/**)", f"Edit(/{report})",
|
||||
*(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in reads),
|
||||
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")
|
||||
allowed = [
|
||||
"Agent", "Skill(security-review)", f"Edit(/{clone}/**)", f"Edit(/{report})",
|
||||
*(f"Bash(git {command} *)" for command in git),
|
||||
*(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"))]
|
||||
# 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]
|
||||
|
||||
|
||||
def git(repo, *args):
|
||||
@@ -91,8 +97,7 @@ def run(name):
|
||||
log.parent.mkdir(exist_ok=True)
|
||||
with log.open("w") as out:
|
||||
subprocess.run(
|
||||
["claude", "-p", prompt, "--permission-mode", "dontAsk", "--permission-prompts", "none",
|
||||
"--allowedTools", *allowed_tools(clone, version_dir, report),
|
||||
["claude", "-p", prompt, *permission_flags(clone, version_dir, report),
|
||||
"--model", "claude-opus-5-5", "--output-format", "stream-json", "--verbose"],
|
||||
cwd=clone, stdout=out, stderr=subprocess.STDOUT)
|
||||
if report.exists():
|
||||
|
||||
@@ -15,7 +15,7 @@ Report: write it to `{report}`.
|
||||
|
||||
- Launch every agent in the foreground (`run_in_background: false`): background agents die when this headless turn ends.
|
||||
- No remote and no forge: skip the PR, CI, the external auto-reviewer and the merge; review locally.
|
||||
- Do not run the repo's code or test suites: the shell is limited to git.
|
||||
- The shell runs only git, so run no code or test suite. Where the process asks for a run, such as the stability pass's mutation test, review by reading and list the skipped run under Ambiguities.
|
||||
- Skip the comprehension check; say so in the report.
|
||||
- No human is reachable. Where the process names a no-human branch, take it; where it names none, take your recommendation and list the question in the report.
|
||||
- Commit each round's fixes on `chunk`, messages prefixed `{case} - review: `. Touch nothing outside this repository except the report.
|
||||
|
||||
Reference in New Issue
Block a user