Files
ruflo/plugin/hooks
rUvandReuven d5fbb3bc4e fix(hooks): stop creating empty files via $TOOL_INPUT shell injection (#1747) (#1757)
The Liberation of Bajor team's report (#1747) is a precise diagnosis:
\`plugin/hooks/hooks.json\` interpolated \`\$TOOL_INPUT_command\` (and
\`\$TOOL_INPUT_*\`, \`\$PROMPT\`, \`\$TOOL_NAME\` etc.) directly into
double-quoted command strings. When the bash command being executed
contained both \" and >, the wrapping quotes broke and the shell
re-parsed the inner content. Any > became a redirect, creating empty
files at CWD with names like '3', '40)', 'maxWidth)', etc.

After ~24h of normal usage on Windows + Git Bash, dozens of empty
files accumulated at every project root.

Fix: rewrite ALL 13 command hooks to use the stdin-jq-xargs pattern
that the companion file \`.claude-plugin/hooks/hooks.json\` already
uses safely:

    cat | jq -r '.tool_input.command // empty' | tr '\\\\n' '\\\\0' \\
        | xargs -0 -I {} npx claude-flow@alpha hooks pre-command --command '{}'

Reading via stdin + jq + xargs -0 -I {} bypasses shell re-parsing
entirely. The user input becomes a single argv element, never
re-interpreted as shell tokens.

Validation (script in commit):
  safe (stdin-jq): 13   unsafe (\$-interp): 0

Affected hooks (all rewritten):
  PreToolUse:  Bash, Write|Edit|MultiEdit, Task, Grep|Glob|Read,
               mcp__claude-flow__*
  PostToolUse: same 5 matchers
  UserPromptSubmit: route by .prompt
  SessionStart:    by .session_id
  Notification:    by .message

Dropped non-essential \$TOOL_SUCCESS / \$TOOL_EXIT_CODE flags from
post-* hooks — they're internal booleans/numbers (not user input,
so not the file-creation vector) but the cleaner stdin-only pattern
is preferable over mixed inline/stdin.

Stop / SubagentStop / PermissionRequest hooks unchanged — they don't
interpolate user input.

This is a plugin-file change; no npm publish needed. The fix is live
when the PR merges and users pull main / re-clone.

Closes #1747.

Co-authored-by: Reuven <cohen@ruv-mac-mini.local>
2026-05-05 10:43:52 -04:00
..