Answer security round 4: 1 🔴, 1 🟡; refuse the format options that start gpg, and load no settings from the case's clone

This commit is contained in:
2026-10-16 22:42:11 +02:00
parent e57309a415
commit 57cd5f76a4
4 changed files with 11 additions and 10 deletions
+3 -2
View File
@@ -50,8 +50,9 @@ def permission_flags(clone, version_dir, report):
*(f"{tool}({tree})" for tool in ("Read", "Grep", "Glob") for tree in trees),
]
denied = ["Bash(git *)", f"Edit(/{clone}/.git/**)", f"Edit(/{clone}/.claude/**)"]
# No "user" source: ~/.claude/settings.json would add ~/code to the trees and run its hooks.
return ["--setting-sources", "project,local", "--permission-mode", "dontAsk", "--permission-prompts", "none",
# No "user" or "project" source: ~/.claude/settings.json would add ~/code to the trees and run its hooks,
# and a case's committed .claude/settings.json could run its own; --strict-mcp-config ignores a committed .mcp.json.
return ["--setting-sources", "local", "--strict-mcp-config", "--permission-mode", "dontAsk", "--permission-prompts", "none",
"--allowedTools", *allowed, "--disallowedTools", *denied]
+4 -4
View File
@@ -7,7 +7,7 @@ working directory, with GIT_DIR and GIT_WORK_TREE pinned to it.
The wrapper refuses every subcommand and option ALLOWED does not list, so a cluster of short options
or a long option cut to a prefix is refused too. An option that takes a value takes it glued, as
`--format=%h`. A commit needs `-m`, whose value is the one free-text argument. Every other argument
`--grep=fix`. A commit needs `-m`, whose value is the one free-text argument. Every other argument
must name no path outside the clone. git runs with no global or system config, hook, pager or editor.
The wrapper checks the arguments git receives, after the shell has removed quotes and expanded `$`,
so no quoting hides a path from it. It lives outside the clone, so a module planted in the clone
@@ -25,10 +25,10 @@ ALLOWED = {
"add": {"-A", "--all", "-u", "--update"},
"commit": {"-a", "--all"},
"diff": OUTPUT | {"--cached", "--check", "--staged", "--word-diff"},
"log": OUTPUT | {"--author=", "--decorate", "--follow", "--format=", "--graph", "--grep=", "--max-count=",
"--oneline", "-p", "--patch", "--pretty=", "--reverse", "--since=", "--until="},
"log": OUTPUT | {"--author=", "--decorate", "--follow", "--graph", "--grep=", "--max-count=",
"--oneline", "-p", "--patch", "--reverse", "--since=", "--until="},
"ls-files": {"--cached", "--deleted", "--exclude-standard", "--modified", "--others"},
"show": OUTPUT | {"--format=", "--no-patch", "--oneline", "--pretty=", "-s"},
"show": OUTPUT | {"--no-patch", "--oneline", "-s"},
"status": {"-b", "--branch", "--porcelain", "-s", "--short"},
}
# The commit identity, since no config supplies one.
+3 -3
View File
@@ -25,7 +25,7 @@ class Refusal(unittest.TestCase):
["diff", "--ext"], ["ls-files", "-oX/abs/x"], ["diff", "--output=.git/config"], ["diff", "--no-index", "a", "b"],
["commit", "-S", "-m", "x"], ["commit", "--gpg-sign", "-m", "x"], ["commit", "-e", "-m", "x"],
["commit", "--edit", "-m", "x"], ["commit", "-c", "HEAD"], ["add", "-e"], ["add", "-p"], ["add", "-i"],
["add", "--patch"], ["log", "--help"],
["add", "--patch"], ["log", "--help"], ["log", "--format=%h %G?"], ["show", "--pretty=%GS"],
):
with self.subTest(argv):
self.assertIn(argv[1], refusal(argv, escapes) or "")
@@ -56,8 +56,8 @@ class Refusal(unittest.TestCase):
def test_allows_the_reviews_own_commands(self):
for argv in (
["log", "--oneline", "abc123..chunk"], ["log", "-5"], ["log", "--max-count=3", "--format=%h %s"],
["log", "--stat", "HEAD~1..HEAD"], ["log", "--pretty=%H", "--", "src/a.py"], ["diff", "base...chunk", "--stat"],
["log", "--oneline", "abc123..chunk"], ["log", "-5"], ["log", "--max-count=3", "--oneline"],
["log", "--stat", "HEAD~1..HEAD"], ["log", "--oneline", "--", "src/a.py"], ["diff", "base...chunk", "--stat"],
["diff", "--cached"], ["diff", "--name-only", "HEAD~1"], ["diff", "--", "src"], ["show", "HEAD"],
["show", "--stat", "abc123"], ["show", "HEAD:README.md"], ["status"], ["status", "--short"], ["ls-files"],
["ls-files", "--others", "--exclude-standard"], ["add", "-A"], ["add", "--", "src/a.py"],