Skip to content

Chained bash commands silently bypass the tool permission allowlist #36637

Closed

Description

@Pro777

Summary

The permissions.allow allowlist evaluates the first token of a bash command. Compound commands (cmd1 && cmd2, cmd1; cmd2, cmd1 | cmd2) only present the first segment to the matcher — the remaining segments execute without evaluation.

Reproduction

Given allowlist:

{ "permissions": { "allow": ["Bash(git:*)"], "deny": ["Bash(rm:*)"] } }

This is blocked as expected:

rm -rf /important/dir

This bypasses the deny rule silently:

git status && rm -rf /important/dir

The allowlist sees git status (allowed), runs the whole chain, and rm executes without hitting the deny rule.

Impact

  • Agents that default to chained commands (common pattern) can unintentionally or maliciously escape permission boundaries
  • The user sees Bash(git:*) in the allow log and has no indication that subsequent chain segments were unevaluated
  • Particularly dangerous in agentic/long-running sessions where compound commands accumulate

Expected Behavior

Each segment of a compound command should be evaluated independently against the allowlist. If any segment would be denied, the entire command should be blocked.

Suggested Fix

Parse compound bash commands and evaluate each segment against the allowlist before execution. Segments joined by &&, ;, ||, or | should each be checked independently.

Activity

  1. Pro777 commented on Mar 20, 2026

    @Pro777
    Author

    Filed a reference implementation as a PreToolUse hook plugin in #36645. The approach:

    • Shell-aware compound splitter (respects single quotes, double quotes, backticks — operators inside strings are not treated as separators)
    • Reads Bash(...) deny patterns from all three settings files (~/.claude/settings.json, .claude/settings.json, .claude/settings.local.json)
    • Evaluates each segment independently with prefix + glob matching that mirrors the built-in rule semantics
    • Strips leading VAR=value env-var assignments before matching (closes the X=1 rm -rf / env-prefix bypass)
    • Fail-open: hook exits 0 on any parse error so legitimate commands are never silently blocked by a hook crash
    • 34 unit tests

    I've been running this as a PreToolUse hook in production on my own installation — it's working correctly and hasn't produced false positives on normal development workflows.

    The PR can serve as a reference implementation or test suite for the core fix in the bundle.

  2. Pro777 commented on Mar 27, 2026

    @Pro777
    Author

    Update with fresh receipts from an independent Windows session on Claude Code 2.1.78:

    • git clean -fd is blocked by disallowedTools as expected
    • git status && git clean -fd is also blocked
    • git status; git clean -fd is also blocked
    • with --dangerously-skip-permissions, the command executes (expected)

    Conclusion: I can no longer reproduce a chain-operator bypass (&&, ;, ||, |) on 2.1.78.

    To keep findings accurate, I opened a separate issue focused on nested/wrapped forms that still appear problematic ($(), backticks, subshell, eval, PowerShell wrapper): #39601

  3. Pro777 commented on Mar 27, 2026

    @Pro777
    Author

    Public thread redaction update: details that could be used as ready-to-run abuse payloads were removed.

    Claim status remains unchanged:

    • chain-operator bypass is not the active claim on 2.1.78
    • wrapper-mediated deny-evaluation gap is the active claim

    Full reproducible artifacts are available privately for maintainer/security review on request.

  4. added
    stale
    on Apr 12, 2026
  5. claude commented on Apr 17, 2026

    @claude
    Contributor

    This issue was fixed as of version 2.1.78.

  6. github-actions commented on Apr 25, 2026

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  7. locked as resolved and limited conversation to collaborators on Apr 25, 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

    area:basharea:permissionsarea:securitybugstale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions