Repository navigation
Fix(policy): Protect targets of protected symlinks - #237
ModeSevenIndustrialSolutions merged 2 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Critical symlink-protection gaps leave hops unprotected after resolution failures and merge distinct Git paths during decoding, allowing protected instruction targets to be replaced or edited.
2 open issues
What changed in this PR
This PR extends proposal validation to protect targets of symlinks stored at protected paths in the base tree, addressing #216.
Changes:
- Adds bounded base-tree scanning and symlink resolution to identify protected targets and link chains.
- Applies the link guard when checking each proposed commit.
- Documents the policy and adds unit and end-to-end regression tests.
| File | Description |
|---|---|
tests/test_protected_links.py |
Tests link resolution, protected targets, and failure cases. |
tests/test_proposal_check.py |
Adds symlink fixtures and end-to-end policy checks. |
scripts/protected_links.py |
Implements base-tree scanning, resolution, and target protection. |
scripts/proposal_check.py |
Integrates the link guard into commit validation. |
docs/DESIGN.md |
Documents symlink protection and the new module. |
Review effort: Balanced
adb0f2c to
ff7262a
Compare
ff7262a to
0a7c5ee
Compare
0a7c5ee to
92d5ef3
Compare
92d5ef3 to
668f873
Compare
668f873 to
22f00bd
Compare
There was a problem hiding this comment.
🤖 Antagonistic review by agent: 1 finding(s) for the human reviewer.
The resolver covers ordinary symlink chains thoroughly, but ancestor deletion can still bypass protection when a target lies inside a submodule.
Antagonistic round 1 of 3. Revision requested from Code Monkey.
Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.
A protected name the base tree holds as a symlink points at another path, and the check judges that path by its own name, so editing it changes what the protected name means. Add end-to-end tests, marked as expected failures, that the check refuses a change to the target of such a link, to a link on its chain, or to a link it cannot resolve, naming the link; and tests that a link at an unprotected path, or the same edits with no link in the base, stay accepted. Review round 1 adds two more: no link on a loop can be replaced by a file or a directory the protected name would then mean, and two links whose names differ only in invalid UTF-8 bytes each protect their own target. Review round 2 adds three: the link past the eight-link bound cannot become a file, a link inside a linked .claude counts under the .claude name too, and deleting an unresolvable protected file link names its target and why it cannot be resolved. Review round 3 adds two: a file cannot change under the target of a .claude chain past the eight-link bound, nor under a link reached through nine directory links. Review round 4 adds one: a file cannot change under the target of a .claude link whose finite chain follows the link a -> . nine times. Review round 5 adds two: a file cannot be deleted from a directory a protected link climbs out of with .., and a base tree whose protected link target holds a NUL byte refuses the proposal. Antagonistic review round 1 adds one: a proposal cannot delete a submodule that holds a protected link's target. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
A protected name the base tree holds as a symlink points at another path, which the check judged by its own name, so a proposal could change what AGENTS.md or the zizmor configuration means by editing the target. The check now lists the base tree once, resolves each symlink that is protected or stands for a protected directory, and refuses a change to its target, to a link on its chain, to the link itself, or to a path under a linked directory that would be protected under the link's name, naming the link. A link inside such a directory's target counts under that name too. A link that leaves the repository, loops or passes eight links makes any change to it, to each link reached before resolution failed, or to its first path a rejection. The rules live in a new module, protected_links.py, with its own unit tests, so proposal_policy.py and proposal_check.py stay within the aislop file-size limit. Review round 1: - Pin symlink hops reached before resolution fails: a failed resolution pinned only the link and its first path, so in AGENTS.md -> a.md -> b.md -> a.md the link b.md could be replaced by a file, or a looping .claude repaired into a directory. LinkError now carries every link followed, and each is pinned. - Preserve byte identity when decoding Git paths: tree names and link targets were decoded with "replace", merging two links whose names differ only in invalid UTF-8. They now use surrogateescape. Review round 2: - Pin the link past the chain bound: in AGENTS.md -> a1 -> ... -> a8 -> target.md the bound refused a8 before recording it, so a8 could be replaced by a file. The link is now recorded first, and the first path of every link reached is pinned, target.md included. - Keep every name a link is reached by: links were deduplicated by path, so with .claude -> config and config/AGENTS.md -> ../settings the .claude name was dropped and settings/options.json stayed editable. Each (link, name) pair now resolves, skipping one whose link already has a name covering everything beneath it, and more than 4096 names reject the proposal, so alias cycles end. - Check the link cause before the name check: deleting an unresolvable AGENTS.md -> ../agents.md gave only the bare name rejection; it now names the link's target and why it fails. Review round 3: - Bound pending work by the context cap: the cap counted names as they resolved, so 4096 links dN/AGENTS.md -> .. could queue about 16.8 million names first. Names are now deduplicated and counted as they are queued, in a deque; each link resolves once, and only links under a resolved target are scanned for nested ones. - Protect descendants past both bounds: with .claude -> a1 -> ... -> a8 -> settings the chain bound pinned only settings, leaving settings/options.json editable, and a link reached through more than eight directory links pinned only its first path. A chain past the bound is now followed until it ends or reaches a link a second time, or refused outright past 4096 links, and its target stays protected under the link's name; a link past the directory-link bound protects its whole target, as does every link inside that. Review round 4: - Tell loops from repeated hops: past the bound, any link reached a second time counted as a loop, so .claude -> a/a/a/a/a/a/a/a/a/ settings with a -> . lost its target and settings/options.json stayed editable. A link reached again is now a loop only when nothing pending at its last expansion has been consumed since, which every endless walk reaches; a finite chain keeps its target. Review round 5: - Protect directories a link climbs out of: a checkout resolves scratch/.. through scratch, so with AGENTS.md -> scratch/../instructions.txt, deleting the last file in scratch left AGENTS.md dangling. Each directory a .. steps out of is now recorded, and any change at or under one is refused, unless a link on the chain lies in it and so holds it in place. - Refuse NUL-bearing link targets: a checkout cuts a target at its first NUL, so AGENTS.md -> docs/guide.md\0ignored points at docs/guide.md while the guard recorded the whole blob. A target read while resolving that holds a NUL now rejects the proposal. Antagonistic review round 1: - Protect paths that hold a protected one: a diff names a submodule it deletes, not the paths inside it, so with AGENTS.md -> vendor/rules/instructions.md and a submodule at vendor/rules the deletion of vendor/rules passed. A path that holds a target, a pinned link or a climbed directory is now refused, and under a linked directory so is a path whose name under the link would hold protected paths, such as config/instructions behind .github. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: lf-releng-code-monkey-bot[bot] <332050256+lf-releng-code-monkey-bot[bot]@users.noreply.github.com>
22f00bd to
be3c525
Compare
There was a problem hiding this comment.
🔵 Needs a closer look
The security-critical symlink and directory-alias resolver warrants independent maintainer validation of its traversal and fail-closed semantics, particularly because project tests and checkout-level validation were not executed.
No open issues 🎉
Review effort: Balanced
There was a problem hiding this comment.
🤖 Antagonistic review by agent: no line-level findings; the summary below is the verdict.
The change appears sound on static review. No actionable defects found in the symlink protection, proposal-check integration, or regression coverage.
Antagonistic round 2 of 3.
Automated antagonistic review by lf-releng-antagonistic-review-bot[bot] using model gpt-6-astra; see the run. This is not a human review and never an approval: a maintainer must still review and approve this pull request.
504479f
into
lfreleng-actions:main


Closes #216
Authored by an AI agent; human review required
claude-opus-5.5via GitHub Copilot CLI9cf16b8cc1c6be0202f572bc0ab8cd1fec11e3ffuv run python -B -m unittest discover -s testsuvx --from gitlint-core gitlint --msg-filename .git/m-d521d2e.txtuvx --from gitlint-core gitlint --msg-filename .git/m-2c78446.txtprek run --files docs/DESIGN.md scripts/proposal_check.py scripts/protected_links.py tests/test_proposal_check.py tests/test_protected_links.pyThe
github-code-monkey-botworkflow opened this pull request.Nobody has merged it; a maintainer must review it first.
Review findings on this pull request are answered by a later revision round of this workflow, up to ten rounds per antagonistic review round; after that a maintainer, or the next antagonistic review, takes on any finding that remains, and a maintainer reviews every round before merge.
Round 6 of revision, on its base. It answers antagonistic review round 1: #237 (review).
Closes #216.
protected()judges a path by its name, so a protected name that the base tree holds as a symlink (AGENTS.md -> docs/guide.md,.claude -> tooling/claude,.github/zizmor.yml -> ../docs/zizmor.yml) could change meaning through an edit to its target. The offline check now lists the base tree once (git ls-tree -r), resolves every symlink that is protected or stands for a protected directory, and refuses a change to its target, to a link on its chain, to the link itself, or to a path under a linked directory that would be protected under the link's name. A rejection reads<path> is protected and cannot change (target of <link>). Links that leave the repository, loop, or pass the bounds (eight links, 4,096 names) fail closed. The rules live inscripts/protected_links.py, with unit tests intests/test_protected_links.py. End-to-end tests intests/test_proposal_check.pyland first as expected failures.docs/DESIGN.md§8 describes the behaviour.Antagonistic review
scripts/protected_links.py, inline thread). Fixed. A diff names a submodule it deletes, not the paths inside it, so withAGENTS.md -> vendor/rules/instructions.mdand a gitlink atvendor/rules, deletingvendor/rulespassed.LinkGuard.causenow refuses any path that holds a resolved target, a pinned link or a climbed directory, with a reason likeholds vendor/rules/instructions.md, target of AGENTS.md. Under a linked directory, it also refuses a path whose name under the link would hold protected paths, such asconfig/instructionsbehind.github -> config. Editing a gitlink was already refused bycheck_change_mode. New tests: one end-to-end test (added to the expected-fail commit) and two unit tests.Checks run
uv run python -B -m unittest discover -s tests: 1789 tests, OK.prek run --files <the branch's changed files>: all hooks passed, including ruff, mypy, basedpyright and aislop.pre-commit.ciwas stale, so I ran the hooks locally.For the reviewer
The ancestor rule is broader than strictly needed: it also refuses a plain file at a path that would be an ancestor of a dangling target. This errs on the side of refusal.