forked from FlorianBruniaux/claude-code-ultimate-guide
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity-check.sh
More file actions
47 lines (41 loc) · 1.22 KB
/
security-check.sh
File metadata and controls
47 lines (41 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# PreToolUse hook - Block commands containing secrets
# Place in: .claude/hooks/security-check.sh
# Register in: .claude/settings.json
INPUT=$(cat)
TOOL=$(echo "$INPUT" | jq -r '.tool_name')
if [[ "$TOOL" == "Bash" ]]; then
COMMAND=$(echo "$INPUT" | jq -r '.tool_input.command')
# Check for common secret patterns
PATTERNS=(
"password="
"PASSWORD="
"secret="
"SECRET="
"api_key="
"API_KEY="
"apikey="
"token="
"TOKEN="
"aws_access_key"
"AWS_ACCESS_KEY"
"aws_secret"
"AWS_SECRET"
"private_key"
"PRIVATE_KEY"
)
for PATTERN in "${PATTERNS[@]}"; do
if echo "$COMMAND" | grep -qi "$PATTERN"; then
echo "{\"decision\": \"block\", \"reason\": \"Potential secret detected: $PATTERN\"}"
exit 2
fi
done
# Check for hardcoded credentials in common formats
# API keys (typically long alphanumeric strings)
if echo "$COMMAND" | grep -qE "(sk-[a-zA-Z0-9]{20,}|pk_[a-zA-Z0-9]{20,}|[a-f0-9]{32,})"; then
echo "{\"decision\": \"block\", \"reason\": \"Potential API key or hash detected\"}"
exit 2
fi
fi
# Allow the command
exit 0