Answer security round 1: 0 🔴, 1 🟡 (0 misread); refuse a Grep with a glob over a folder holding an ignored env-file, and file item 370 for recursive Bash searches
CI / tests (pull_request) Successful in 2m36s

This commit is contained in:
2026-11-13 21:12:38 +01:00
parent b4b84a4280
commit 60a1f5c385
4 changed files with 11 additions and 4 deletions
+3 -2
View File
@@ -27,7 +27,8 @@ def reads(call: Call, path: pathlib.Path, home: str) -> bool:
return names(resolved(call.cwd, text(call.given, "file_path"), home), path)
if call.tool == "Grep":
searched = resolved(call.cwd, text(call.given, "path") or ".", home)
return names(searched, path) or holds(searched, path) and not ignored(path)
# ripgrep's --glob overrides its ignore files, so an ignored file is skipped only by a Grep without one.
return names(searched, path) or holds(searched, path) and (bool(text(call.given, "glob")) or not ignored(path))
command = text(call.given, "command")
relative = os.path.relpath(path, home)
spellings = "|".join(re.escape(spelling) for spelling in (str(path), *(f"{prefix}/{relative}" for prefix in ("~", "$HOME", "${HOME}"))))
@@ -51,5 +52,5 @@ def holds(folder: str, path: pathlib.Path) -> bool:
def ignored(path: pathlib.Path) -> bool:
"""Whether the checkout holding path ignores it: Grep runs ripgrep, which skips such a file in a folder it searches."""
"""Whether the checkout holding path ignores it: Grep runs ripgrep, which skips such a file in a folder it searches unless a glob names it."""
return not isinstance(guarded_git(str(path.parent), "check-ignore", "--quiet", path.name), Failure)
+1 -1
View File
@@ -38,7 +38,7 @@ RULES: dict[RuleName, Rule] = {
# A marker would let the credentials into the transcript all the same, so no marker waives it.
"env-file-read": Rule(
"an agent never reads ~/.claude/.env or a project's env-file, the file of credentials its config names, since a value it reads lands in its transcript, which loop-claude archives and the backups copy; a tool that needs a credential reads the file itself, and `project-config env-file` prints the file's path",
"a Read of the file, a Grep of the file or of a folder that holds it where no checkout ignores it, and a Bash command that spells the file's path or names it from the directory `cd` left the command in, against ~/.claude/.env and the env-file of every config under ~/.claude-projects",
"a Read of the file, a Grep of the file, or of a folder that holds it where the Grep sets a glob or no checkout ignores the file, and a Bash command that spells the file's path or names it from the directory `cd` left the command in, against ~/.claude/.env and the env-file of every config under ~/.claude-projects",
overridable=False,
),
"ignorefile-sorted": Rule(
+1
View File
@@ -405,6 +405,7 @@ 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):