Compare commits

...

8 Commits

Author SHA1 Message Date
lilleman c8eeeadd24 Answer prose round 1: 0 🔴, 3 🟡 (0 misread); reword the rule's checked text, the changelog bullet and the ignored docstring, in the stability answer
CI / tests (pull_request) Successful in 2m23s
2026-11-13 21:25:15 +01:00
lilleman 66670f4e3d Answer product-owner round 1: 0 🔴, 3 🟡 (0 misread); refuse a Grep only where its glob can match the ignored file, and stop the changelog promising more than the rule does, both in the stability answer 2026-11-13 21:25:15 +01:00
lilleman 0cc242ac1b 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 2026-11-13 21:25:15 +01:00
lilleman 60a1f5c385 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
2026-11-13 21:12:38 +01:00
lilleman b4b84a4280 Sort test_project_config.py's imports
CI / tests (pull_request) Successful in 2m24s
2026-11-13 21:11:01 +01:00
lilleman bc066943f6 Sort env_file.py's imports and test env_files 2026-11-13 21:06:12 +01:00
lilleman 7b59056c3d Test the env-file-read spellings and log names that mutants survived 2026-11-13 21:01:03 +01:00
lilleman 333ebe58b8 Refuse a Read, Grep or Bash call that reads ~/.claude/.env or a config's env-file
CI / tests (pull_request) Failing after 2m29s
2026-11-13 20:56:17 +01:00
11 changed files with 266 additions and 13 deletions
+1
View File
@@ -2,6 +2,7 @@
## Unreleased
- rule-hook refuses a Read or a Grep of `~/.claude/.env` or of the `env-file` any project's config names, and a Bash command that names either, so that a worker doesn't put a credential in its transcript in passing. A command that hides the path, such as behind a glob or a variable, still goes through.
- To keep Mattermost DMs, move the keys from `~/.claude/.env` into a file outside the checkout and the config's folder, such as `~/.claude-projects/<key>.env`, and name it in the project's config as `env-file`; `mattermost-dm` and loop-claude's DMs no longer read `~/.claude/.env`, and a project with no `env-file` gets none. A failure names each missing key and holds no token.
## 0.10.0
+2 -2
View File
@@ -94,7 +94,7 @@ goals-and-audience = "checkout:README.md"
principles = "~/.claude/principles"
```
A project may also set `env-file`, the file of `KEY=value` credentials its tools read, such as `env-file = "~/.claude-projects/log.env"`. It is a path that starts with `/` or `~/`, outside the checkout and the config's folder, so that no git remote receives it. A tool that needs a key fails and names each one the file lacks. No failure message, prompt, log line or archived loop output holds a token from the file. A worker that opens the file itself still puts it in its transcript. A project without the setting has no credentials, and never reads another project's. `project-config env-file` prints the path.
A project may also set `env-file`, the file of `KEY=value` credentials its tools read, such as `env-file = "~/.claude-projects/log.env"`. It is a path that starts with `/` or `~/`, outside the checkout and the config's folder, so that no git remote receives it. A tool that needs a key fails and names each one the file lacks. No failure message, prompt, log line or archived loop output holds a token from the file. rule-hook refuses a Read or a Grep of the file and a Bash command that names it, so a worker doesn't read it in passing; `rule-hook --help` says which calls it checks. A project without the setting has no credentials, and never reads another project's. `project-config env-file` prints the path.
For a client's project, use one sandbox VM per client, so that one client's code, transcripts and credentials never share a machine with another's. What the client's repo should not hold lives in the config's folder, at paths written as `folder:<path>`, as `project-config --help` shows: the plan, the working rules in an `AGENTS.md` I write for the agents, the records, and the goals and audience, as `goals-and-audience = "folder:goals.md"`. Name that file `goals.md`, so the rules for goals and audience load when an agent writes it. A file outside the checkout has no commits in the checkout's history, so four things are not supported for it yet. `score-outcomes` and loop-claude's routing figures count a project's chunks only where `todo.md`, `docs/comprehension-history.md` and `docs/reading-cost.md` are at those paths in the checkout; otherwise each says so, and the loop goes on. For a plan or a comprehension history outside the checkout, `larv-review` says it cannot tell whether a scoring run is owed, and for such a history it cannot find a paired ruling's base. For a plan outside the checkout, chunk-preflight and loop-claude don't see a release whose last item has shipped, and say that its release review and its cut are yours to call. And rule-hook checks a plan outside the checkout on every call, not only when it changed.
@@ -149,7 +149,7 @@ Install puts only `loop-claude` and `loop-inbox` on `PATH`; call the others by t
- `rank_todo.py [--check] [todo.md]` scores and ranks a project's `todo.md`, by default the one its config names; `rank_todo.py --help` states the format.
- `reading-cost [--reset] [record]` appends a figure for each chunk `loop-claude` finished to a project's `docs/reading-cost.md`, and says whether the figures rise; `reading-cost --help` states the measure.
- `review-replay <pass> <model>` replays a review pass's archived rounds from the projects run on the model, on the code each reviewed, and prints the lowest rung below the project's that, like each rung above it, qualifies: it finds no less of the 🔴 and 🟡 findings than two replays on the project's rung find, within a margin, and misses no 🔴 that both found. `review-replay --help` states the replay. With `--omit-claude-md` it tests instead whether the pass's reviewer may start without `CLAUDE.md`: it replays each round three times as archived and once without the instruction files, and prints whether the reviewer passes: whether the last replay missed no more findings than the most an unchanged replay missed, with each count and each finding it missed. Each replayed reviewer skips every permission prompt, stability-reviewer has Bash, and an archived prompt may name paths on the host.
- `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Agent, Bash, Edit, MultiEdit, Read, Skill and Write call, and `rule-hook --help` states the rules and the override.
- `rule-hook [overrides]` blocks a tool call that breaks a rule a program can check, unless the call overrides the rule; `settings.json` → `hooks` runs it before each Agent, Bash, Edit, Grep, MultiEdit, Read, Skill and Write call, and `rule-hook --help` states the rules and the override.
- `run-heavy <command>` runs a heavy command once it holds one of the machine's heavy slots, one per 4 CPUs, which every session shares; `run-heavy --help` states the slots, and the memory cap it gives a container that sets no limit.
- `run-tests [<pytest args>...]` runs this repo's test suite, as Test says.
- `score-outcomes [L E I S]` shows what each finished item's chunk measured beside the scores the item was guessed at, to score a new item by. Per chunk it also shows code health's two counter-signals, misread findings and later fixes, and how many of the human's answers reversed a worker's choice; `score-outcomes --help` states the report.
+6
View File
@@ -87,6 +87,12 @@ def held(folder: pathlib.Path, home: pathlib.Path) -> ProjectConfig | Failure |
return config if isinstance(config, Failure) else load(config[0], config[0], home)
def env_files(home: pathlib.Path) -> list[pathlib.Path]:
"""Every config's env-file, read without the checks load makes, so a config that fails them still keeps its credentials guarded; a config that cannot be read names none."""
configs = [read(file, home) for file in sorted((home / PROJECTS).glob(f"*/{CONFIG}"))]
return [path for config in configs if not isinstance(config, Failure) and (path := anywhere(config[1].get(ENV_FILE), home))]
def read(file: pathlib.Path, home: pathlib.Path) -> tuple[pathlib.Path, dict[str, object]] | Failure:
"""The checkout a config names, as an absolute path, and its other values."""
try:
+10 -1
View File
@@ -8,8 +8,8 @@ import unittest.mock
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
from project_config.settings import env_files, held, load, OUTSIDE, ProjectConfig, SETTINGS
from failure import Failure
from project_config.settings import held, load, OUTSIDE, ProjectConfig, SETTINGS
from test_env import isolated_env
TOOL = pathlib.Path(__file__).resolve().parents[1] / "project-config"
@@ -238,6 +238,15 @@ class HeldTest(ConfigCase):
self.assertIsInstance(held(target, self.home), ProjectConfig, "git names the folder by its resolved path")
class EnvFilesTest(ConfigCase):
def test_lists_each_readable_configs_env_file_even_one_load_refuses(self) -> None:
self.write("acme", CLIENT + 'env-file = "~/acme.env"\n')
self.write("misplaced", 'checkout = "~/code/other"\nenv-file = "/srv/other.env"\n')
self.write("broken", "checkout = ")
self.write("none", CLIENT)
self.assertEqual(env_files(self.home), [self.home / "acme.env", pathlib.Path("/srv/other.env")])
class ToolTest(ConfigCase):
def run_tool(self, *args: str, cwd: pathlib.Path | None = None) -> subprocess.CompletedProcess[str]:
return subprocess.run([sys.executable, str(TOOL), *args], cwd=cwd or self.checkout, env={**isolated_env(), "HOME": str(self.home)}, capture_output=True, text=True)
+104
View File
@@ -0,0 +1,104 @@
"""Whether a Read or a Grep reads a credentials file, or a Bash command names one, for the `env-file-read` rule.
The files are `~/.claude/.env` and every config's `env-file`, not only the calling project's: a worker in one client's project must not read another client's credentials either, and listing every config's file needs no git call, as finding the calling project's would.
A Bash command names one where its text spells the file's path, or one of its words, a redirect's target included, leads to the file from the directory `cd` left the command in. Whether the command reads the file is not judged, so one that only mentions the path is refused too.
This guards against an agent reading the file in passing, not against one that hides the path, such as behind a glob, a variable of its own or a recursive search of a folder that holds it; todo.md item 370 covers the recursive Bash searches."""
import os
import pathlib
import re
import typing
from rule_hook.rules import Breach
from rule_hook.call import Call, text
from project_config.settings import env_files
from failure import Failure
from rule_hook.git import guarded_git
from command_lines.shell_command import lexed, OPERATOR, resolved
# What a Grep's glob holds beyond literals, `*`, `?` and `/`: forms globbed() does not translate.
UNMATCHED = re.compile(r"[{}\[\]\\,\s]|/$")
def env_file_breaches(call: Call, home: str) -> list[Breach]:
guarded: dict[str, pathlib.Path] = {}
for path in (pathlib.Path(home, ".claude", ".env"), *env_files(pathlib.Path(home))):
if path.is_file():
# Several configs may name one file: it is checked, and reported, once.
guarded.setdefault(os.path.realpath(path), path)
# A command may name the file without reading it, so the detail claims no read of it.
found = "the command names {}, a file of credentials that must stay out of the transcript" if call.tool == "Bash" else "the call reads {}, whose credentials would land in the transcript"
return [Breach("env-file-read", found.format(path), call.cwd) for path in guarded.values() if reached(call, path, home)]
def reached(call: Call, path: pathlib.Path, home: str) -> bool:
"""Whether a Read or a Grep reads path, or a Bash command names it."""
if call.tool == "Read":
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)
# ripgrep's --glob overrides its ignore files, so an ignored file is skipped unless a glob matches it.
return names(searched, path) or holds(searched, path) and (globbed(text(call.given, "glob"), searched, path) 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}"))))
# Bounded on both sides, so a longer path that holds a spelling, such as ~/.claude/.envrc, is another file.
spelt = re.search(rf"(?<![\w./~-])(?:{spellings})(?![\w.-])", command)
return spelt is not None or any(names(word, path) for word in paths(command, call.cwd, home))
def paths(command: str, cwd: str, home: str) -> typing.Iterator[str]:
"""Each word of the command as a path from the directory `cd` left it in. Unlike simple_commands, it keeps a redirect's target, which a command reads as it reads an operand."""
tokens = lexed(command)
if tokens is None:
# One unbalanced quote should not hide the other lines.
tokens = [token for line in command.splitlines() for token in (lexed(line) or []) + ["\n"]]
directory = cwd
words: list[str] = []
for token in [*tokens, "\n"]:
if token and set(token) <= OPERATOR:
if len(words) == 2 and words[0] == "cd":
directory = resolved(directory, words[1], home)
words = []
else:
# The lexer has joined a quoted "$HOME" to the rest of its word.
word = re.sub(r"^\$(HOME|\{HOME\})(?=/|$)", "~", token)
words.append(word)
yield resolved(directory, word, home)
def globbed(glob: str, searched: str, path: pathlib.Path) -> bool:
"""Whether a Grep's glob can match path, as ripgrep matches it: one without a `/` against the file's name, one with a `/` against the path from the searched folder. A glob holding a form this does not translate, such as `{a,b}`, counts as matching."""
if not glob:
return False
if UNMATCHED.search(glob):
return True
if glob.startswith("!"):
# It only excludes files.
return False
anchored = glob.lstrip("/") if "/" in glob else f"**/{glob}"
# A `**` that is not a whole folder name matches as `*` in ripgrep; crossing folders there only refuses more.
translated = {"**/": "(?:.*/)?", "**": ".*", "*": "[^/]*", "?": "[^/]"}
pattern = "".join(translated.get(piece, re.escape(piece)) for piece in re.split(r"(\*\*/|\*\*|\*|\?)", anchored))
return re.fullmatch(pattern, os.path.relpath(os.path.realpath(path), os.path.realpath(searched))) is not None
def names(given: str, path: pathlib.Path) -> bool:
"""Whether given leads to path, through any symlink."""
try:
return os.path.realpath(given) == os.path.realpath(path)
except ValueError:
# A word holding a NUL byte names no file.
return False
def holds(folder: str, path: pathlib.Path) -> bool:
try:
return pathlib.Path(os.path.realpath(path)).is_relative_to(os.path.realpath(folder))
except ValueError:
# A folder whose path holds a NUL byte holds no file.
return False
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 unless a glob matches it."""
return not isinstance(guarded_git(str(path.parent), "check-ignore", "--quiet", path.name), Failure)
+7 -3
View File
@@ -3,7 +3,7 @@
usage: rule-hook (a PreToolUse hook: reads the call as JSON on stdin)
rule-hook overrides (prints this chunk's overrides)
settings.json runs it before each Agent, Bash, Edit, MultiEdit, Read, Skill and Write call, in every session and
settings.json runs it before each Agent, Bash, Edit, Grep, MultiEdit, Read, Skill and Write call, in every session and
subagent. The rules:
{rules}
@@ -44,6 +44,7 @@ from rule_hook.call import applied, Call, FILE_TOOLS, parsed_call, text
from rule_hook.rules import Breach, check, Checked, command_breaches, file_breaches, rules_help
from git_cli.git_command import commits
from rule_hook.committed_files import committed_file_breaches
from rule_hook.env_file import env_file_breaches
from failure import Failure
from rule_hook.override_log import Log, log_path, logged, print_overrides, write_override
from rule_hook.file_text import read
@@ -86,9 +87,12 @@ def breaches_of(call: Call, home: str, environ: typing.Mapping[str, str]) -> tup
return text(call.given, "args"), text(call.given, "skill"), skill_breaches(call, environ)
if call.tool == "Bash":
command = text(call.given, "command")
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home) + read_breaches(call, home)
return command, command.split("\n", 1)[0], bash_breaches(command, call.cwd, home) + read_breaches(call, home) + env_file_breaches(call, home)
if call.tool == "Read":
return "", text(call.given, "file_path"), read_breaches(call, home)
return "", text(call.given, "file_path"), read_breaches(call, home) + env_file_breaches(call, home)
if call.tool == "Grep":
# Only env-file-read checks a Grep, and it takes no override, so no marker or log line concerns the call.
return "", "", env_file_breaches(call, home)
path = text(call.given, "file_path")
if call.tool not in FILE_TOOLS or not path:
return None
+7 -1
View File
@@ -11,7 +11,7 @@ from command_lines.shell_command import launched, Simple
from review_rules.review_folder import REPORTS
from command_lines.docker_command import unlimited
RuleName = typing.Literal["action-pin", "commit-one-line", "docker-run-memory", "ignorefile-sorted", "image-pin", "no-ai-attribution", "repeat-read", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"]
RuleName = typing.Literal["action-pin", "commit-one-line", "docker-run-memory", "env-file-read", "ignorefile-sorted", "image-pin", "no-ai-attribution", "repeat-read", "reviewer-report", "reviewer-rung", "round-cap", "round-title-counts", "run-heavy", "todo-rank-check"]
@dataclasses.dataclass(frozen=True)
@@ -35,6 +35,12 @@ RULES: dict[RuleName, Rule] = {
"a container made with docker run or docker create has a memory limit and a swap limit, as large as its work needs, such as `--memory 4g --memory-swap 4g`, so a runaway container fails alone instead of starving the machine; a swap limit equal to the memory limit keeps it out of swap",
"docker run, docker create, docker container run and docker container create, whether direct or through a launcher such as nice or timeout. One under run-heavy passes, as run-heavy's docker adds the limits on Linux, unless it names docker by its path, or changes or clears PATH, as env -i, sudo or doas do. A container a script or docker compose starts is not checked",
),
# 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 the project's config names, since a value the agent reads lands in its transcript, which loop-claude archives and the backups copy; it leaves a tool that needs a credential to read the file itself, gets the file's path from `~/.claude/bin/project-config env-file`, and spells the path another way, such as \"the .env in ~/.claude\", in a command that must mention it without reading it, such as a commit's title",
"against ~/.claude/.env and the env-file of every config under ~/.claude-projects: a Read of one; a Grep of one, or of a folder holding one, unless a checkout ignores the file and the Grep's glob cannot match it; and a Bash command that spells one's path, or names it in a word or a redirect's target from the directory `cd` left the command in, whether or not the command reads it",
overridable=False,
),
"ignorefile-sorted": Rule(
"each block of an ignore file is sorted in code-point order, as LC_ALL=C sort does, since its order carries no meaning; where order matters, such as a re-include after its exclude, split the block with a blank line or a comment",
"a .*ignore file; a block already unsorted before the edit is left alone",
+107 -1
View File
@@ -18,7 +18,7 @@ from rule_hook.rules import blocks, Breach, check, command_breaches, file_breach
from rule_hook.main import breaches_of
from rule_hook.call import Call, parsed_call
from git_cli.git_command import commit_message, CommitCall, commits
from project_config.test_project_config import configured
from project_config.test_project_config import configured, write_config
from release_plan.test_ranking import DECISIONS, README, TODO
from rule_hook.git import guarded_git
from test_env import isolated_env
@@ -360,6 +360,112 @@ class ReviewerRung(unittest.TestCase):
self.assertTrue(any("Skill" in tools for tools in matchers))
class EnvFileRead(unittest.TestCase):
"""A home with ~/.claude/.env and a config whose env-file lies outside any checkout."""
def setUp(self) -> None:
self.home = pathlib.Path(self.enterContext(tempfile.TemporaryDirectory()))
(self.home / ".claude").mkdir()
(self.home / ".claude" / ".env").write_text("TOKEN=x\n")
write_config(self.home, self.home / "code" / "acme")
config = self.home / ".claude-projects" / "acme" / "config.toml"
config.write_text(config.read_text() + 'env-file = "~/secrets/acme.env"\n')
(self.home / "secrets").mkdir()
(self.home / "secrets" / "acme.env").write_text("TOKEN=y\n")
def breached(self, tool: str, given: dict[str, typing.Any], cwd: str = "/r") -> list[str]:
found = breaches_of(Call(tool, given, cwd), str(self.home), {})
return sorted({rule for rule in rules(found[2]) if rule == "env-file-read"}) if found else []
def test_a_read_of_claude_s_env_or_a_config_s_env_file_is_refused(self):
self.assertEqual(self.breached("Read", {"file_path": f"{self.home}/.claude/.env"}), ["env-file-read"])
self.assertEqual(self.breached("Read", {"file_path": "acme.env"}, f"{self.home}/secrets"), ["env-file-read"])
def test_a_read_spelt_from_home_is_refused_naming_the_file(self):
found = breaches_of(Call("Read", {"file_path": "~/.claude/.env"}, "/r"), str(self.home), {})
self.assertEqual([breach.detail for breach in found[2]], [f"the call reads {self.home}/.claude/.env, whose credentials would land in the transcript"])
def test_the_log_names_a_read_by_its_file_and_a_command_by_its_first_line(self):
self.assertEqual(breaches_of(Call("Read", {"file_path": "a.txt"}, "/r"), str(self.home), {})[1], "a.txt")
self.assertEqual(breaches_of(Call("Bash", {"command": "ls -l\nls -a\nls"}, "/r"), str(self.home), {})[1], "ls -l")
def test_a_read_through_a_symlink_is_refused(self):
(self.home / "link").symlink_to(self.home / "secrets" / "acme.env")
self.assertEqual(self.breached("Read", {"file_path": f"{self.home}/link"}), ["env-file-read"])
def test_a_read_of_another_file_passes(self):
self.assertEqual(self.breached("Read", {"file_path": f"{self.home}/.claude/settings.json"}), [])
def test_a_grep_of_the_file_or_of_a_folder_holding_it_is_refused(self):
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": f"{self.home}/secrets/acme.env"}), ["env-file-read"])
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": str(self.home)}), ["env-file-read"])
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN"}, f"{self.home}/secrets"), ["env-file-read"])
self.assertEqual(self.breached("Grep", {"pattern": "TOKEN", "path": "~/secrets"}), ["env-file-read"])
def test_a_grep_of_a_folder_whose_checkout_ignores_the_file_or_of_another_folder_passes(self):
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}/code"}), [])
def test_a_command_naming_the_file_is_refused(self):
for command in ("cat ~/.claude/.env", "sh -c 'cat ~/.claude/.env'", f"sh -c 'cat {self.home}/secrets/acme.env'", f"grep TOKEN {self.home}/secrets/acme.env", "source $HOME/secrets/acme.env", "wc < ${HOME}/.claude/.env", "cd ~/secrets && cat acme.env"):
with self.subTest(command):
self.assertEqual(self.breached("Bash", {"command": command}), ["env-file-read"])
def test_a_command_naming_another_file_passes(self):
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]:
given = {"file_path": path, "content": "BLOCK\n"} if tool == "Write" else {"file_path": path, "old_string": "a", "new_string": "b"}
+17
View File
@@ -1915,3 +1915,20 @@ Read most (opens and searches):
Read most (opens and searches):
- `skills/larv-review/SKILL.md` 7
## Reading cost, chunk ea61fbec00f3, finished 2026-11-13T19:51:50Z
160159 new input tokens before the first commit.
Read most (opens and searches):
- `bin/loop_claude/test_black_box.py` 11
- `README.md` 6
- `bin/mattermost_dm/test_mattermost_dm.py` 4
- `settings.json` 4
- `bin/project_config/settings.py` 3
- `bin/project_config/test_project_config.py` 3
- `CHANGELOG.md` 2
- `bin/loop_effects/effects.py` 2
- `bin/mattermost_dm/dm.py` 2
- `bin/project_config/main.py` 2
+1 -1
View File
@@ -32,7 +32,7 @@
"type": "command"
}
],
"matcher": "Agent|Bash|Edit|MultiEdit|Read|Skill|Write"
"matcher": "Agent|Bash|Edit|Grep|MultiEdit|Read|Skill|Write"
}
],
"SubagentStart": [
+4 -4
View File
@@ -6,13 +6,13 @@
`Bar = 0.1`
`Next ID = 370`
`Next ID = 371`
## Items
| ID | Release | Blocked by | Exempt | Item | L | E | I | R | S | Moves | Score |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 369 | 0.11.0 | | security | **Refuse a Read, Grep or Bash call that reads the project's env-file or ~/.claude/.env, so no credential value reaches a transcript.** | 3 | 2 | 4 | 7 | 4 | 4 by 8 | 8.3 |
| 370 | 0.11.0 | | security | **Refuse a Bash command that recursively searches a folder holding an env-file, as `grep -r` or `rg` do, so no credential reaches a transcript.** | 2 | 2 | 4 | 6 | 2 | 4 by 3 | 4.2 |
| 354 | 0.11.0 | | | **Read and write the decisions, score anchors, comprehension history, reading cost and changelog each through the backend its project's config names, with markdown files as one backend.** | 3 | 2 | 3 | 6 | 6 | 1.6 by 4, code health by 1 | 1.2 |
| 364 | 0.11.0 | 354 | | **Read a client repo's own `CLAUDE.md` and `AGENTS.md`, propose to its team each change that aligns them with this setup, and record each conflict left as a decision in the project's records.** | 2 | 2 | 2 | 4 | 2 | 1.6 by 4, 1.2 by 2 | 2.2 |
| 360 | 0.11.0 | | | **Make `chunk-pr merge` wait for the human approvals a project's config requires, as part of the gate, before it merges.** | 2 | 2 | 3 | 5 | 3 | 1.6 by 5 | 1.6 |
@@ -87,9 +87,9 @@
## Details
### 369. Refuse a Read, Grep or Bash call that reads the project's env-file or ~/.claude/.env, so no credential value reaches a transcript.
### 370. Refuse a Bash command that recursively searches a folder holding an env-file, as `grep -r` or `rg` do, so no credential reaches a transcript.
Item 348 gives each project's config an `env-file` of KEY=value credentials, such as a Mattermost bot token, read by `bin/mattermost-dm` and loop-claude. Its code never puts a value in a prompt, log line or archive, but it left the worker out of scope: a loop-claude worker runs headless in auto permission mode and can still Read, Grep or `cat` the env-file. The value then lands in its transcript, which loop-claude archives under `~/.claude/loop-claude-transcripts` and the backup copies. `~/.claude/.env` is exposed the same way today. Add a `bin/rule_hook` rule that resolves the project's env-file through `bin/project_config` (`ProjectConfig.env_file`), along with `~/.claude/.env`, and refuses a tool call whose path or command names either. A test must show the refusal for each tool. Where the change touches `bash_breaches` in `bin/rule_hook/main.py:116`, split its long return line, which the comprehension seats found hard to read.
The env-file-read rule refuses a Grep of a folder that holds `~/.claude/.env` or a config's env-file, but a Bash command only where it spells or names the file itself. A worker that runs `grep -r TOKEN ~/.claude-projects`, or `rg --no-ignore` over `~/.claude`, still prints the credential lines into its transcript, which loop-claude archives under `~/.claude/loop-claude-transcripts` and the backups copy. README suggests keeping the env-file at `~/.claude-projects/<key>.env`, in a folder agents search often. Extend `bin/rule_hook/env_file.py` to refuse a `grep -r`/`-R`, `rg` or `ag` whose folder operand, or the directory `cd` left it in when it names none, holds a guarded file that the tool doesn't skip. A test must show the refusal for each tool. The security pass of item 369's chunk raised it.
### 354. Read and write the decisions, score anchors, comprehension history, reading cost and changelog each through the backend its project's config names, with markdown files as one backend.