secret-scanner
БесплатноБез исполняемых скриптовНе проверенDetects API keys, passwords, and secrets in code before they reach git. Use before commits, when working with credentials, or when user mentions "security…
Об этом скилле
Secret Scanner
What This Skill Does
Automatically scans code for hardcoded secrets BEFORE they reach git:
- API keys
- Passwords
- Access tokens
- Private keys
- Database credentials
- Any sensitive data
Detection Patterns
High-Risk Patterns (Always Block)
# ❌ Will be blocked
API_KEY = "sk_live_1234567890abcdef"
SECRET_KEY = "supersecretpassword123"
PASSWORD = "admin123"
AWS_SECRET = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
PRIVATE_KEY = "-----BEGIN RSA PRIVATE KEY-----"
DATABASE_URL = "postgresql://user:pass@localhost/db"
Safe Patterns (Will Pass)
# ✅ Safe - environment variables
API_KEY = os.getenv("API_KEY")
SECRET_KEY = settings.secret_key
PASSWORD = env.str("DATABASE_PASSWORD")
# ✅ Safe - configuration references
api_key: str = Field(..., env="API_KEY")
Regex Patterns Used
The scanner looks for:
# API keys and secrets
(API_KEY|SECRET|PASSWORD|TOKEN|PRIVATE_KEY)\s*=\s*["'][^"']{8,}["']
# JWT tokens
eyJ[A-Za-z0-9-_=]+\.eyJ[A-Za-z0-9-_=]+\.[A-Za-z0-9-_.+/=]*
# AWS keys
AKIA[0-9A-Z]{16}
# Database URLs with credentials
(postgres|mysql|mongodb):\/\/[^:]+:[^@]+@
# Private keys
-----BEGIN (RSA|DSA|EC) PRIVATE KEY-----
How to Handle Detected Secrets
Step 1: Remove from code
# Before (❌ blocked)
OPENAI_KEY = "sk-proj-1234567890abcdef"
# After (✅ passes)
OPENAI_KEY = os.getenv("OPENAI_KEY")
Step 2: Add to .env file
# .env (never committed!)
OPENAI_KEY=sk-proj-1234567890abcdef
DATABASE_URL=postgresql://user:pass@localhost/db
SECRET_KEY=your-secret-key-here
Step 3: Add to .env.example
# .env.example (can be committed)
OPENAI_KEY=sk-proj-xxx
DATABASE_URL=postgresql://user:pass@localhost/dbname
SECRET_KEY=generate-with-openssl-rand-hex-32
Step 4: Update .gitignore
# Environment variables
.env
.env.local
.env.production
# Secrets
secrets/
*.key
*.pem
*.cert
Pydantic Settings Integration
Use pydantic-settings for type-safe config:
from pydantic_settings import BaseSettings, SettingsConfigDict
class Settings(BaseSettings):
"""Application settings loaded from environment."""
model_config = SettingsConfigDict(
env_file=".env",
env_file_encoding="utf-8",
case_sensitive=False,
)
# Database
database_url: str
# API Keys
openai_api_key: str
sentry_dsn: str | None = None
# Security
secret_key: str
algorithm: str = "HS256"
access_token_expire_minutes: int = 30
# Usage
settings = Settings()
# Now use settings.database_url instead of os.getenv()
Manual Scan Command
Run scanner manually:
# Scan all Python files
grep -rnE '(API_KEY|SECRET|PASSWORD|TOKEN)\s*=\s*["'\''][^"'\'']{8,}' app/
# Scan staged files only
git diff --cached --name-only | xargs grep -nHE 'API_KEY.*=.*["\047]'
# Check for common patterns
rg 'sk-[a-zA-Z0-9]{20,}' app/ # OpenAI keys
rg 'AKIA[0-9A-Z]{16}' app/ # AWS keys
rg 'ghp_[a-zA-Z0-9]{36}' app/ # GitHub tokens
Common Secret Types
OpenAI API Keys
# ❌ Bad
OPENAI_KEY = "sk-proj-1234567890"
# ✅ Good
OPENAI_KEY = os.getenv("OPENAI_KEY")
Database Credentials
# ❌ Bad
DATABASE_URL = "postgresql://admin:secretpass@localhost/mydb"
# ✅ Good
DATABASE_URL = settings.database_url
JWT Secrets
# ❌ Bad
SECRET_KEY = "my-super-secret-key-12345"
# ✅ Good
SECRET_KEY = os.getenv("SECRET_KEY")
# Generate with: openssl rand -hex 32
AWS Credentials
# ❌ Bad
AWS_ACCESS_KEY_ID = "AKIAIOSFODNN7EXAMPLE"
AWS_SECRET_ACCESS_KEY = "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
# ✅ Good
# Use AWS CLI credentials or instance roles
import boto3
s3 = boto3.client('s3') # Uses ~/.aws/credentials
Secrets Already Committed?
If you accidentally committed secrets:
Step 1: Rotate the secret
# Generate new API key immediately!
# Old key is now compromised and must be revoked
Step 2: Remove from git history
# Remove file from all commits
git filter-branch --force --index-filter \
'git rm --cached --ignore-unmatch path/to/file.py' \
--prune-empty --tag-name-filter cat -- --all
# Force push (if remote)
git push origin --force --all
Step 3: Add to .gitignore
echo "config/secrets.py" >> .gitignore
git add .gitignore
git commit -m "security: prevent secrets in git"
Best Practices
1. Use Environment Variables
import os
from functools import lru_cache
@lru_cache
def get_settings():
return Settings()
settings = get_settings()
2. Separate Config Files
project/
├── config/
│ ├── settings.py # Settings class
│ ├── production.py # Prod config (no secrets!)
│ └── development.py # Dev config (no secrets!)
├── .env # Secrets (gitignored!)
└── .env.example # Template (committed)
3. Use Secret Management
# For production, use secr
Установить secret-scanner в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Bash(git:*, grep:*)FAQ
Что делает скилл secret-scanner?
Detects API keys, passwords, and secrets in code before they reach git. Use before commits, when working with credentials, or when user mentions "security check" or "secrets".
Как установить скилл secret-scanner?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл secret-scanner запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic