fix(hooks): resolve .. in the main-checkout guard #172
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "fix/guard-dotdot"
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?
Why
The main-checkout guard let an agent write into a main checkout on its
main branch when the path climbed back with
..through a directorythat does not exist, such as
/tmp/x/../../repo/AGENTS.md, while itrefused the same file named directly. A mistaken path join or injected
text was enough to change the checkout
AGENTS.mdkeeps as it was.Fixes #169.
Refusing every path with
..was weighed and set aside: it would alsorefuse edits the guard passes today, such as
../sibling/xfrom alinked worktree.
What changed
The guard now resolves
.and..in the part of the path that doesnot exist yet, where every name is a missing directory and so resolves
exactly, and a leading
..climbs from the existing directory as thekernel does. It then looks the repository up where the path really
lands, so both paths above are refused. Empty names from a doubled
slash are dropped first, so
missing//../..resolves the same way.Paths that do not land in a guarded checkout pass as before.
How to verify
In a scratch directory, make a repository on
mainand run the guardwith a path that climbs back into it:
The branch prints the refusal and
exit 2; main printsexit 0. Thesame with
outside/missing/../../repo/AGENTS.mdgives the same pair.The source's Maintenance checks pass on the tip:
bash tests/verify-agent-config.sh(321 passed),bash tests/check-work-folder.sh,.agents/hooks/shellcheck.sh repo,prettier --check '**/*.md',scripts/verify-agent-config.sh, andgit diff --check main. The two new cases intests/agent-config/main-checkout-guard.shfail on main with exit 0.How each client normalizes a path before writing was not checked, as
their source is outside the repository.