Harden sensitive file guard confirmation flow#34286
Open
teee32 wants to merge 2 commits into
Open
Conversation
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>
This was referenced Mar 15, 2026
|
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 0Add to global settings for project-independent protection. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing
.hooksfromplugins/sensitive-file-guard/hooks/hooks.jsonand validated withplugins/plugin-dev/skills/hook-development/scripts/validate-hook-schema.sh