Skip to content

block-hook-bypass: false-fires when a Bash command contains both an echo token and a redirect (script-stdout capture, or quoted-string arguments) rather than an actual file-authoring bypass #546

Closed

Description

@kyle-sexton

Observed during PR-babysitting of #526 (source-control worker loop).

Symptom

block-hook-bypass.sh (PreToolUse:Bash) blocked otherwise-legitimate commands with:

BLOCKED: echo > file write bypasses Write/Edit hooks
Use the Write or Edit tool instead of Bash file-write workarounds.

None of the blocked commands authored file content via the shell. They redirected a script's stdout to a scratchpad JSON data file, and separately contained one or more echo status lines elsewhere in the same compound command. Paraphrased examples:

  1. bash fetch-all-pr-comments.sh 526 > pr526.json combined with a trailing echo "EXIT: $?" in the same call.
  2. A bounded poll loop: bash fetch-....sh 526 > poll.json inside a loop body that also had echo "..." summary lines.
  3. The gh issue create for THIS very report — blocked purely because the issue body text contained the literal tokens echo and > describing the bug. Had to fall back to --body-file.

Removing the echo statements (leaving only the redirect capturing script stdout) let the identical redirect through — confirming the trigger is the co-occurrence of an echo token and a > token in one Bash command string, not an actual file-authoring bypass.

Root cause (hypothesis)

The guard heuristic matches echo + > anywhere in the same Bash command string and conflates it with the echo "content" > file content-authoring bypass it is meant to catch. It does not distinguish:

  • echo "content" > file — the intended target (authoring file content, bypassing Write/Edit), from
  • some_command > file.json accompanied by an unrelated echo "status" — legitimate (redirecting a subprocess's stdout to a data sink), or
  • an echo/> appearing only inside a quoted string argument (e.g. a gh issue create --body payload).

Impact

  • "Run a script, capture its stdout to a scratchpad data file" is blocked whenever an echo appears in the same call, forcing awkward command splitting.
  • Any command whose string arguments merely mention echo/> (issue bodies, commit messages, docs about shell) trips the guard — a content-independent false positive.

Suggested fix direction

Scope the match to the concrete echo .../printf ... producer being redirected into a file (i.e. the redirect's left side is the echo/printf), rather than flagging any command string that contains both tokens. Ignore tokens that fall inside quoted argument strings. A subprocess whose stdout is redirected to a data file, and a quoted argument that happens to contain the words, should not trip the guard.

Category

bug (hook false-positive / over-broad heuristic)


Filed as a babysit self-observation. Not refiling the sibling flag-commit-pr-skill-bypass advisory false-fire (already tracked in #545).

Activity

  1. added
    needs-triageNot yet classified. Floor until a type and one priority tier are set.
    on Jul 19, 2026
  2. kyle-sexton commented on Jul 19, 2026

    @kyle-sexton
    MemberAuthor

    This was generated by AI during triage. · Category: bug · Priority: priority: high (guardrails over-broad match blocks legitimate script-stdout capture AND any command whose string args merely mention echo/> — including issue/commit bodies about shell). Routed status: ready.

    Plan

    block-hook-bypass.sh (PreToolUse:Bash) matches echo + > anywhere in the command string and conflates it with the echo "content" > file content-authoring bypass it targets. It wrongly blocks:

    • some_command > file.json accompanied by an unrelated echo "status" in the same compound call (redirecting a subprocess's stdout to a data sink — legitimate);
    • echo/> appearing only inside a quoted argument (e.g. a gh issue create --body "…echo…>…" payload — which blocked the filing of the report itself).

    Fix direction: scope the match to the concrete echo … / printf … producer being redirected into a file — i.e. the redirect's left-hand side IS the echo/printf. Ignore echo/> tokens that fall inside quoted argument strings. A subprocess whose stdout is redirected to a data file, and a quoted argument that merely contains the words, must not trip the guard.

    Acceptance

    • bash script.sh > out.json; echo "done" → allowed (redirect producer is the script, not echo).
    • gh issue create --body "text mentioning echo and >" → allowed (tokens inside a quoted arg).
    • echo "content" > file / printf '%s' … > file → still BLOCKED (genuine content-authoring bypass — the true positive stays caught).

    Triage corroboration (this lane)

    This lane preemptively routed ALL its GitHub writes through --body-file / -f body=@file (never inline --body), specifically because inline bodies containing shell tokens trip this guard — corroborating the quoted-argument false-positive (case 3). Genuine cat >/printf > file heredoc writes were correctly blocked (true positives), so the fix must preserve those.

    Decision defaulted: match only an echo/printf producer on the left of a file redirect, ignoring tokens inside quoted args, rather than any co-occurrence of echo and > — veto before merge

  3. added
    status: readyTriaged, unblocked, and fully specified; eligible to pick up.
    and removed
    needs-triageNot yet classified. Floor until a type and one priority tier are set.
    on Jul 19, 2026
  4. kyle-sexton commented on Jul 19, 2026

    @kyle-sexton
    MemberAuthor

    Adjacent facet observed during PR #528 babysitting (round 2): block-hook-bypass also fires on genuine echo >file writes made inside the session scratchpad/temp dir (e.g. $TMPDIR/claude/.../scratchpad) when a verification worker builds a throwaway git sandbox to empirically reproduce shell-logic findings. There the detection is a true positive but the protection is unwanted — the files are disposable and outside any repo. Consider scoping the hook to repo-tracked paths (or exempting the CLAUDE temp/scratchpad root) so sandbox setup does not require git commit --allow-empty / Write-tool workarounds. Filing here rather than as a new issue since it is the same hook; flag if you would prefer it split out.

  5. self-assigned this
    on Jul 19, 2026
  6. kyle-sexton commented on Jul 20, 2026

    @kyle-sexton
    MemberAuthor

    Two more confirming examples from a babysit-prs loop session (2026-07-20, lane: babysit):

    1. python pr_queue_snapshot.py ... > snapshot-latest-run.json 2>&1 (redirecting the JSON-producing script's own stdout to a file for orchestrator capture) — false-fired: BLOCKED: echo > file write bypasses Write/Edit hooks.
    2. Worker on PR docs(session-flow): document override boundary for stage taxonomy and retro rubric #489 hit the same false-fire piping fetch-all-pr-comments.sh stdout to a file; worked around by piping to python instead of redirecting to a file.

    Both are plain script-stdout capture, no echo/printf producer of file content — matches the issue title's second clause. No action needed beyond this confirming telemetry; #568 already carries the fix.

  7. removed their assignment
    on Jul 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: readyTriaged, unblocked, and fully specified; eligible to pick up.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions