Skip to content

fix(#799): refuse a symlinked-ancestor handoff target on write, not only on read - #800

Merged
fdaviddpt merged 2 commits into
mainfrom
fix/799
Sep 26, 2026
Merged

fdaviddpt merged 2 commits into
mainfrom
fix/799

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

write-handoff.sh's #750 tracked-target guard refused only the tracked and unavailable states returned by _remember_file_tracked_state_into. That helper also returns symlinked-ancestor, which the read-side guard (_remember_may_inject) already refused -- so a repo that committed .remember as a symlink could have /remember write straight through it while reporting success, the same "reports success, then silently refuses on read" shape #750 was meant to close.

Closes #799

What changed

  • Added a single shared list, _REMEMBER_REFUSED_TRACKED_STATES, and a helper _remember_tracked_state_is_refused() in scripts/lib-memory-context.sh.
  • scripts/write-handoff.sh now gates on that helper before its refusal case, covering tracked, unavailable, symlinked-ancestor, and a defensive default that also refuses.
  • Self-review (two independent spawns against the first commit) converged on the same finding: the read-side guard, _remember_may_inject(), still carried its own independent copy of the same three-state case ending in an unconditional allow-through default -- meaning a future state added to the shared list without also touching that second case would make the read side the one that silently let it through. Fixed in the same PR: _remember_may_inject() now gates on the same shared helper first, keeps its existing user-facing messages, and fails closed on an unrecognised state instead of falling through to allow it.
  • A second, lower-severity review finding -- the new symlink test's blanket Windows skip restates a rationale this repo has separately documented elsewhere as stale -- is not fixed here: it touches a sibling test file outside this diff's blast radius and the correct guard shape needs a design call. Logged to trap.d/799.windows-skip-reason-stale.md rather than fixed here.

Testing

TDD: a new test class plants .remember as a symlink to an outside directory and asserts refusal plus that the file is never created through the symlink, paired with a positive control (an ordinary untracked .remember, still written). Before the fix this failed (script wrote through the symlink and exited 0); after, tests/test_write_handoff_tracked_target_750.py plus the adjacent guard/locale suites are green (34 tests after both commits). bash -n scripts/lib-memory-context.sh passes. The full pytest suite was not run, per this repo's convention of running it locally on demand rather than as a merge gate.

🤖 Generated with Claude Code

[AI-generated]

fdaviddpt and others added 2 commits September 26, 2026 18:47
…de too

write-handoff.sh's #750 tracked-target guard refused a `tracked` or
`unavailable` target but fell through silently for `symlinked-ancestor` --
a state the read-side injection guard (_remember_may_inject,
lib-memory-context.sh) already refuses. A repository could commit
`.remember` as a symlink pointing anywhere its author chose, and
/remember would write straight through it while reporting success,
reproducing the "reports success, then silently refuses on read" shape
#750 was meant to close.

Fix: extract the refused-states list into
_REMEMBER_REFUSED_TRACKED_STATES + _remember_tracked_state_is_refused()
in lib-memory-context.sh, a single source of truth both guards consult,
and have write-handoff.sh's case use it instead of its own independent
copy of the list.

TDD: tests/test_write_handoff_tracked_target_750.py gains
TestSymlinkedAncestorIsRefused (planted symlinked .remember, plus a
positive control that an ordinary untracked target is still written).
Red: 1 failed, 3 passed (script wrote through the symlink, exit 0).
Green: 4 passed. Adjacent read-side and repo-wide scanner tests
(test_injection_guard_ancestor_symlink.py, test_locale_ranges_695.py)
re-run green, 9 passed.

Observed on macOS; symlink handling on Windows Git Bash is not exercised
by this suite (reasoned, not observed), consistent with the existing
platform skip on this test file.

Changelog fragment added; README has no write-handoff/symlink content,
no-change-needed.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…state list

Self-review (Explore and oss:auditor, spawned independently, converged on the
same finding): the previous commit's _REMEMBER_REFUSED_TRACKED_STATES /
_remember_tracked_state_is_refused() in lib-memory-context.sh was only wired
into write-handoff.sh. _remember_may_inject (the read-side guard) kept its own
independent, hand-written case over the same three states, with an
unconditional `(*) return 0` default -- the exact "two lists that can drift"
hazard #799 fixed on the write side, just left standing on the read side, and
in the more dangerous direction (a future unmatched state would be silently
INJECTED, not silently written).

Fix: _remember_may_inject now gates on _remember_tracked_state_is_refused
first, keeping its existing per-state messages, with a new default arm that
refuses (fails closed) any refused state the inline case does not separately
name -- mirroring write-handoff.sh's own defensive default arm.

Verified: full read-side + write-side guard suites re-run green (34 passed):
test_write_handoff_tracked_target_750.py, test_injection_guard_ancestor_
symlink.py, test_injection_guard_754_755_756.py, test_locale_ranges_695.py.
No behavior change for the three states that exist today (tracked,
unavailable, symlinked-ancestor all still refused, everything else still
delivered) -- confirmed by these suites, not just reasoned.

A second, non-blocking self-review finding (the new test's Windows skip
reason is stale, mirroring an already-documented issue with a sibling test
file's identical blanket skip) is logged to trap.d/799.windows-skip-reason-
stale.md rather than fixed here -- it touches files outside this diff's
blast radius and needs a design decision on how to narrow it.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@fdaviddpt
fdaviddpt merged commit 28a980b into main Sep 26, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/799 branch September 26, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

write-handoff.sh's tracked-target guard (#750) omits the symlinked-ancestor state the read side already refuses

1 participant