Skip to content

fix(#761,#762): fail closed on a symlinked .git; guard non-object .plugins before to_entries - #786

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/761-762
Sep 26, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/761-762

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

What this fixes

#761 -- symlinked .git bypasses the config tracked-check. _remember_config_tracked_status (scripts/lib-memory-dir.sh) resolved .git the 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.json as "untracked" (safe to deliver). Low-priority defense-in-depth: the attacker already needs local write access to PROJECT_DIR/.git, a stronger primitive than #720/#721's own threat model assumed. Fix: after confirming is-inside-work-tree, resolve rev-parse --show-toplevel, and if ${toplevel}/.git is a symlink, fail closed (could-not-tell) rather than proceed to the ls-files check. A linked git worktree's .git (a plain file with a gitdir: 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 .plugins shape silently reverses the promo probe. scripts/session-start-hook.sh's installed_plugins.json probe used jq's to_entries on .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 .plugins as non-object under schema version "2". Fix: guard .plugins' type before calling to_entries, falling back to the same cannot-tell suppression as every other malformed-file case.

Tests (TDD, red confirmed before each fix)

Changelog and docs

changelog.d/761.security.md and changelog.d/762.fixed.md added; assembler run clean (--check pass). README.md (this repo's only docs_targets entry) 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 missing target_is_directory=True on 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]

fdaviddpt and others added 3 commits September 26, 2026 03:16
…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]>
@fdaviddpt
fdaviddpt merged commit 0be67b5 into main Sep 26, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/761-762 branch September 26, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant