credential-leak-guard · Hooks para Claude Code | Prompt Studio
    1. Claude Code
    2. Hooks
    3. credential-leak-guard
    Claude Code · HooksPreToolUse

    credential-leak-guard

    Bloquea intentos de buscar o exfiltrar credenciales.

    por davepoon/buildwithclaude

    PreToolUse

    Licencia: MITVer original

    Instalación

    /plugin marketplace add davepoon/buildwithclaude
    /plugin install hooks-safety@buildwithclaude

    Contenido

    ---
    name: credential-leak-guard
    description: Block credential hunting and exfiltration attempts via environment scanning, file access, and HTTP upload
    category: security
    event: PreToolUse
    matcher: Bash
    language: bash
    version: 1.0.0
    ---
    
    # credential-leak-guard
    
    Detects and blocks credential hunting patterns: environment variable scanning for tokens/secrets, direct access to SSH keys and cloud credentials, searching for credential files, and exfiltration via `curl`/`wget`.
    
    This addresses [anthropics/claude-code#37845](https://github.com/anthropics/claude-code/issues/37845) where 48 bash commands were auto-executed to scan for credentials.
    
    ## Event Configuration
    
    - **Event Type**: `PreToolUse`
    - **Tool Matcher**: `Bash`
    - **Category**: security
    
    ### Script
    
    ```bash
    #!/bin/bash
    # credential-leak-guard.sh — Block credential hunting and exfiltration
    
    INPUT=$(cat)
    COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command // empty' 2>/dev/null)
    
    [ -z "$COMMAND" ] && exit 0
    
    # Pattern 1: env/printenv piped to grep for secrets
    if echo "$COMMAND" | grep -qiE '(env|printenv|set)\s*\|.*grep.*\b(token|secret|key|password|credential|auth|oauth|cookie|session|api.key)\b'; then
        echo "BLOCKED: Credential hunting via environment variable scanning" >&2
        exit 2
    fi
    
    # Pattern 2: find searching for credential files
    if echo "$COMMAND" | grep -qiE 'find\s.*-name\s.*\*?(token|secret|credential|password|\.key|\.pem|\.p12|\.pfx|\.keystore|\.jks|\.env)'; then
        echo "BLOCKED: Credential hunting via file system search" >&2
        exit 2
    fi
    
    # Pattern 3: Direct access to SSH credentials
    if echo "$COMMAND" | grep -qE 'cat\s+(~|/home|/root)/.ssh/(id_|authorized_keys|known_hosts|config)'; then
        echo "BLOCKED: Direct SSH credential access" >&2
        exit 2
    fi
    
    # Pattern 4: System credential files
    if echo "$COMMAND" | grep -qE 'cat\s+(/etc/shadow|/etc/gshadow|/etc/passwd)'; then
        echo "BLOCKED: System credential file access" >&2
        exit 2
    fi
    
    # Pattern 5: Cloud provider credentials
    if echo "$COMMAND" | grep -qE 'cat\s+(~|/home|/root)/\.(aws|gcloud|azure|kube)/(credentials|config|token)'; then
        echo "BLOCKED: Cloud provider credential access" >&2
        exit 2
    fi
    
    # Pattern 6: Browser credential stores
    if echo "$COMMAND" | grep -qiE 'find\s.*\.(chrome|firefox|mozilla|safari).*\b(login|password|cookie|token)\b'; then
        echo "BLOCKED: Browser credential hunting" >&2
        exit 2
    fi
    
    # Pattern 7: HTTP upload of credential files
    if echo "$COMMAND" | grep -qiP 'curl\s.*-d\s+@[^\s]*(\.env|\.pem|\.key|credentials|\.ssh/id_)|wget\s.*--post-file[= ][^\s]*(\.env|\.pem|\.key|credentials|\.ssh/id_)'; then
        echo "BLOCKED: Credential file exfiltration via HTTP upload" >&2
        exit 2
    fi
    
    # Pattern 8: Piping credential files to HTTP clients
    if echo "$COMMAND" | grep -qiP 'cat\s+[^\s]*(\.env|\.pem|\.key|credentials|\.ssh/id_)\S*\s*\|.*curl|cat\s+[^\s]*(\.env|\.pem|\.key|credentials|\.ssh/id_)\S*\s*\|.*wget'; then
        echo "BLOCKED: Credential file piped to HTTP client" >&2
        exit 2
    fi
    
    exit 0
    ```
    
    ## Usage
    
    Add to your `.claude/settings.json`:
    
    ```json
    {
      "hooks": {
        "PreToolUse": [{
          "matcher": "Bash",
          "hooks": [{ "type": "command", "command": "~/.claude/hooks/credential-leak-guard.sh" }]
        }]
      }
    }
    ```
    

    Más en Hooks

    • Formatear al editar

      Ejecuta Prettier sobre cada archivo que Claude edita o crea.

    • Bloquear archivos .env

      Impide que Claude lea o edite archivos de secretos.

    • Aviso al terminar

      Notificación de escritorio en macOS cuando Claude termina.

    • Chequeo de tipos al editar

      Corre tsc después de editar archivos TypeScript y muestra los errores.

    • Contexto al iniciar

      Carga la rama y los últimos commits al abrir una sesión.

    • Registro de comandos

      Guarda cada comando de shell en un log para auditoría.

    Ver todo en Hooks (621) →

    Tu colección definitiva de prompts de IA. Inspírate, explora ejemplos y crea con IA.

    Hubs principales

    • Prompts
    • Imágenes
    • Videos
    • Generar Videos
    • Plantillas
    • Animaciones
    • Precios
    • Conoce
    • Afiliado

    Explorar por tipo

    • Kits de componentes
    • Etiquetas de imagen
    • Etiquetas de video
    • Webs

    Temas populares

    • Música
    • Portafolio
    • Gaming
    • Viajes
    • Nano Banana Pro

    Legal

    • Términos de uso
    • Política de privacidad
    • Política de cookies
    • Política de licencias
    • Política de reembolsos
    • Términos del programa de afiliados
    • Términos de Crowdfunding

    Magzin LLC, 800 Third Avenue Associates, New York, NY, 10022, United States

    © 2026 Prompt Studio by Magzin. Todos los derechos reservados.