Repository navigation
Merged
Conversation
…tmp path from $$ (#429) Both built a predictable name through an intermediate variable (SYS_TMPDIR, _REMEMBER_ENV_CACHE_FILE) -- the same TOCTOU #427 fixed in doctor.sh, invisible to its class-pin regex because the path goes through a variable rather than a literal. Traced with a live symlink reproduction: lib-memory-dir.sh's merged-config write follows the symlink and delivers the actual merged JSON -- including a live haiku.oauth_token when configured -- to the attacker-chosen target, not just a truncation. Both now use mktemp, matching save-session.sh and #427's fix, with no trailing suffix after the X's (BSD/macOS mktemp only substitutes a run of X's at the very end of the template). test_case_divergence_298.py's byte-pin guard against origin/main now explicitly sanctions this one line. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
…temp fallback The reviewer and auditor spawned against the #429 commit both flagged the same real gap: an empty $_merged_cfg (mktemp itself failing) fell straight into `jq ... > "$_merged_cfg"` with an empty redirect target, a shell-level "ambiguous redirect" error 2>/dev/null cannot suppress -- an edge case the old literal-path code never had, since it always produced a non-empty path string even when that path was unwritable. The merge attempt is now skipped outright when mktemp fails; REMEMBER_CONFIG ends up empty exactly as every consumer already treats a genuinely-absent config file. test_case_divergence_298.py's _SANCTIONED_DIVERGENCE is widened to also cover this if/elif restructuring (still scoped to exactly this one block -- anything else diverging from origin/main still fails the guard), and test_post_tool_hook_spawns.py's POST_TOOL_SPAWN_MEASURED moves 16 -> 17: the mktemp #429 added is a real, necessary, one-time spawn on the resolving path, not a regression to chase back out. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This was referenced Aug 29, 2026
fdaviddpt
added a commit
that referenced
this pull request
Aug 29, 2026
…ives its own merge (#441) * fix: give #429's sanctioned-divergence guard a third state so it survives its own merge (#440) The guard compared origin/main's lib-memory-dir.sh against a keyed old->new allowance and asserted whenever old_code was not found. That was correct while #436 was open and unsatisfiable the moment it merged: origin/main then held new_code, old_code was gone, and the guard failed on the default branch itself. _apply_sanctioned_divergence() now recognizes old-absent/new-present as the post-merge steady state rather than staleness, only asserting when neither side is found. Co-Authored-By: Max <noreply> * fix: keep the new sanctioned-divergence unit tests out of the whole-file Windows skip (#440) Self-review on #440 found that the three new _apply_sanctioned_divergence regression tests, added inside tests/test_case_divergence_298.py, silently inherited that module's whole-file `pytestmark` skip on win32 -- a skip that exists for the file's bash-spawning tests and does not describe these three, which are pure Python string manipulation. Relocated them to a new file, tests/test_sanctioned_divergence_state_440.py, so they actually run on windows-latest CI instead of reporting green while never executing. Co-Authored-By: Max <noreply>
This was referenced Oct 2, 2026
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.
Summary
Fixes #429.
scripts/lib-memory-dir.shandscripts/lib-env-cache.shboth built a shared-tmpdir path through an intermediate variable (SYS_TMPDIR,_REMEMBER_ENV_CACHE_FILE) suffixed with the shell's own$$-- the same predictable-name TOCTOU #427 fixed inscripts/doctor.sh, invisible to #427's own class-pin regex because the path is built through a variable rather than a literal on one line.The central question this issue left open, answered
The issue asked whether the credential-bearing write can actually land at a symlink's target, or whether something intermediate defeats that. Traced with a live reproduction rather than assumed: it lands there. A pre-seeded symlink at the predictable
${TMPDIR:-/tmp}/remember-config-<pid>.jsonis truncated by(umask 077; : > "$_merged_cfg")first, and then the actual merge write that follows (jq -s ... > "$_merged_cfg", or the Python fallback'sopen(out_path, "w")) follows the SAME symlink and writes the real merged config through it -- includinghaiku.oauth_tokenwhen configured. Manual repro, before any test scaffolding existed:This is
disclosesin the release-ranking table, not the milder truncation-only shapedoctor.shhad. The EXIT trap'srm -fafterwards removes only the symlink, never the victim file it pointed at.lib-env-cache.sh's publish-temp path (_t="${_REMEMBER_ENV_CACHE_FILE}.$$") is the same shape without the credential -- disclosed asdisclosesfor lib-memory-dir.sh, and the plain truncation class (same rank as #427) for lib-env-cache.sh.The fix
Both now use
mktemp, matchingsave-session.sh's six existing uses and #427's fix todoctor.sh-- with the X's as the literal LAST characters of the template and no trailing suffix after them. This mattered in practice:mktemp "/tmp/foo-XXXXXX.json"on this developer's macOS (BSD mktemp) silently creates a file named literallyfoo-XXXXXX.json, unrandomized, because BSD mktemp -- unlike GNU -- only substitutes a TRAILING run of X's and leaves anything after them literal with no error. That would have shipped a fix that looked identical to the working GNU form while reintroducing the exact vulnerability.tests/test_predictable_tmp_429.pyis a live symlink-race reproduction: two must-not-fire attack tests (credential lands at the symlink target / env-cache publish temp survives a planted symlink) each paired with a must-fire positive control proving the legitimate write still happens -- including the token -- when nothing interferes.Cross-cutting guards this diff had to widen
The full suite (not the narrow subset) caught two guards a filename-based subset would have missed entirely:
tests/test_case_divergence_298.pypinslib-memory-dir.sh's executable code byte-identical toorigin/main, specifically to catch a silent spawn addition to this hot-path library.mktempis a spawn, so it failed exactly as designed. Widened via an explicit_SANCTIONED_DIVERGENCEsubstitution scoped to exactly the two changed blocks (verified: any OTHER divergence fromorigin/mainstill fails the guard), following the precedent set by commitfd721fc(perf(post-tool): give PostToolUse the #227 env-cache fast path #352) for the same test.tests/test_post_tool_hook_spawns.py's spawn-count budget moved from 16 to 17 measured spawns, documented as the mktemp fix's real, necessary, one-time cost -- not a regression to chase back out.Self-review
Two independent reviewers (Explore + oss:auditor) both flagged the same real bug: the
mktempfailure fallback left$_merged_cfgempty, which fed an empty redirect target tojq ... > "$_merged_cfg"-- a shell-level "ambiguous redirect" error2>/dev/nullcannot suppress, an edge case the old literal-path code never had. Fixed in a follow-up commit: the merge attempt is now skipped outright whenmktempfails, leavingREMEMBER_CONFIGempty exactly as every consumer already treats a genuinely-absent config file.Two more items, not fixed here:
shared_tmpalready exists before the subprocess starts, so the wait never actually spins) -- but the auditor independently verified 30/30 real races caught against a reverted, pre-fix copy of the scripts, so this is not currently a false-pass risk. Tightening it would mean adding a testing hook to production shell scripts for a risk that is not manifesting today.scripts/log.sh:78,392,tests/test_log_sh.py:874andREADME.md:276is no longer accurate now that the merged config gets an unpredictablemktempname rather than one derived from the PID. Not fixed here because it also touchesscripts/post-tool-hook.sh:73,178, a file held by the live lanefix/424.docs_targets
README.md(this repo's onlydocs_targetsentry):not-read-- this is internal hardening of an implementation detail (a temp-file naming scheme) the README never documented (grepped forremember-config-,remember-env-,mktemp: zero hits), so there was nothing to check it against and opening it would not have changed anything about this diff.Test plan
tests/test_predictable_tmp_429.py-- red before the fix (both attack tests failed, both positive controls passed), green aftertests/test_case_divergence_298.py-- green, widened guard verified to still catch any other divergencepython3 .oss/assemble_changelog.py --check-- ok