Skip to content

Reject a leading dash in post-tool-hook.sh's session_id guard (#610) - #611

Merged
fdaviddpt merged 3 commits into
mainfrom
fix/610
Sep 7, 2026
Merged

fdaviddpt merged 3 commits into
mainfrom
fix/610

Conversation

@fdaviddpt

@fdaviddpt fdaviddpt commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

What

post-tool-hook.sh's STDIN_SESSION_ID guard (the case pattern at what is now
post-tool-hook.sh:419-421) never excluded a leading dash -- the same character-class gap
already closed at two sibling call sites, #576 (agy-stop-hook.sh, merged) and #600
(session-end-hook.sh, PR #609, not yet merged as of this PR). A crafted PostToolUse
payload with session_id: "--dry" paired with a real, existing transcript_path passed the
guard untouched, was trusted by the STDIN_SESSION_ID_TRUSTED branch (which verifies only that
some transcript_path was given, never that this session_id names it -- an established #468
trust decision, see "Judgment call" below), and reached save-session.sh's argv on the
background nohup save path as nohup "$SAVE_SCRIPT" "$SESSION_ID" ... &. save-session.sh's
own arg loop reads a leading-dash value as the --dry FLAG rather than a positional session id.
With no other positional arg, save-session.sh's own auto-detect then correctly identifies the
real session from its transcript directory -- so the exploit's damage is not misattribution, it
is DRY_RUN silently true: no summary written, no position advanced, and nothing about the hook's
own exit code (always 0; it only forked a background process) reveals it.

Fixes #610.

Judgment call (issue explicitly asked this be stated)

Chose to close only the guard-level gap (adding -* to the case pattern), mirroring #576/#600
exactly. Did not strengthen the STDIN_SESSION_ID_TRUSTED branch to positively verify the
session_id names the resolved transcript. Reasoning: STDIN_TRANSCRIPT_PATH is independently
existence-checked before it can be trusted at all, and once the leading-dash class is closed the
residual risk is a misattribution (a well-formed but wrong session_id paired with a real
transcript_path for a different session) rather than an argv-injection -- a materially
different, already-documented #468 trust decision (pipeline/host.py's docstring,
tests/test_transcript_path_trust_431.py) that this fix deliberately does not reopen.

TDD

Red (before the fix, exploit test failed): session_id="--dry" with a real transcript reached
the === DRY RUN === banner in save-session.sh's own log -- 1 failed, 1 passed (exploit
failed, positive control passed).

Green (after the fix): 2 passed. The positive control (an ordinary session_id) independently
proves the harness reaches a real Haiku spawn via a faked claude binary (same technique
tests/test_spawn_containment.py already uses), so the exploit assertion is not passing merely
because nothing ran.

New fixture note: an artificial transcript_path that does not live under the real Claude Code
session directory makes save-session.sh's own session-id auto-detect fail outright ("invalid
session ID") rather than reproduce the silent dry-run -- the working fixture places the
transcript at the correct, real session-directory location, which is also the realistic shape a
genuine payload's transcript_path always has.

Self-review (both findings fixed in a second commit)

Docs / changelog

  • changelog.d/610.fixed.md added.
  • docs/windows-skip-triage.md: added a row for the new test module's win32 skip (bash
    subprocess dependency, same reason/verdict as its sibling tests/test_post_tool_session_id.py
    it is modeled on).
  • README.md (docs_targets): grepped for session_id/transcript_path/dry run/guard-related
    content; no user-facing documentation of this internal guard's security guarantee exists to
    update -- no change needed.

Not run

The repo's full pytest suite was not run locally (per policy: CI is the gate across the whole
matrix; only the targeted new test file plus its closest sibling
(tests/test_post_tool_session_id.py) and the changelog-fragment/windows-skip-triage
self-checks were run here).

Closes #610

🤖 Generated with Claude Code

Verified by the maintainer

This PR's own new docs/windows-skip-triage.md table row (added above) pushed a pre-existing
prose-vs-table drift in that same file one row further out of sync (#612 tracks the original
instance, caused by two earlier PRs -- #605 fixing #595, #606 fixing #596 -- each merging green
against its own stale base). CI caught it on this PR (windows-latest, py3.11:
tests/test_windows_skip_triage_prose_totals_595.py), and I resumed the dispatched agent
(commit 49ad889, same branch) to re-derive the four prose totals directly from the table and
fix them in place, rather than dispatching a fresh lane for what was already this lane's own
file. Independently confirmed the root-cause chain via git merge-base --is-ancestor and by
reading docs/windows-skip-triage.md's own git history (7819c5e, d5123ee) before resuming
the lane, and re-read the follow-up commit's diff before pushing it.

Filed #613 for the recurring pattern behind this (prose duplicating a table's own counts,
drifting on every PR that is not rebased past the last one to touch the table) -- this PR and
#612 fix one more instance of it, not the underlying design.

[AI-generated]

fdaviddpt and others added 3 commits September 7, 2026 01:45
STDIN_SESSION_ID reaches save-session.sh's argv on the background nohup
save path (`nohup "$SAVE_SCRIPT" "$SESSION_ID" ... &`), and that script's
own arg loop reads a leading-dash value as a FLAG rather than a
positional session id -- the character class this guard applied
(`[!A-Za-z0-9._-]`) already allowed a leading dash, so a session_id
shaped exactly like "--dry", paired with a real transcript_path, passed
through untouched and was trusted by the STDIN_SESSION_ID_TRUSTED branch
(which verifies only that a transcript_path was supplied, not that this
id actually names it -- an established #468 trust decision this fix does
not revisit). save-session.sh's own auto-detect fallback then correctly
identified the real session from the transcript_path, but with DRY_RUN
silently true: no summary written, no position advanced, log line reads
like an ordinary run. Third call site in this class, after #576
(agy-stop-hook.sh) and #600 (session-end-hook.sh).

A new end-to-end fixture drives the real post-tool-hook.sh and reaps the
forked save-session.sh, pinned red against the unpatched guard (the "===
DRY RUN ===" banner reaching the autonomous log for a crafted
session_id) and green after, with a positive control proving an ordinary
session_id still produces a genuine save.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
Self-review (Explore) caught the new test's docstrings/messages citing
pre-comment-insertion line numbers for post-tool-hook.sh (off by +15,
the exact width of the #610 rationale comment this same commit inserted).
Corrected to the actual committed line numbers: the guard case statement
at 419-421 (was cited 404-406), STDIN_SESSION_ID_TRUSTED at 564-576 (was
549-557), and the nohup dispatch at 908 (was 893).

Audit (oss:auditor) caught a second, more substantive overclaim: the
original commit message, changelog fragment and test docstring described
#576 and #600 as both "already closed" siblings. #576 (agy-stop-hook.sh)
is merged into this branch's history; #600 (session-end-hook.sh, PR #609)
is not -- `git merge-base --is-ancestor 511e3d3 HEAD` fails, and #609 is
still open. session-end-hook.sh in this tree still carries the pre-#600
vulnerable pattern; that is a fact about an unmerged sibling PR, not
something this commit introduces or is responsible for fixing, but this
commit's own prose should not have implied it was already fixed.

Both are documentation-only corrections: the guard fix and its test's
assertions are unchanged and still pass (2 passed).

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
…ne row further by #610

CI on PR #611 (windows-latest, py3.11) failed in
tests/test_windows_skip_triage_prose_totals_595.py: this PR's own new row
(tests/test_post_tool_dry_flag_injection_610.py) grew the table to 104
rows / 84 unclear, but four prose sentences elsewhere in the doc still
cited the pre-existing stale totals (102 / 82) -- a pre-existing drift
already filed as #612 (two earlier PRs, #605 and #606, each merged green
against their own base and left the prose one row further behind), which
this PR's own table addition made one row worse and is why the failure
surfaced specifically on this branch.

Re-derived the correct totals directly from the table itself (104 total
rows, 84 unclear, 8 convertible, 12 not-convertible -- the latter two
already matched) rather than trusting any externally-reported numbers,
and updated all four prose citations: "## The count: 104, not 107",
"finds **104** modules", "not that read. 84 modules.", "bulk of these
104 reasons". Confirmed against the live table rather than assumed.

tests/test_windows_skip_triage_prose_totals_595.py: 3 failed, 2 passed
before this fix (confirmed locally); 7 passed (that module plus its
sibling table-diff guard, test_windows_skip_triage_497.py) after.

This also resolves the concern #612 was filed for -- the prose now
matches the table exactly, with no residual drift.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c
@fdaviddpt
fdaviddpt merged commit 7e664c0 into main Sep 7, 2026
16 checks passed
@fdaviddpt
fdaviddpt deleted the fix/610 branch September 7, 2026 00:34
fdaviddpt added a commit that referenced this pull request Sep 7, 2026
…) (#615)

The doc restated four of its own table's counts (total module count, three
times; convertible/not-convertible/unclear verdict counts, once each) as
free prose next to the table that already carries them as structured data.
A reactive test (#595) caught a mismatch after the fact, but the numbers
still drifted three times in quick succession (#595, #596, a follow-up on
#611) -- each time because a PR adding one table row was reviewed and
merged green against its own stale base, before a sibling PR's prose fix
had landed. A same-PR test cannot see a drift introduced by a different
PR's base.

This removes the class rather than the next instance: the prose numbers are
deleted, so the table is the only place any of these counts live and there
is nothing left for a PR to leave out of sync. The old reactive test
(tests/test_windows_skip_triage_prose_totals_595.py) is replaced by
tests/test_windows_skip_triage_no_stale_prose_counts_613.py, which guards
against one of these numbers creeping back into the prose by hand, with a
positive control proving the detector still fires on #595's own original
sentences.


Claude-Session: https://claude.ai/code/session_01P9WexZb39yUjQgJ53Zmf1c

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

post-tool-hook.sh: STDIN_SESSION_ID guard gap lets a flag-shaped session_id reach save-session.sh's argv (same class as #576/#600)

1 participant