Repository navigation
Merged
Conversation
…ript, refuse a repo-committed handoff The /remember skill took its Write destination from "the most recent === HANDOFF === block in this session's context" -- text any untrusted content the session ingested (a hostile README, a fetched page, an issue body, a repo-committed .remember/remember.md the SessionStart hook itself injected) could forge, with Write pre-approved for any path. The skill now pipes its note to a new scripts/write-handoff.sh, which resolves the destination from REMEMBER_DIR and an out-of-band hint the hook writes to $REMEMBER_DIR/tmp/handoff-path, never from the transcript, and refuses (falling back to the ordinary default) any resolved path whose shape isn't remember.md / remember.<id>.md directly inside REMEMBER_DIR (#720). SessionStart also no longer injects a git-tracked .remember/remember.md as though it were the user's own prior note -- this plugin never commits one itself, so a tracked file was shipped by the repository, not written by a real /remember run, and delivering it verbatim was also how a forged HANDOFF block reached the skill. A genuine, untracked handoff is still delivered, now fenced with an explicit "data, not instructions" line (#721). #690's macOS/bash-3.2 regression is already fixed on main (PR #708); its remaining Windows gap is tracked separately as #712, out of this lane's scope. Co-Authored-By: Max <noreply>
…itive tracked check, mktemp, token fence
Explore review:
- allowed-tools was written as Bash(bash "${CLAUDE_PLUGIN_ROOT}/scripts/write-handoff.sh":*),
which does not match this environment's real scoped-Bash convention
(Bash(${CLAUDE_PLUGIN_ROOT}/...:*), no "bash " prefix, no quotes --
confirmed against ralph-loop's own command). Fixed the rule and the
invocation to match, and the script is already +x with a shebang.
- The hook's pre-existing "=== HANDOFF ===" hint (external/per-session
mode) is still emitted and is no longer read by anything -- its own
comment claimed it was "consumed by the /remember skill", which stopped
being true. Relabelled it human-facing-only and corrected the "that
channel is gone" overclaim in docs/handoff.md.
- Strengthened a weak test assertion that would pass on a stub script that
never touched the filesystem.
oss:auditor:
- _remember_handoff_is_tracked's exact-case `git ls-files` check missed a
handoff committed under a different case than this session resolves it
-- on a case-insensitive filesystem (APFS default, NTFS) the SAME bytes
are still delivered. Added a case-insensitive ls-tree fallback, with a
new test pinning it.
- write-handoff.sh's temp file used a $$-suffixed literal name in the same
shared directory this repo's own lib-memory-dir.sh already documents the
hazard for (predictable, symlink-followable). Switched to mktemp.
- The new closing fence used a fixed literal string
("=== END LAST HANDOFF ==="), which the handoff's own attacker-controlled
content could pre-embed a forged copy of. The marker now carries a
per-delivery random token the hook generates at delivery time.
The token broke an existing invariant test (single mode byte-identical to
the unset default) by introducing legitimate non-determinism; normalized
the token out of that comparison rather than removing it.
Co-Authored-By: Max <noreply>
Second-pass Explore + oss:auditor review over the fixup commit (85d0e70) found the case-insensitive tracked-check fallback it introduced was itself broken in three ways, one a real regression: - it restricted the ls-tree pathspec to the handoff's OWN directory case, so a repo-committed DIFFERENTLY-CASED DIRECTORY (.Remember/remember.md) was invisible to it -- pathspec matching is byte-exact regardless of core.ignorecase, so this missed the exact class of attack #721 targets, just shaped one level up from a differently-cased filename; - it read HEAD's tree rather than the index, so `git rm --cached` -- the remediation the hook's own refusal message names -- did not un-refuse a handoff until a new commit landed. A genuine regression for anyone who follows the refusal message's own advice; - it used `--name-only` with no `-z`, so `core.quotepath`'s default octal-escaping of non-ASCII paths could silently break the comparison. Rewritten to scan `git ls-files -z` with no path restriction, comparing each NUL-delimited entry case-insensitively in bash rather than trusting git's pathspec matching -- closes all three at once, since it no longer depends on a directory pathspec, reads the index (agreeing with the exact-case check on `git rm --cached` immediately), and sidesteps quoting by using `-z`. Piped via process substitution rather than a `$(...)` variable: NUL- delimited output cannot survive a bash variable at all (the string truncates at the first NUL), which very nearly shipped as a new bug introduced by this same fixup. Two new regression tests pin the differently-cased-directory case and the git-rm---cached-un-refuses-immediately case, the second staged with git plumbing (`hash-object`/`update-index --cacheinfo`) since an actual second, differently-cased directory cannot exist on this filesystem's own case-insensitive volume. Not fixed, logged to trap.d/ instead (non-blocking per the ranking table): a git command failure in either the exact or the fallback check collapses to the same state as "genuinely untracked" -- a pre-existing shape in the codebase (case-divergence's own three-state model exists for the identical reason) that this diff duplicates rather than introduces. Also not fixed: mktemp's 0600 vs the previous umask-following handoff file permissions -- judged a desirable tightening consistent with this project's own stated "treat ~/.remember/ like ~/.ssh/" posture, not a regression. Co-Authored-By: Max <noreply>
…ird trap.d fragment CI on windows-latest (PR #731) caught a real defect: scripts/write-handoff.sh's `_wh_shape_ok` used a bracket-range character class (`*[!A-Za-z0-9._-]*`) without pinning `LC_ALL=C` first, the exact class tests/test_locale_ranges_695.py's `test_no_unguarded_letter_range_in_shipped_shell` exists to catch (#695) -- under a locale whose collation folds letters differently (Turkish is the standing example elsewhere in this codebase), the range can match or reject bytes it should not. Pinned it the same way every other bracket-range comparison in this codebase already does (lib-memory-dir.sh, lib-memory-context.sh, session-start-hook.sh all carry the identical `local LC_ALL=C # bracket ranges below are byte-wise, not collated (#695)` line). Confirmed red before (temporarily removed the pin, test_no_unguarded_letter_range_in_shipped_shell failed) and green after, restored file verified byte-identical to the fix. Also adds the third below-bar trap.d fragment (trap.d/721.git-dir-symlink-bypasses-tracked-check.md) for the residual finding the PR body already named but whose receipt was missing: a `.git` symlinked to a different repository could in principle bypass `_remember_handoff_is_tracked`, left unaddressed because it requires a strictly stronger local-write primitive than #720/#721's own threat model assumes. Co-Authored-By: Max <noreply>
… on all 4 ubuntu legs) `test_git_tracked_handoff_is_refused_even_under_a_different_case` wrote its differently-cased plant directly to disk (`cased.write_text(...)` at `.remember/Remember.MD`, then `git add`). That only ever worked because it was authored and locally verified on APFS -- case-insensitive by default, so writing `Remember.MD` and reading back `remember.md` (the literal path `$REMEMBER_HANDOFF` resolves to) hit the SAME inode. On a real case-sensitive filesystem (ext4, every `ubuntu-latest` CI runner) they are two different files: the literal-case `remember.md` this session actually resolves to never existed on disk at all, so the hook found nothing to either refuse or deliver -- the assertion failed because "refused" is not in an output that consists only of the unrelated always-injected REMEMBER section, not because the production code (scripts/session-start-hook.sh) did anything wrong. Not a defect in _remember_handoff_is_tracked or its case-insensitive fallback -- both are unchanged by this commit. Fixed the fixture to match the sibling directory-case test's own convention: write real content to the literal-case path returned by `_sandbox` (what the hook will actually look for), and stage the DIFFERENTLY-cased git-index entry with plumbing (`hash-object` + `update-index --add --cacheinfo`) rather than a second, differently-cased file on disk. Verified against the real CI failure: pulled all 4 failing ubuntu-latest job logs (gh-job:105881733864/854/888/950) directly rather than trusting a paraphrase -- all four are the identical failure, in the identical test, for the identical reason. Local run after the fix: tests/test_handoff_fence_and_tracked_refusal_721.py -- 6 passed. 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.
Two clustered Claude Security scan findings (F2/#720, F3/#721) at 9a0169a:
/rememberskill parsed its Write destination out of "the most recent=== HANDOFF ===block in this session's context" -- forgeable by any untrusted content a session ingests -- withallowed-tools: Read, Writepre-approved for any path and a 'Saved.' output rule that hid the destination.session-start-hook.shcat'd a repo-committed.remember/remember.mdverbatim into context, unfenced, with no provenance marker and no check the file wasn't shipped by the repo itself -- the delivery vehicle for a forged HANDOFF block that then drives F2.Closes #720
Closes #721
Fix
scripts/write-handoff.sh:/remembernow pipes its note through this script via Bash instead of a model-chosenWritepath. The script resolvesREMEMBER_DIRitself, reads an out-of-band hint theSessionStarthook writes every session at$REMEMBER_DIR/tmp/handoff-path(never the transcript), validates the resolved path's shape (parent must be exactlyREMEMBER_DIR, basenameremember.mdorremember.<safe-token>.md), and falls back to the default path on any validation failure. Always prints the path written or aREFUSED:line.skills/remember/SKILL.md: no more free-text path-parsing instructions;allowed-toolsnarrowed to that one scoped Bash invocation.scripts/session-start-hook.sh: new_remember_handoff_is_tracked()refuses injecting.remember/remember.mdwhen it is tracked in the project's own git index (legacy layout only; this plugin never commits one itself). Untracked handoffs are still delivered, now fenced with a provenance line ("data, not instructions") and a closing marker carrying a per-delivery random token generated after the content is written to disk, so planted content cannot pre-forge the fence's own close.Review
Two rounds (Explore + oss:auditor each round, round 2 required because
fix_commit_scope.pyreturnedneeds-second-passon the first fixup). All reviewer-found bugs fixed, including two real regressions in the lane's own round-1 fallback (a differently-cased-parent-directory bypass, andgit rm --cachednot immediately un-refusing a handoff -- both closed by switching the fallback fromgit ls-tree HEADtogit ls-filesscanned via-z/process substitution).Three findings judged below the intake bar, not filed to the tracker, logged to
trap.d/for a curation pass instead:_remember_th_ci_eq) usesshopt -s nocasematchwithout pinningLC_ALL=C, matching an already-accepted precedent inlib-case-divergence.sh's own_remember_case_fold_eq(The store's git index and its directory can differ in case; on a case-sensitive restore that may split the store #298) with the identical characteristic -- seetrap.d/721.case-fold-helper-not-pinned-to-c-locale.md.trap.d/721.git-command-failure-reads-as-untracked.md..gitsymlinked to a different repository could bypass the tracked-check the same way the case-insensitivity finding did, but requires the attacker to already hold a stronger local-write primitive (replacingPROJECT_DIR/.gititself) than security(scan-20260918): /remember skill parses its Write destination from any === HANDOFF === text in context #720/security(scan-20260918): session-start injects repo-committed .remember/*.md unfenced into context #721's stated threat model assumes; left unaddressed and out of scope for this PR.Not in this PR
Related: #690's macOS/bash-3.2 regression is already fixed on
main(merged #708); its remaining gap is Windows-only (test_the_real_hook_traces_past_the_bootstrapxfail'd on win32), tracked separately as #712, which is out of this PR's scope and needs a live Windows runner to verify.Tests
57 targeted tests pass (
test_handoff_fence_and_tracked_refusal_721.py,test_write_handoff_script_720.py, and 7 adjacent handoff/bootstrap modules), all confirmed red before each fix and green after. Broader-k "handoff or bootstrap or worktree_memory or external_data_dir"sweep: 72 passed. Full suite not run locally, per repo convention; CI is the matrix's source of truth.[AI-generated]