Repository navigation
fix(#761,#762): fail closed on a symlinked .git; guard non-object .plugins before to_entries - #786
Merged
Merged
Conversation
…ugins before to_entries #761: _remember_config_tracked_status resolved PROJECT_DIR/.git the ordinary way, following whatever it pointed to. A pre-planted symlink swapping it for a DIFFERENT repository's git directory (its own, independent objects and index) would answer the whole tracked-check against that unrelated repo instead of the real one. Now refuses to trust the result (fails closed, same as every other ambiguous case in this function) when the repository's own toplevel .git is a symlink -- a shape neither an ordinary checkout nor a linked git worktree ever produces, so it is only ever a pre-planted swap. #762: the up-front installed_plugins.json probe used to_entries on .plugins, which (unlike the per-candidate query it replaced) does not error on a non-object shape. A JSON array there was silently read as "no installed keys" instead of "cannot tell", firing the plugin promo in exactly the situation the #574 design meant to suppress it in. The probe now checks .plugins' type before calling to_entries, falling back to the same cannot-tell suppression as every other malformed-file case. Both regression tests fail red against the pre-fix code and pass green after. tests/test_case_divergence_298.py's sanctioned-divergence pair for lib-memory-dir.sh is folded forward to the #761 shape, per the #734/#746 precedent already used there. Co-Authored-By: Claude Sonnet 5 <[email protected]>
…ing in test Self-review findings on 88b6bde: - scripts/lib-memory-dir.sh's `_remember_config_tracked_status` header comment still claimed "two spawns at most" and described only the `rev-parse --is-inside-work-tree` / `ls-files` pair -- stale after #761 added a third `rev-parse --show-toplevel` spawn on the already-in-a-work-tree path. Comment now names all three. - tests/test_migration_trust_757.py's new symlinked-.git regression test created a directory-target symlink without `target_is_directory=True`, unlike every sibling directory-symlink call in this suite -- flagged as a Windows-portability nit by the audit pass. Matches the established pattern now. Co-Authored-By: Claude Sonnet 5 <[email protected]>
Co-Authored-By: Max <noreply>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this fixes
#761 -- symlinked
.gitbypasses the config tracked-check._remember_config_tracked_status(scripts/lib-memory-dir.sh) resolved.gitthe ordinary way, with no check on what it actually was. A pre-planted symlink at the repository's own toplevel.git, pointing at a different repository (its own independent objects/index), could make the whole tracked-check silently answer against that unrelated repo -- e.g. reporting a genuinely-committed.remember/config.jsonas "untracked" (safe to deliver). Low-priority defense-in-depth: the attacker already needs local write access toPROJECT_DIR/.git, a stronger primitive than #720/#721's own threat model assumed. Fix: after confirmingis-inside-work-tree, resolverev-parse --show-toplevel, and if${toplevel}/.gitis a symlink, fail closed (could-not-tell) rather than proceed to thels-filescheck. A linked git worktree's.git(a plain file with agitdir:pointer, never a symlink) is left untouched -- that shape is already trusted elsewhere (#56) and is not the attack this guards against.#762 -- non-object
.pluginsshape silently reverses the promo probe.scripts/session-start-hook.sh'sinstalled_plugins.jsonprobe used jq'sto_entrieson.plugins, which (unlike the per-candidate query it replaced, #660) does not error on a non-object shape -- a JSON array there was read as "no installed keys" instead of "cannot tell", firing the promo in exactly the situation the #574 design meant to suppress it in. Low-priority/latent: not established whether the real writer (Claude Code core) ever emits.pluginsas non-object under schema version "2". Fix: guard.plugins' type before callingto_entries, falling back to the same cannot-tell suppression as every other malformed-file case.Tests (TDD, red confirmed before each fix)
tests/test_plugin_promo_574.py::TestPromoOnlyWhenNotInstalled::test_non_object_plugins_shape_is_cannot_tell. RED: promo fired on a.pluginsarray (bug reproduced exactly). GREEN: 15/15 in the file, including a positive control (test_positive_control_promotes_when_genuinely_not_installed).tests/test_migration_trust_757.py::TestSymlinkedGitDirFailsClosed, two tests -- a symlinked-.git-to-an-unrelated-repo case (drives the real migration flow, not a mock) and a positive control (test_an_ordinary_untracked_git_dir_still_migrates). RED: the config migrated away because the tracked-check answered against the wrong repo's index. GREEN: both pass; ran together with the sibling migration/case-divergence/promo test files = 82 passed.tests/test_case_divergence_298.py's byte-pin allowlist forscripts/lib-memory-dir.shwas folded forward (its staleold_codehalf replaced with the code currently onorigin/main,new_codeextended with the _remember_handoff_is_tracked resolves PROJECT_DIR/.git the ordinary way -- a pre-planted symlink/gitdir pointer answers against a different repository (out of #720/#721's own threat model) #761 addition), following the existing main is red at 7ba7609 (#732): stale _SANCTIONED_DIVERGENCE entry in test_case_divergence_298.py for lib-memory-dir.sh's elif/python branch #734/test: drop the #726 sanctioned-divergence pair #744 stranded on main #746 fold precedent in that same file.Changelog and docs
changelog.d/761.security.mdandchangelog.d/762.fixed.mdadded; assembler run clean (--checkpass).README.md(this repo's onlydocs_targetsentry) checked against both fixes -- no change needed, the documented promo contract and the tracked-check's internal shape are both unaffected in wording.Self-review
Two reviewers spawned (Explore, oss:auditor), tree confirmed unmutated before/after. One finding each, both fixed in commit ef3b1d2: a stale docstring undercounting
_remember_config_tracked_status's spawn count, and a missingtarget_is_directory=Trueon a directory symlink in the new #761 regression test (platform nit, reasoned not observed -- no Windows access to confirm either way, branch unpushed so no CI run exists yet).Note on #745
The original task also carried #745, which turned out to already have a complete, committed fix sitting unpublished in a sibling worktree (
fix/745, commits fc4e65f/38638fc/d14565c/acca67e, no PR open). This pull request does not touch #745 or duplicate that work.Closes #761
Closes #762
🤖 Generated with Claude Code
[AI-generated]