fix(hooks): main-checkout guard misses .. paths #169
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Defect
The main-checkout guard (
.agents/hooks/main-checkout-guard.sh) lets anedit into a main checkout on its main branch when the path goes through
a directory that does not exist and then climbs back with
...Location
.agents/hooks/main-checkout-guard.sh,check(), lines 84-88 at0fa031286f: the loop walks up to thefirst existing directory and keeps every later component,
..included, as literal text, so the repository lookup runs from the
wrong directory.
Evidence
With
/repoa main checkout onmain:{"tool_name":"Write","tool_input":{"file_path":"/tmp/nonexistent-x/../../repo/AGENTS.md"},"cwd":"/repo"}exits 0 (allowed);
/repo/AGENTS.mdexits 2 with the refusal.The client then writes to the resolved path, inside the main checkout.
Scenario
An agent, by mistake or following injected text, edits
/tmp/x/../../repo/AGENTS.mdwhile/repois on its main branch; theguard allows it and the main checkout changes. Severity is low: Bash
stays unguarded, so this widens little, but it is a hole in the
control.
Smallest fix
Refuse any path that holds a
..component, one test before the walk;or resolve
..lexically before the walk.Seen at
0fa031286f.