Dev.to AI šŸ¤– Ai šŸ‘ 0 šŸ“– 4 min read

A reader broke my coding-agent guard in a day. Then I broke it six more times.

Last week I wrote about giving Claude Code a poisoned GitHub issue, twice. The short version: cleimesh guard runs as a Claude Code hook, remembers what the session has read, and once the session has read something from o

A reader broke my coding-agent guard in a day. Then I broke it six more times.

Last week I wrote about giving Claude Code a poisoned GitHub issue, twice. The short version: cleimesh guard runs as a Claude Code hook, remembers what the session has read, and once the session has read something from outside (an issue, a web page, a curl), the push, the secret and the pipe to the network wait for a person. In the run where the model obeyed the injection, the attacker's server got zero requests.

A day later, a reader named reidmarlow left a comment I've been thinking about since:

A useful next test would be an allowed local command that can itself invoke a shell or read arbitrary files.

He was right, and it was worse than a probe.

The hole

Once tainted, the guard still lets the agent work: it can edit files in the project, and it can run a short list of commands, builds and tests among them, because an agent that can't run cargo test is useless. Both rules are reasonable alone. Together:

Each step passed. Together they leaked .env.

The issue doesn't have to ask for curl at all. It asks for a Makefile target that posts .env, then for make. Step 2 is a write inside the project: allowed. Step 3 is a listed command: allowed. Nothing ever looks at the two together.

The fix: edit code or run it, not both

The guard already keeps per-session state (which receipt tainted the session). Now it also remembers the first file the session wrote after it was tainted. From then on, every listed command that runs project code is refused until a person clears the session: builds, tests, make, anything the user added to the list, and also git commit (hooks can live in the project through core.hooksPath) and cargo fmt (a project's .cargo/config.toml can alias it). Reading and staging the change still work: git diff, git status, git add, cat.

$ make
cleimesh guard: `make` runs project code, and this session has written files
after this session brought in outside content: it may edit code or run it,
not both. A person reviews the change (receipt 019a…).
A person clears it: cleimesh guard clear 6f1c…

The refusal is a signed receipt that names both the read that tainted the session and the write that came after it, so whoever reviews it sees the chain, not just the last step. The test is the attack itself: an_injected_makefile_never_runs.

Then I did what the reader did

The comment's real lesson wasn't the Makefile. It was the method: take each command the guard allows and ask how it becomes a different command. So I did that to every rule, and found six more.

Six more ways around the list, closed

  • Flag values are paths. The guard checked every argument that didn't start with - as a path. grep --file=~/.ssh/id_rsa src starts with -. So does less --log-file=~/.bashrc, which writes.
  • Symlinks. Paths were checked as text. A cloned repository can ship docs/notes.txt -> ~/.ssh/id_rsa; reading it read the key, and writing a link to ~/.bashrc wrote outside the project. Paths are now resolved on disk before the check.
  • Globs. The guard saw cat .e*; the shell runs cat .env. Unquoted globs are refused once tainted.
  • Recursive search. grep -r TOKEN . reads .env without naming it. A recursive search over a directory with a secret under it is refused; grep -r TOKEN src is fine.
  • A listed command, an outside file. make -f /tmp/x.mk or cargo test --manifest-path run code from wherever the earlier curl put it.
  • After a write. git commit and cargo fmt, as above.

All seven fixes are in 0.2.9.

Allowed calls now say why

reidmarlow's second point was about inspection: "recording which rule allowed the command would make a surprising pass as useful to inspect as a refusal." Until now only refusals carried a reason. Every allowed decision now carries the rule that let it through:

"decision": "allowed",
"rule": "allowed when tainted: cargo test"

If something gets through that shouldn't, the receipt says which rule to tighten.

What this doesn't fix

The guard is a hook in front of the agent's tools, not isolation. A command it lets run runs with your rights. Before the session writes anything, make still runs whatever the project already contained, so a hostile repository is a job for a sandbox, not for this. And a closed list of commands will keep having edges; the difference now is that each edge I found is a test, and each decision, allowed or not, is a signed receipt you can check with the public key alone.

Try it

brew install cleitonaugusto/cleimesh/cleimesh   # or: pip install cleimesh / npx cleimesh
cleimesh guard install                          # Claude Code; --agent codex for Codex
cleimesh guard status
cleimesh audit view --receipts ~/.local/share/cleimesh/receipts/claude-code.jsonl

Source, tests and the release's build provenance: github.com/cleitonaugusto/cleimesh.

The most useful thing anyone did for this project last week was try to break it in a comment. If you find another allowed command that turns into a different one, I'd like to hear it, and it will become a test.

šŸ“° Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.