Loading...
Loading...
Pre-commit security validation and secret detection. Runs gitleaks scan and validates configuration, integrates with pre-commit hooks to prevent credential leaks. Use when user mentions scanning for secrets, gitleaks, secret detection, credential scanning, pre-commit security, or .gitleaks.toml.
npx skill4agent add laurigates/claude-plugins git-security-checks.gitleaks.toml# Full scan: check all tracked files
bash "${CLAUDE_PLUGIN_ROOT}/skills/git-security-checks/scripts/security-scan.sh"
# Staged-only: check only files about to be committed
bash "${CLAUDE_PLUGIN_ROOT}/skills/git-security-checks/scripts/security-scan.sh" --staged-only# Install gitleaks (macOS)
brew install gitleaks
# Install gitleaks (Go)
go install github.com/gitleaks/gitleaks/v8@latest
# Install gitleaks (binary download)
# See https://github.com/gitleaks/gitleaks/releases
# Scan repository
gitleaks detect --source .
# Scan with verbose output
gitleaks detect --source . --verbose.gitleaks.tomltitle = "Gitleaks Configuration"
[extend]
useDefault = true
[allowlist]
description = "Project-wide allowlist for false positives"
paths = [
'''test/fixtures/.*''',
'''.*\.test\.(ts|js)$''',
]
regexes = [
'''example\.com''',
'''localhost''',
'''fake-key-for-testing''',
]# Scan for secrets in current state
gitleaks detect --source .
# Scan only staged changes (pre-commit mode)
gitleaks protect --staged
# Scan with specific config
gitleaks detect --source . --config .gitleaks.toml# This line is safe
API_KEY = "fake-key-for-testing-only" # gitleaks:allow
# Works in any language
password = "test-fixture" # gitleaks:allow.gitleaks.toml[allowlist]
paths = [
'''test/fixtures/.*''',
'''.*\.example$''',
'''package-lock\.json$''',
][allowlist]
regexes = [
'''example\.com''',
'''localhost''',
'''PLACEHOLDER''',
][[rules]]
id = "generic-api-key"
description = "Generic API Key"
[rules.allowlist]
regexes = ['''test-api-key-.*''']
paths = ['''test/.*''']# 1. Scan for secrets
gitleaks protect --staged
# 2. Run all pre-commit hooks
pre-commit run --all-files --show-diff-on-failure
# 3. Stage your actual changes
git add src/file.ts
# 4. Show what's staged
git status
git diff --cached --stat
# 5. Commit if everything passes
git commit -m "feat(auth): add authentication module"repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.22.1
hooks:
- id: gitleaks# Run all hooks on all files
pre-commit run --all-files
# Run all hooks on staged files only
pre-commit run
# Run specific hook
pre-commit run gitleaks
# Show diff on failure for debugging
pre-commit run --all-files --show-diff-on-failure
# Install hooks to run automatically on commit
pre-commit install# Detected: Hardcoded API key
API_KEY = "sk_live_abc123def456ghi789" # gitleaks:allow
# Detected: AWS credentials
aws_access_key_id = AKIAIOSFODNN7EXAMPLE # gitleaks:allow
# Detected: Database password
DB_URL = "postgresql://user:Pa$$w0rd@localhost/db" # gitleaks:allow
# Detected: Private key # gitleaks:allow
-----BEGIN RSA PRIVATE KEY----- # gitleaks:allow
MIIEpAIBAAKCAQEA... # gitleaks:allow.gitleaks.toml[allowlist]
paths = [
'''package-lock\.json$''',
'''.*\.lock$''',
'''test/.*\.py$''',
]# In code, mark false positives
api_key = "test-key-1234" # gitleaks:allow
# Works in any language comment style
password = "fake-password" # gitleaks:allow# Example .gitignore for secrets
.env
.env.local
.env.*.local
*.pem
*.key
credentials.json
config/secrets.yml
.api_tokens# 1. Use obviously fake values
API_KEY = "fake-key-for-testing-only" # gitleaks:allow
# 2. Use placeholders
API_KEY = "<your-api-key-here>" # gitleaks:allow
# 3. Add path exclusion in .gitleaks.toml for test fixtures# 1. ROTATE THE SECRET IMMEDIATELY
# - Change passwords, revoke API keys, regenerate tokens
# - Do this BEFORE cleaning git history
# 2. Remove from current commit (if just committed)
git reset --soft HEAD~1
# Remove secret from files
git add .
git commit -m "fix(security): remove leaked credentials"
# 3. Force push (if not shared widely)
git push --force-with-lease origin branch-name# Use git-filter-repo to remove from all history
pip install git-filter-repo
# Remove specific file from all history
git filter-repo --path path/to/secret/file --invert-paths
# Remove specific string from all files
git filter-repo --replace-text <(echo "SECRET_KEY=abc123==>SECRET_KEY=REDACTED")# Always run security checks before committing
pre-commit run gitleaks
# Check what's being committed
git diff --cached
# Use .gitignore for sensitive files
echo ".env" >> .gitignore
echo ".api_tokens" >> .gitignore# Before staging any files
gitleaks protect --staged
pre-commit run --all-files
# Stage changes
git add src/feature.ts
# Final check before commit
git diff --cached # Review changes
gitleaks protect --staged # One more scan
# Commit
git commit -m "feat(feature): add new capability"# Example GitHub Actions workflow
name: Security Checks
on: [push, pull_request]
jobs:
security:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Gitleaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}# Check what rules are triggering
gitleaks detect --source . --verbose 2>&1 | head -50
# Add targeted allowlists in .gitleaks.toml
# Use path exclusions for test fixtures
# Use regex exclusions for known safe patterns
# Use inline gitleaks:allow for individual lines# Run pre-commit in verbose mode
pre-commit run gitleaks --verbose
# Check gitleaks config validity
gitleaks detect --source . --config .gitleaks.toml --verbose
# Update pre-commit hooks
pre-commit autoupdate# Scan entire git history for leaked secrets
gitleaks detect --source . --log-opts="--all"
# Scan specific commit range
gitleaks detect --source . --log-opts="HEAD~10..HEAD"
# Generate JSON report
gitleaks detect --source . --report-format json --report-path gitleaks-report.json# Detect secrets in repository
gitleaks detect --source .
# Protect staged changes (pre-commit mode)
gitleaks protect --staged
# Scan with custom config
gitleaks detect --source . --config .gitleaks.toml
# Verbose output
gitleaks detect --source . --verbose
# JSON report
gitleaks detect --source . --report-format json --report-path report.json
# Scan git history
gitleaks detect --source . --log-opts="--all"
# Scan specific commit range
gitleaks detect --source . --log-opts="main..HEAD"# Install hooks
pre-commit install
# Run all hooks
pre-commit run --all-files
# Run specific hook
pre-commit run gitleaks
# Update hook versions
pre-commit autoupdate
# Uninstall hooks
pre-commit uninstall