Skip to content

guardrails: block-hook-bypass does not re-parse a sh -c / bash -c operand that four sibling guards do #4243

Closed

Description

@kyle-sexton

Observed in .claude/plugins/data/plugin-quality-melodic-software/evidence/c7ff503b-19e2-40d2-b99e-38c747f7fc0f/guardrails-hooks/20260919T205610Z/audit-notes.md, finding F2 (auditor severity: HIGH). Probe results are direct runs of the registered chain at guardrails 0.35.0. Tier: measured this session (E1).

The guard blocks "Bash file-write workarounds that circumvent Write/Edit hook gates" (the userConfig description in plugin.json). Moving the identical text one level into a -c operand makes it invisible:

command exit
echo secret > a.txt 2 (blocked)
printf "%s" x > a.txt 2
cat > a.txt <<EOF ... 2
bash -c 'echo secret > a.txt' 0
sh -c 'echo secret > a.txt' 0
bash -c 'cat > a.txt <<EOF ...' 0
bash -c 'git reset --hard' 2 (a sibling guard DOES see through)

The asymmetry is internal to one hook process. grep -n "shell_c_operand" over hooks/*.sh and lib/powershell/*.sh finds call sites in block-convention-violation.sh:431, block-dangerous-git.sh:714, block-no-verify.sh:191 and block-noncanonical-commit.sh:618, and none in block-hook-bypass.sh, block-windows-drive-tmp.sh or block-exported-msys-pathconv.sh.

Why it matters beyond the write gate: secret-pattern-detection is registered only on the Write|Edit|MultiEdit|NotebookEdit and GitHub-MCP matchers in hooks.json, never on Bash|PowerShell. The write gate is what forces content through the lane where the secret scan lives, so bash -c 'echo <credential> > .env' skips both the write gate and the secret scan in one move.

Disclosure gap: the README residual at L136-L139 covers the script-file case ("it does not read the contents of a script that command invokes"). The inline -c case is materially different, since the text is already in .tool_input.command and four sibling guards parse it, and it is named nowhere.

Cheapest fix: add the same hook::shell_c_operand plus hook::bash_parse_segments re-parse that block-dangerous-git.sh:714-715 already uses. This reuses an existing helper and follows the pattern of four sibling guards. Fuller fix: apply it to block-windows-drive-tmp.sh and block-exported-msys-pathconv.sh, which share the gap. If deferred, disclose the -c operand case in both the README residual list and the runtime scope line the guard prints on a block.

Verification: the three bash -c / sh -c rows above must exit 2, with bash -c 'git status' still at 0.

🤖 Generated with Claude Code

https://claude.ai/code/session_01F7GFS5autRMSaea6kSoXzx

Activity

  1. added
    area: security
    agent-ready
    on Sep 19, 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

    agent-readyarea: security

    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