Skip to content

Fix(policy): Protect targets of protected symlinks - #237

Merged
ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-216
Nov 24, 2026
Merged

ModeSevenIndustrialSolutions merged 2 commits into
lfreleng-actions:mainfrom
lfreleng-bot-forks:code-monkey/issue-216

Conversation

@lf-releng-code-monkey-bot

@lf-releng-code-monkey-bot lf-releng-code-monkey-bot Bot commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Closes #216

Authored by an AI agent; human review required
Command Exit
uv run python -B -m unittest discover -s tests 0
uvx --from gitlint-core gitlint --msg-filename .git/m-d521d2e.txt 0
uvx --from gitlint-core gitlint --msg-filename .git/m-2c78446.txt 0
prek run --files docs/DESIGN.md scripts/proposal_check.py scripts/protected_links.py tests/test_proposal_check.py tests/test_protected_links.py 0

The github-code-monkey-bot workflow 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 in scripts/protected_links.py, with unit tests in tests/test_protected_links.py. End-to-end tests in tests/test_proposal_check.py land first as expected failures. docs/DESIGN.md §8 describes the behaviour.

Antagonistic review

  • Deleting an ancestor of a protected target (scripts/protected_links.py, inline thread). Fixed. A diff names a submodule it deletes, not the paths inside it, so with AGENTS.md -> vendor/rules/instructions.md and a gitlink at vendor/rules, deleting vendor/rules passed. LinkGuard.cause now refuses any path that holds a resolved target, a pinned link or a climbed directory, with a reason like holds 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 as config/instructions behind .github -> config. Editing a gitlink was already refused by check_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.ci was stale, so I ran the hooks locally.
  • gitlint on both commit messages: clean.

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread scripts/protected_links.py Resolved
Comment thread scripts/protected_links.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two critical symlink-protection gaps allow protected instructions or configuration to change, while unresolved protected-file links lack required target-and-cause diagnostics.

3 open issues

Review effort: Balanced

Comment thread scripts/protected_links.py Resolved
Comment thread scripts/protected_links.py Resolved
Comment thread scripts/proposal_check.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Critical findings show that traversal bounds leave protected configuration descendants editable and the context cap permits millions of queued aliases, risking gigabytes of memory consumption.

2 open issues

Review effort: Balanced

Comment thread scripts/protected_links.py Resolved
Comment thread scripts/protected_links.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The repeated-link check mistakes finite symlink hops for a cycle, leaving protected configuration editable and allowing proposals to change it without rejection.

1 open issue

Review effort: Balanced

Comment thread scripts/protected_links.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Two critical symlink-handling gaps allow protected targets to remain editable when link blobs contain NUL bytes and allow required traversal directories to be removed, leaving AGENTS.md dangling.

2 open issues

Review effort: Balanced

Comment thread scripts/protected_links.py Resolved
Comment thread scripts/protected_links.py Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The security-critical custom symlink resolver and alias propagation require maintainer review to validate filesystem-resolution parity and the operational impact of fail-closed edit blocking.

No open issues 🎉

Review effort: Balanced

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

Comment thread scripts/protected_links.py Resolved
lf-releng-code-monkey-bot Bot and others added 2 commits November 23, 2026 19:59
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 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.

@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions merged commit 504479f into lfreleng-actions:main Nov 24, 2026
36 checks passed
@ModeSevenIndustrialSolutions
ModeSevenIndustrialSolutions deleted the code-monkey/issue-216 branch November 24, 2026 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix(policy): Protect targets of protected symlinks

2 participants