Repository navigation
fix(hooks): simplify-ignore only touches paths inside the project - #648
Sunil56224972 wants to merge 3 commits into
Conversation
The simplify-ignore cache lives in the project tree (.claude/.simplify-ignore-cache), so a cloned repository can ship one. On Stop the hook read <id>.path and, without validation, overwrote that file with <id>.bak, copied its previous contents into the cache as .recovered, or ran mkdir -p and mv next to it. A crafted entry therefore let a repository overwrite ~/.bashrc (or any user-writable file) and pull outside files into the project the first time the hook's Stop event ran. Add inside_project(), which rejects empty or multi-line paths, any .. component, a symlinked final component, and any path whose nearest existing ancestor does not resolve (cd -P) under the physically resolved project root. Windows-form paths are normalised with cygpath on Git Bash. Stop skips and keeps any cache entry that fails the check; Read and Edit|Write ignore files outside the project.
|
issue (blocking): the Stop-side containment is fine as small hardening, but the Read and Edit gating fails open. For a file outside CLAUDE_PROJECT_DIR (an added working directory), an in-project symlink, or on macOS a path that differs only in case, main hides the protected block and this PR shows it to the model. That's a regression in the one thing the hook exists to do. issue (blocking): there are no tests, for a change framed as a security fix. question: as with #455, anyone who can plant a cache file can already edit the hook or its settings, so I don't see a trust boundary being crossed. I'd take this trimmed to the Stop check, with tests, described as hardening. |
|
Addressed in 620a9bb. I removed the Read/Edit containment gate and kept containment validation on Stop-side cache restoration only, preserving the hook's behavior for added working directories and symlink/case variants. The absolute-path and traversal regressions are included. CI is green, including hook regression tests on macOS and Windows. The symlink cases could not be exercised by my local Git Bash environment, so I am relying on the Unix CI run for those. |
|
@addyosmani The blocking feedback is addressed in 620a9bb (details in my comment above). CI is green; ready for re-review when you have a moment. |
|
Thanks for removing the Read and Edit gating and adding tests. I'm closing this one though. The new Stop check brings a different regression in the hook's core job: for a file outside the project dir, an in-project symlink, or a path that differs only in case, Read still hides the block but Stop now refuses to restore it, so the user's file is left with the placeholder on disk and the protected code only in the cache. That's worse than what's being guarded against, and as with #455 I don't see a trust boundary here, since anyone who can plant a cache file can already edit the hook. Two rounds in, the risk outweighs the benefit. Your #649 and #651 were real fixes and I'm glad to have them. |
Problem
hooks/simplify-ignore.shtrusts.claude/.simplify-ignore-cache/<id>.pathblindly. OnStopit runscat "$bak" > "$orig"(orcat "$orig" > "$rewritten",mv "$bak" "${orig}.recovered") for whatever path that file names. The cache lives inside the project, so a repo that ships a.claude/.simplify-ignore-cache/(committed by mistake, or planted in a PR or a cloned repo) controls those writes. The first sessionStopin that project then:~/.bashrc, an autostart entry,~/.ssh/authorized_keys), with attacker-chosen content~/.aws/credentials,~/.ssh/id_ed25519) into the project cache, where the nextgit add -Apicks it upThe
ReadandEdit|Writebranches likewise act on anyfile_path, including files outside the project.#294 adds
-Lchecks on the cache entries themselves. It does not check where.pathpoints, so a plain absolute path or a../path still escapes.Fix
inside_project()accepts a path only if:..componentcd -Pso symlinked parent directories are followed, lies under the physically resolved project root (missing trailing directories are allowed, since a moved file's directory may be gone)On Git Bash/MSYS,
C:\...paths are converted withcygpathfirst.Stopskips and keeps any cache entry that fails the check, so a genuine backup is never destroyed.ReadandEdit|Writeignore files outside the project.Proof
PoC: a planted cache with 10 hostile
.pathvalues (absolute,../, symlinked parent, symlinked file, Windows drive path, outsideRead):bash hooks/simplify-ignore-test.sh: 49 passed, 0 failed (Windows Git Bash and Alpine). The normal Read -> Edit -> Stop round trip is unchanged.PoC script (run:
bash finding1-poc.sh hooks/simplify-ignore.sh)