Skip to content

guardrails: block-hook-bypass message overstates enforcement scope (writes inside an invoked script are not inspected) #1802

Closed

Description

@kyle-sexton

Severity: SUGGESTION (enforcement-scope disclosure, not a bypass vulnerability).

Component: guardrails plugin, hooks/block-hook-bypass.sh (observed at 0.13.0).

Summary

The guard's user-facing block message asserts an enforcement guarantee that the hook is documented not
to provide. The hook is deliberately producer-scoped and its own header comments name the escape
explicitly — but the message a user sees says nothing about that scope, so it reads as "shell file
writes are blocked" when the accurate statement is "shell file writes in this tool call's command
string
are blocked".

What was observed

Two inline Bash commands were blocked during a long fleet-hygiene session:

BLOCKED: cat > file write bypasses Write/Edit hooks
Use the Write or Edit tool instead of a shell file-write workaround.
BLOCKED: echo/printf > file write bypasses Write/Edit hooks
Use the Write or Edit tool instead of a shell file-write workaround.

The identical redirects, placed inside a .sh file and run as bash script.sh, were not blocked — and
this was not incidental: four scripts written that session (execute.sh, wtstate.sh,
remove-clean-worktrees.sh, verify.sh) all append to log files with printf >> and ran freely.

This is by design, and the hook says so

Worth stating plainly so nobody treats this as a hole to plug. The hook's header comments document the
producer-scoped design and name this exact case:

The echo/printf redirect is PRODUCER-SCOPED (see producer_redirect_bypass): it fires only when the
echo/printf is itself the command whose stdout is redirected into a real file, NOT when an echo
token and a > token merely co-occur in one compound command (bash x.sh > out.json && echo done —
the redirect's producer is bash) …

The hook scans .tool_input.command. It does not — and reasonably cannot — read the contents of a
script that command invokes. That is a sound boundary for a PreToolUse hook.

The actual defect

The message does not carry the scope the design has. "Use the Write or Edit tool instead of a
shell file-write workaround" tells a user their write was prevented and that the sanctioned path is
Write/Edit. It does not say that the guard covers direct redirects in the command string only, so a
reader over-trusts it in both directions:

  • An agent concludes shell file writes are unavailable and contorts around a restriction that a script
    file does not have — I hit this and rewrote work to route through Write/Edit unnecessarily.
  • A human reading the block assumes hook coverage the guard never claimed, which is the more expensive
    error if the guard is load-bearing in anyone's threat model.

Per the recurring-concerns checklist this is an enforcement scope/tier disclosure gap: the guard is a
speed bump against a specific accidental pattern, and its message is worded like a boundary.

Suggested fix

One line in the block message naming the scope, e.g.:

BLOCKED: echo/printf > file write bypasses Write/Edit hooks
Use the Write or Edit tool instead of a shell file-write workaround.
Scope: direct redirects in this command only — writes inside an invoked script are not inspected.

Alternatively, state the scope wherever the guard's guarantees are documented for consumers, and have
the message point there. No hook logic change is implied.

Environment

  • guardrails 0.13.0 (also present: 0.10.0, 0.12.3), marketplace install melodic-software
  • Claude Code on Windows 11 Pro 10.0.26200, Bash tool (Git Bash)
  • Surfaced incidentally during a repo-fleet-hygiene audit session; filed separately because it is a
    different plugin
  • Observed 2026-07-29/30

Activity

  1. added
    needs-triage
    on Jul 30, 2026
  2. self-assigned this
    on Jul 30, 2026
  3. kyle-sexton commented on Jul 30, 2026

    @kyle-sexton
    MemberAuthor

    Verified — and the suggested wording would have overstated coverage in the other direction

    Reproduced against the hook with fixture PreToolUse JSON (never by live-triggering it):

    Command Exit
    printf 'x' > out.log 2 (blocked)
    bash execute.sh 0 (allowed)
    ./verify.sh 0 (allowed)
    python3 build.py 0 (allowed)

    So the reported behaviour holds: a direct producer redirect blocks, while the identical redirect inside an invoked script is not inspected. The design read is right too — the hook scans .tool_input.command and reasonably cannot read a script's contents.

    One correction, and it changes the fix

    The suggested line is:

    Scope: direct redirects in this command only — writes inside an invoked script are not inspected.
    

    That would claim more coverage than the guard has. Three more shapes, all direct redirects in the command string, are allowed by the producer-scoped design:

    Command Exit
    bash execute.sh >> run.log 0 (allowed)
    sort data.txt > out.txt 0 (allowed)
    curl https://example.com > page.html 0 (allowed)
    jq . in.json > out.json 0 (allowed)
    echo hi | tee out.txt 0 (allowed)
    cat a.txt b.txt > c.txt 0 (allowed)

    The last one is worth calling out: only the stdin-consuming cat > f form is a write workaround. cat with input files is ordinary data processing and is allowed, which is correct — but it means "direct redirects in this command" is not the boundary either.

    The real scope is narrower than either statement: one command string, and only the specific content-producer write forms — cat > f consuming stdin, echo/printf > f, inline python3 -c writes, and the PowerShell write cmdlets.

    Fix

    PR incoming. block_bypass() gains a third line, so every lane carries it:

    BLOCKED: echo/printf > file write bypasses Write/Edit hooks
    Use the Write or Edit tool instead of a shell file-write workaround.
    Scope: only this command string is inspected, and only known file-write forms in it. Writes performed inside a script or program this command invokes, and redirects produced by another program, are not seen.
    

    Taking the issue's alternative suggestion as well rather than instead: the README residuals section — which already documents this guard's quoted-span residual — now states the same scope, so the limit is where consumers read the guard's guarantees and not only at the moment of a block.

    No hook logic changes. The behaviour the note describes is pinned by tests beside the message-content assertions, so a future change to what the guard blocks cannot silently make its message wrong again. Suite: 210 assertions, 0 failures.

  4. added a commit that references this issue on Jul 31, 2026
    8bbfeb1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

needs-triage

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