Answer stability round 1: 0 🔴, 4 🟡 (0 misread); say a command names the file rather than reads it, name the way on, refuse redirect targets and a quoted $HOME, check each file once, and drop the README caveat the rule outlived
This commit is contained in:
@@ -405,7 +405,6 @@ class EnvFileRead(unittest.TestCase):
|
||||
subprocess.run(["git", "init", "--quiet", str(self.home / ".claude")], check=True, env=isolated_env())
|
||||
(self.home / ".claude" / ".gitignore").write_text(".env\n")
|
||||
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": f"{self.home}/.claude"}), [])
|
||||
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": f"{self.home}/.claude", "glob": "*"}), ["env-file-read"], "a glob overrides ripgrep's ignore files")
|
||||
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": f"{self.home}/code"}), [])
|
||||
|
||||
def test_a_command_naming_the_file_is_refused(self):
|
||||
@@ -417,6 +416,55 @@ class EnvFileRead(unittest.TestCase):
|
||||
self.assertEqual(self.breached("Bash", {"command": f"cat ~/.claude/.envrc /backup{self.home}/.claude/.env .env"}, "/r"), [])
|
||||
self.assertEqual(self.breached("Bash", {"command": "cat 'a\0b'"}, f"{self.home}/.claude"), [])
|
||||
|
||||
def test_a_command_s_refusal_says_it_names_the_file_not_that_it_reads_it(self):
|
||||
found = breaches_of(Call("Bash", {"command": "ls -l ~/.claude/.env"}, "/r"), str(self.home), {})
|
||||
details = [breach.detail for breach in found[2] if breach.rule == "env-file-read"]
|
||||
self.assertEqual(len(details), 1)
|
||||
self.assertTrue(details[0].startswith(f"the command names {self.home}/.claude/.env"), details[0])
|
||||
self.assertNotIn("reads", details[0])
|
||||
|
||||
def test_the_rule_names_the_way_on_for_a_command_that_only_mentions_the_path(self):
|
||||
holds = RULES["env-file-read"].holds
|
||||
self.assertIn('"the .env in ~/.claude"', holds)
|
||||
self.assertIn("`~/.claude/bin/project-config env-file`", holds)
|
||||
self.assertNotIn(". ", holds, "one sentence")
|
||||
|
||||
def test_a_command_redirecting_from_the_file_is_refused(self):
|
||||
self.assertEqual(self.breached("Bash", {"command": "cd ~/secrets && wc < acme.env"}), ["env-file-read"])
|
||||
self.assertEqual(self.breached("Bash", {"command": "wc < acme.env"}, f"{self.home}/secrets"), ["env-file-read"])
|
||||
self.assertEqual(self.breached("Bash", {"command": "while read l; do echo $l; done < .env"}, f"{self.home}/.claude"), ["env-file-read"])
|
||||
|
||||
def test_a_command_naming_the_file_through_a_quoted_home_is_refused(self):
|
||||
for command in ('cat "$HOME"/.claude/.env', 'cat "${HOME}"/.claude/.env'):
|
||||
with self.subTest(command):
|
||||
self.assertEqual(self.breached("Bash", {"command": command}), ["env-file-read"])
|
||||
|
||||
def test_a_grep_s_glob_is_refused_only_where_it_can_match_the_ignored_file(self):
|
||||
subprocess.run(["git", "init", "--quiet", str(self.home / ".claude")], check=True, env=isolated_env())
|
||||
(self.home / ".claude" / ".gitignore").write_text(".env\n")
|
||||
for glob, expected in (("**/*.md", []), ("rules/*.md", []), ("*.py", []), ("!.env", []), ("*", ["env-file-read"]), (".env*", ["env-file-read"]), ("{*.md,.env}", ["env-file-read"])):
|
||||
with self.subTest(glob):
|
||||
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": f"{self.home}/.claude", "glob": glob}), expected)
|
||||
|
||||
def test_a_grep_s_glob_with_a_slash_is_matched_against_the_path_from_the_searched_folder(self):
|
||||
subprocess.run(["git", "init", "--quiet", str(self.home / ".claude")], check=True, env=isolated_env())
|
||||
(self.home / ".claude" / ".gitignore").write_text(".env\n")
|
||||
# ~/secrets/acme.env is in no checkout, so only the ignored file's breach tells the globs apart.
|
||||
for glob, refused in ((".claude/*", True), ("**/.env", True), ("/.claude/.env", True), (".claude/**", True), ("secrets/*", False), ("*/*.md", False), (".env/*", False)):
|
||||
with self.subTest(glob):
|
||||
found = breaches_of(Call("Grep", {"pattern": "TOKEN", "path": str(self.home), "glob": glob}, "/r"), str(self.home), {})
|
||||
self.assertEqual(any(breach.detail.startswith(f"the call reads {self.home}/.claude/.env,") for breach in found[2]), refused)
|
||||
|
||||
def test_a_file_several_configs_name_is_reported_once(self):
|
||||
write_config(self.home, self.home / "code" / "other")
|
||||
config = self.home / ".claude-projects" / "other" / "config.toml"
|
||||
config.write_text(config.read_text() + 'env-file = "~/secrets/../secrets/acme.env"\n')
|
||||
found = breaches_of(Call("Read", {"file_path": "~/secrets/acme.env"}, "/r"), str(self.home), {})
|
||||
self.assertEqual(len([breach for breach in found[2] if breach.rule == "env-file-read"]), 1)
|
||||
|
||||
def test_a_grep_of_a_path_holding_a_nul_byte_passes(self):
|
||||
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": "a\0b"}), [])
|
||||
|
||||
|
||||
class ReviewerReport(unittest.TestCase):
|
||||
def breached(self, tool: str, path: str, agent: str = "prose-reviewer", cwd: str = "/r") -> list[str]:
|
||||
|
||||
Reference in New Issue
Block a user