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)