Skip to content

Harden sensitive file guard confirmation flow#34286

Open
teee32 wants to merge 2 commits into
anthropics:mainfrom
teee32:sensitive-file-guard-confirmation-flow
Open

Harden sensitive file guard confirmation flow#34286
teee32 wants to merge 2 commits into
anthropics:mainfrom
teee32:sensitive-file-guard-confirmation-flow

Conversation

@teee32

@teee32 teee32 commented Mar 14, 2026

Copy link
Copy Markdown

Summary

  • switch sensitive-file-guard to structured PreToolUse permission decisions with deny/ask/allow risk levels
  • only allowlist medium-risk files after the exact asked tool call succeeds, and clear pending state on failure
  • add a quoted shell wrapper for Python resolution across python3/python/py and add focused regression tests

Testing

  • python3 plugins/sensitive-file-guard/hooks/test_sensitive_file_guard_hook.py
  • extracted .hooks from plugins/sensitive-file-guard/hooks/hooks.json and validated with plugins/plugin-dev/skills/hook-development/scripts/validate-hook-schema.sh

GG ZIBLAKING and others added 2 commits March 14, 2026 12:28
This plugin adds a PreToolUse hook that intercepts Write, Edit, and
MultiEdit operations to protect sensitive infrastructure files from
accidental overwrites.

Protected file categories:
- Environment files (.env, .env.local, .env.production, etc.)
- Package lockfiles (package-lock.json, yarn.lock, Cargo.lock, etc.)
- CI/CD configs (.github/workflows/*.yml, .gitlab-ci.yml, Jenkinsfile)
- Container configs (Dockerfile, docker-compose.yml)
- Infrastructure-as-Code (terraform.tfstate, *.tfvars)
- Cryptographic keys (*.pem, *.key, id_rsa, id_ed25519)
- Deployment configs (vercel.json, netlify.toml, fly.toml)

Features:
- Session-scoped warnings (warns once per file per session)
- Graceful fallback on invalid input
- Configurable via SENSITIVE_FILE_GUARD_ENABLED environment variable
- Automatic cleanup of state files older than 30 days

Co-Authored-By: Claude <noreply@anthropic.com>
@yurukusa

Copy link
Copy Markdown

A PreToolUse hook can implement a strict sensitive file guard:

FILE=$(cat | jq -r '.tool_input.file_path // empty' 2>/dev/null)
[ -z "$FILE" ] && exit 0
SENSITIVE='\.env|\.env\.|credentials|secret|password|token|key\.pem|id_rsa|id_ed25519|\.gnupg|\.ssh/config|\.netrc|\.npmrc.*authToken'
if echo "$FILE" | grep -qiE "$SENSITIVE"; then
    echo "BLOCKED: Access to sensitive file: $FILE" >&2
    echo "  This file may contain credentials or secrets" >&2
    exit 2
fi
exit 0

Add to global settings for project-independent protection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants