#!/bin/bash # ============================================================================= # CLAUDE.md Injection Scanner Hook # ============================================================================= # Event: SessionStart (runs when Claude Code session begins) # Purpose: Detect potential prompt injection attacks in CLAUDE.md files # # Installation: # Add to .claude/settings.json: # { # "hooks": { # "SessionStart": [{ # "matcher": "", # "hooks": ["bash examples/hooks/bash/claudemd-scanner.sh"] # }] # } # } # # What it detects: # - "ignore previous instructions" patterns (common injection technique) # - Shell command execution attempts (curl|bash, wget|sh, eval) # - Base64 encoded content (potential obfuscation) # - Suspicious HTML comments that might hide instructions # ============================================================================= set -euo pipefail # Define suspicious patterns (case-insensitive) SUSPICIOUS_PATTERNS=( "ignore.*previous.*instruction" "ignore.*all.*instruction" "disregard.*instruction" "forget.*instruction" "new.*instruction.*follow" "curl.*\|.*bash" "curl.*\|.*sh" "wget.*\|.*bash" "wget.*\|.*sh" "eval\s*\(" "base64.*decode" "\$\(.*curl" "\$\(.*wget" "