Chapter 56 · Reviewing Claude Config
Subchapter 56.3
reference/security-patterns.mdMarkdown11 KBView on GitHub
Security checks, detection commands, and remediation patterns for Claude configuration files.
Perform these checks for EVERY Claude configuration review:
If ANY check fails, flag as CRITICAL immediately.
Manual Detection:
# Check if file is tracked by git
git ls-files | grep "settings.local.json"
# If output exists, file is incorrectly committedExpected Output:
Automated Detection:
#!/bin/bash
# detect-committed-local-settings.sh
if git ls-files | grep -q "settings.local.json"; then
echo "CRITICAL: settings.local.json is committed to git"
exit 1
else
echo "OK: settings.local.json not in git"
exit 0
fiPattern Detection:
# Search for common secret patterns
grep -rE "(apiKey|api_key|API_KEY|password|passwd|token|secret)\s*[:=]\s*['\"]" .claude/
# Search for specific key prefixes
grep -rE "(sk-[a-zA-Z0-9]{32,}|ghp_[a-zA-Z0-9]{36}|gho_[a-zA-Z0-9]{36})" .claude/Common Secret Patterns:
| Pattern | Regex | Example |
|---|---|---|
| OpenAI API Key | sk-[a-zA-Z0-9]{32,} | sk-abc123def456... |
| GitHub Token | ghp_[a-zA-Z0-9]{36} | ghp_xxxxxxxxxxxx... |
| Generic API Key | (api[-_]?key)\s*[:=]\s*['"][^'"]+ | apiKey: "abc123" |
| Password | (password|passwd)\s*[:=]\s*['"][^'"]+ | password: "secret" |
Automated Detection:
#!/bin/bash
# detect-hardcoded-secrets.sh
FOUND_SECRETS=0
# OpenAI keys
if grep -rE "sk-[a-zA-Z0-9]{32,}" .claude/ 2>/dev/null; then
echo "CRITICAL: Found OpenAI API key pattern"
FOUND_SECRETS=1
fi
# GitHub tokens
if grep -rE "gh[po]_[a-zA-Z0-9]{36}" .claude/ 2>/dev/null; then
echo "CRITICAL: Found GitHub token pattern"
FOUND_SECRETS=1
fi
# Generic API keys and passwords
if grep -rE "(apiKey|api_key|password|token)\s*[:=]\s*['\"][^'\"]{8,}" .claude/ 2>/dev/null; then
echo "CRITICAL: Found potential hardcoded credential"
FOUND_SECRETS=1
fi
if [ $FOUND_SECRETS -eq 0 ]; then
echo "OK: No hardcoded secrets detected"
exit 0
else
exit 1
fiDangerous Permission Patterns:
# Check for overly broad permissions
grep -r "Read://\*" .claude/settings.json
grep -r "Write://\*" .claude/settings.json
grep -r "Bash:\*" .claude/settings.jsonRed Flags:
Read://* - Read access to entire filesystemWrite://* - Write access to entire filesystemBash:* - Auto-approve ALL bash commandsRead://Users/username/.ssh/** - Access to SSH keysRead:///etc/** - Access to system configAutomated Detection:
#!/bin/bash
# detect-broad-permissions.sh
ISSUES=0
if grep -q 'Read://\*"' .claude/settings.json 2>/dev/null; then
echo "CRITICAL: Overly broad Read permissions (Read://*)"
ISSUES=1
fi
if grep -q 'Write://\*"' .claude/settings.json 2>/dev/null; then
echo "CRITICAL: Overly broad Write permissions (Write://*)"
ISSUES=1
fi
if grep -q '"Bash:\*"' .claude/settings.json 2>/dev/null; then
echo "CRITICAL: Auto-approve all Bash commands (Bash:*)"
ISSUES=1
fi
# Check for sensitive paths
if grep -rE '(\.ssh|/etc|\.aws|\.config)' .claude/settings.json 2>/dev/null; then
echo "WARNING: Permissions reference sensitive directories"
ISSUES=1
fi
if [ $ISSUES -eq 0 ]; then
echo "OK: Permissions appropriately scoped"
exit 0
else
exit 1
fiDangerous Command Patterns:
# Check for dangerous commands
grep -E "(rm -rf|chmod 777|mkfs|dd|curl.*\| sh)" .claude/settings.jsonDangerous Commands List:
| Command | Risk | Why Dangerous |
|---|---|---|
rm -rf | Data loss | Recursive deletion without confirmation |
git push --force | Data loss | Overwrites remote history |
chmod 777 | Security | Grants all permissions to everyone |
curl ... | sh | RCE | Executes arbitrary remote code |
dd | Data loss | Low-level disk operations |
mkfs | Data loss | Formats filesystems |
:(){ :|:& };: | DoS | Fork bomb |
Automated Detection:
#!/bin/bash
# detect-dangerous-commands.sh
DANGEROUS_PATTERNS=(
"rm -rf"
"rm -fr"
"git push --force"
"git push -f"
"chmod 777"
"chmod 666"
"curl.*| sh"
"curl.*| bash"
"wget.*| sh"
"dd if="
"mkfs"
"> /dev/sd"
)
FOUND_DANGEROUS=0
for pattern in "${DANGEROUS_PATTERNS[@]}"; do
if grep -qE "$pattern" .claude/settings.json 2>/dev/null; then
echo "CRITICAL: Dangerous command auto-approved: $pattern"
FOUND_DANGEROUS=1
fi
done
if [ $FOUND_DANGEROUS -eq 0 ]; then
echo "OK: No dangerous command auto-approvals"
exit 0
else
exit 1
fiFull automated security scan:
#!/bin/bash
# security-scan.sh
# Comprehensive security scan for Claude configuration files
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
CLAUDE_DIR="${SCRIPT_DIR}/.."
ISSUES_FOUND=0
echo "=== Claude Configuration Security Scan ==="
echo ""
# Check 1: Committed settings.local.json
echo "[1/4] Checking for committed settings.local.json..."
if git
# Remove from git but keep locally
git rm --cached .claude/settings.local.json
# Ensure .gitignore includes it
if ! grep -q "settings.local.json" .gitignore; then
echo ".claude/settings.local.json" >> .gitignore
fi
# Commit the fix
git add .gitignore
git commit -m "Remove settings.local.json from git tracking"Before:
{
"apiKey": "sk-1234567890abcdef"
}After:
{
"apiKeyVar": "$OPENAI_API_KEY",
"note": "Set API key: export OPENAI_API_KEY=your-key"
}Or remove entirely and document:
# Configuration
Set required environment variables:
- `OPENAI_API_KEY` - Your OpenAI API keyBefore:
{
"autoApprovedTools": ["Read://*"]
}After:
{
"autoApprovedTools": [
"Read://Users/username/projects/myproject/**",
"Read://Users/username/.claude/projects/**"
]
}Before:
{
"autoApprovedTools": ["Bash:*"]
}After:
{
"autoApprovedTools": [
"Bash:git status:*",
"Bash:git log:*",
"Bash:git diff:*",
"Bash:npm install:*",
"Bash:./gradlew test:*"
]
}Read-Only Commands (Generally Safe):
git status, git log, git diff, git showls, cat, head, tail, lessgrep, find, wc, sortnpm list, ./gradlew tasksIdempotent Commands (Safe):
npm install, npm ci./gradlew build, ./gradlew testgit pull (on feature branches)mkdir -p (with scoped paths)Commands Requiring Approval:
rm commandgit push --forcechmod, chown