Two findings from ruvnet's review on #4053:
1. The powershell/-EncodedCommand pattern (`\s+.*-e(...)`) backtracks
quadratically on hostile input -- measured ~1.9s on 64,000 spaces with no
match; a 1MB hook command would stall session-restore (an unconditional
boot path) for minutes. Rewritten as a linear token-walk
(`(?:\S+\s+)*?`), confirmed <5ms on a 1MB hostile input while still
matching real EncodedCommand payloads. Fixed in both the CJS mirror and
the shared TS original (settings-risk-scanner.ts), since the TS version
is already live via init/--upgrade.
2. scanSessionStartSettingsForRisk()'s warnings included up to 120 chars of
the matched hook-command snippet -- but session-restore's stdout is read
back into the live Claude Code session as context, unlike init/--upgrade
where a human reads the terminal directly. Printing attacker-controlled
settings.json content into that context is a prompt-injection path even
with control characters stripped. The automatic-boot path now prints
only the scanner-generated location + reason, never the snippet;
srFormatRiskFindingsAsWarnings (snippet included) is unchanged for
init/--upgrade's human-facing output.
New tests: a 1MB ReDoS timing guard, a snippet-leak regression guard, and a
real-payload-still-detected check after the regex rewrite. 75/75 related
tests pass.
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01HW4yuGGcrCy4CcPgQ7Q2dx
Under Git Bash MSYS rewrote the /c of the generated cmd /c IF EXIST hook, so cmd
started interactively, executed the hook's stdin JSON and created zero-byte files
from text after a >. The Windows hook is now a single node -e with no cmd, no
%VAR%, and none of < > | & $ or inner double quotes. It keeps the project-first
then user-profile fallback (#1943), user scope never reads the project, and the
helper runs as a child with inherited stdio so stdin and the exit status pass
through. pinToUserHelpers recognises the new form (exact match only) as well as
the old ones.
Co-Authored-By: RuFlo <ruv@ruv.net>
Closes the gap #3835 itself disclosed: the settings-risk scanner
(CVE-2025-59536-class detection, #3043) ran at init/--upgrade and (pending
#3835) the explicit hooks_session-restore MCP/CLI handler, but never on the
one path that fires automatically on every real Claude Code session boot
-- hook-handler.cjs's session-restore command, wired via .claude/settings.json's
own SessionStart hooks array. Validated against a real 2026 attack campaign
("Mini Shai-Hulud" npm worm) and a real Claude Code CVE (CVE-2026-25725),
both of which use exactly this SessionStart-hook persistence mechanism.
Ports the existing TS scanner's logic (hook-handler.cjs has no build step)
into scanSessionStartSettingsForRisk(), wired into the 'session-restore'
command handler in both the root and package copies of hook-handler.cjs
(kept byte-identical per the existing parity test). An adversarial-critic
subagent review found and this session fixed one real issue pre-commit: a
non-SyntaxError JSON.parse failure would have aborted session-restore
itself rather than degrading gracefully, since this path runs
unconditionally on every boot (unlike the opt-in MCP-tool path #3835
hardened the same way).
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01HW4yuGGcrCy4CcPgQ7Q2dx
#2351 fixed trajectory-end feedback being dropped, but only for step-less
trajectories (`!hasSteps` gate). The common start -> step -> end path that
real agents use recorded SONA state via `processTrajectoryOutcome`, but the
non-empty `feedback` string was never promoted to the `pattern` namespace,
so it was unreachable through `hooks_intelligence_pattern-search`.
Remove the `!hasSteps` restriction so feedback is promoted whenever it is
non-empty, regardless of whether steps were recorded. `patternsExtracted`
and the `feedbackDistilled` response field already handled both cases
generically, so no other call sites change behavior.
Adds a regression test driving the full trajectory-start -> step -> end ->
pattern-search path, which fails on current main and passes with this fix.
Note: this addresses only the "indexed when steps are present" half of
#3662. The issue's other claim — that `hooks_route` never consults a
persisted SONA `getRoutingSuggestion()` pattern — is real (verified:
`getSuggestion`/`getRoutingSuggestion` have no callers outside
sona-optimizer.ts) but requires an architectural decision (precedence vs.
the AgentDB/semantic routing paths, the confidence threshold, and new
response fields distinguishing "persisted" from "eligible for inference")
that is out of scope for this fix.
Co-Authored-By: RuFlo <ruv@ruv.net>
Claude-Session: https://claude.ai/code/session_01QFyyphjiSXRE1TS2rRnEwU