Skip to content

Reject a leading dash in session-end-hook.sh's session_id guard (#600) - #609

Merged
fdaviddpt merged 1 commit into
mainfrom
fix/600
Sep 7, 2026
Merged

fdaviddpt merged 1 commit into
mainfrom
fix/600

Conversation

@fdaviddpt

Copy link
Copy Markdown
Contributor

What

scripts/session-end-hook.sh's STDIN_SESSION_ID guard allowed a leading dash through its
character class (*[!A-Za-z0-9._-]* does not exclude -), so a session_id of exactly --dry on
the SessionEnd hook's stdin payload passed unrejected and reached save-session.sh's argv as
bash "$SAVE_SCRIPT" "$STDIN_SESSION_ID" --force. save-session.sh's own arg-parsing loop reads a
leading-dash value as a FLAG rather than a positional session id — --dry sets DRY_RUN=true,
silently turning the SessionEnd last-chance flush into a no-op dry-run preview: no summary written,
position not advanced, log line reads like an ordinary run.

This mirrors, at a sibling call site, the exact gap issue #576 already closed in
scripts/agy-stop-hook.sh (commit a07f08e) — that fix's own comment noted the session-end-hook.sh
guard did not close this same gap, and it did not, until now.

Fixes #600.

Fix

Adds -* to the case pattern, rejecting any leading-dash session_id (falls back to discovering the
session id from the latest transcript file instead, same as when no session_id is sent at all) —
identical remedy shape to #576's own fix at the sibling call site.

Tests

Added TestFlagShapedSessionIdIsRejected600 to tests/test_session_end_hook_345.py, using the
module's existing harness (_make_env, _wire_hook, _run_hook). Must-fire case drives the hook
with session_id="--dry" and asserts the stubbed pipeline still reaches call-haiku (proving a real
flush happened, not a silent dry-run no-op). Paired must-not-fire positive control proves the
fixture is live with an ordinary session id.

Red (pre-fix): 1 failed, 1 passed —

AssertionError: session_id=--dry must not reach save-session.sh's argv as a flag -- if it does, DRY_RUN=true silently swallows the whole flush
  extract aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee /.../project
assert 'call-haiku' in 'extract aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee /.../project\n'

Green (post-fix): tests/test_session_end_hook_345.py — 9 passed in 3.03s.

test_command (pytest) was not run in full; ran the module's own tests plus checked
lane_setup.py's cross-cutting guards for the touched files (both named guards do not exist in this
repo, so nothing extra applied). CI is the authority for the full matrix.

Docs / changelog

README.md (this repo's only docs_targets entry) read against the fix — still accurate, no change
needed (internal argv-hardening, invisible from the hook-table description). changelog.d/600.fixed.md
added; python3 .oss/assemble_changelog.py --check passed.

Self-review

Spawned Explore and oss:auditor against the committed diff. oss:auditor returned NO FINDINGS
across four checklist classes (silent absence, guard-did-not-run, untrusted-boundary, cross-platform
band). Explore returned one finding:

A third, still-unpatched call site of the identical guard gap exists in scripts/post-tool-hook.sh.
Its STDIN_SESSION_ID guard (lines 404-406) carries the exact pre-#600 pattern, and its
STDIN_SESSION_ID_TRUSTED branch (lines 549-556) only requires STDIN_TRANSCRIPT_PATH to name an
existing file — it never checks that STDIN_SESSION_ID corresponds to that transcript. A payload
with a real transcript_path and a crafted session_id of --dry therefore reaches
nohup "$SAVE_SCRIPT" "$SESSION_ID" ... & (line 893) unrejected, turning every per-tool-call
background save into a silent no-op dry run — same class, same silent-swallow consequence, at a
call site this issue's own brief flagged as an open question ("closed by a different mechanism...
reasoned... not observed to fire live"). Verified by direct code reading: that assumption does not
hold, since the existence check validates the transcript path, not the session id, so it does not
actually close the gap.

Not fixed in this diff, and this paragraph is the pr_anchor for that decision: post-tool-hook.sh
is a different call site with its own more complex trust-boundary logic that needs its own design
decision (whether/how to also verify the transcript actually names the given session id) and its own
TDD pass against a background (nohup ... &) code path with a different test harness shape than
this issue's synchronous-exit fixture — fixing it here would roughly double this diff's size and
scope. Recommend filing a follow-up issue against scripts/post-tool-hook.sh:404-406 /
549-556 / 893, same class as #600 and #576.

🤖 Generated with Claude Code

[AI-generated]

STDIN_SESSION_ID reaches save-session.sh's argv below, and that script's own
arg loop reads a leading "--dry"/"--force" 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" passed through untouched and silently turned the
SessionEnd last-chance flush into a dry-run preview (no summary written,
position not advanced). Mirrors the `-*` remedy #576 already applied at the
sibling agy-stop-hook.sh call site.

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

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

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

* Fix stale line numbers and #600 merge-status overclaim in the #610 fix

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

* Fix docs/windows-skip-triage.md prose-vs-table drift (#612), pushed one 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

---------

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.

session-end-hook.sh: unextended dash-guard lets --dry reach save-session.sh via SessionEnd session_id

1 participant