Answer security round 5: 0 🔴, 1 🟡; load no settings source at all, and answer stability round 5's nit with a test that no config or hook program runs
This commit is contained in:
@@ -50,9 +50,10 @@ 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" 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",
|
||||
# No settings source: ~/.claude/settings.json would add ~/code to the trees and run its hooks, and a case's
|
||||
# committed .claude/settings.json or settings.local.json could run its own. --strict-mcp-config ignores a
|
||||
# committed .mcp.json.
|
||||
return ["--setting-sources", "", "--strict-mcp-config", "--permission-mode", "dontAsk", "--permission-prompts", "none",
|
||||
"--allowedTools", *allowed, "--disallowedTools", *denied]
|
||||
|
||||
|
||||
|
||||
@@ -119,6 +119,25 @@ class Wrapper(unittest.TestCase):
|
||||
ran = self.wrapper("diff", "--output=.git/config", cwd=self.clone)
|
||||
self.assertEqual((ran.returncode != 0, (self.clone / ".git" / "config").read_bytes()), (True, config))
|
||||
|
||||
def test_runs_no_program_that_a_config_or_hook_names(self):
|
||||
marker = self.root / "ran"
|
||||
program = self.root / "program.sh"
|
||||
program.write_text(f"#!/bin/sh\ntouch {marker}\n")
|
||||
program.chmod(0o755)
|
||||
home = self.root / "home"
|
||||
home.mkdir()
|
||||
(home / ".gitconfig").write_text(f"[diff]\n\texternal = {program}\n")
|
||||
(self.clone / ".git" / "hooks" / "pre-commit").write_text(f"#!/bin/sh\ntouch {marker}\n")
|
||||
(self.clone / ".git" / "hooks" / "pre-commit").chmod(0o755)
|
||||
with (self.clone / ".git" / "config").open("a") as config:
|
||||
config.write(f"[core]\n\tfsmonitor = {program}\n")
|
||||
(self.clone / "a.txt").write_text("two\n")
|
||||
self.env["HOME"] = str(home)
|
||||
self.wrapper("diff", cwd=self.clone)
|
||||
self.wrapper("status", cwd=self.clone)
|
||||
self.wrapper("commit", "-a", "-m", "x", cwd=self.clone)
|
||||
self.assertFalse(marker.exists())
|
||||
|
||||
def test_refuses_to_run_without_the_clone_named(self):
|
||||
(self.clone / "a.txt").write_text("two\n")
|
||||
ran = self.wrapper("diff", cwd=self.clone, clone_env=False)
|
||||
|
||||
Reference in New Issue
Block a user