Block Copying PII Columns to a Non-Encrypted Destination
A `cp` or database export command naming a known customer/PII table is fine if it lands on an encrypted volume and a problem if it lands anywhere else. This checks the destination against a configured encrypted-mount prefix before allowing the command through.
1. Save this as the hook script
#!/usr/bin/env python3
"""PreToolUse hook — blocks a cp/export referencing a PII table unless
the destination is under an encrypted mount. Wire to the Bash matcher."""
import json, re, sys
data = json.load(sys.stdin)
command = (data.get("tool_input") or {}).get("command", "")
PII_TABLES = ["customers", "account_holders", "kyc_records"]
ENCRYPTED_MOUNT_PREFIX = "/mnt/encrypted/"
if any(t in command for t in PII_TABLES) and re.search(r"(?i)\b(cp|export)\b", command):
if ENCRYPTED_MOUNT_PREFIX not in command:
print(f"BLOCKED: command references a PII table but its destination "
f"isn't under {ENCRYPTED_MOUNT_PREFIX}.", file=sys.stderr)
sys.exit(2)
sys.exit(0)
Save to a path inside your project, e.g. .claude/hooks/block-pii-columns-to-unencrypted-dest.sh, then chmod +x it.
2. Wire it into .claude/settings.json
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{"type": "command", "command": "python3 .claude/hooks/block-pii-columns-to-unencrypted-dest.py"}
]
}
]
}
}
Before you use this
A hook runs with your local shell's permissions — review the script above before adding it, the same way you'd review any script you didn't write yourself. See our guide on hook security risks for the specific CVEs this category of feature has already produced.
Related hooks