| created | "2025-12-16T00:00:00.000Z" |
| modified | "2026-05-09T00:00:00.000Z" |
| reviewed | "2026-04-25T00:00:00.000Z" |
| name | git-security-checks |
| description | Pre-commit security validation and secret detection via gitleaks. Use when scanning for secrets, setting up gitleaks, or configuring .gitleaks.toml pre-commit security. |
| user-invocable | false |
| allowed-tools | Bash, Read |
Git Security Checks
When to Use This Skill
| Use this skill when... | Use the alternative when... |
|---|
Running gitleaks to scan for secrets before committing | Use git-commit-workflow for general staging and commit-message conventions |
Configuring .gitleaks.toml allowlists and pre-commit integration | Use git-maintain for git fsck integrity checks rather than secret scanning |
| Validating that no credentials leak into a PR | Use git-fix-pr when CI gitleaks scans fail and you need to fix them on branch |
| Setting up pre-commit hooks for credential scanning | Use release-please-protection to detect manual edits to release-managed files |
Expert guidance for pre-commit security validation and secret detection using gitleaks and pre-commit hooks.
Core Expertise
- gitleaks: Scan for hardcoded secrets and credentials using regex + entropy analysis
- Pre-commit Hooks: Automated security validation before commits
- Declarative Allowlisting: Manage false positives via
.gitleaks.toml configuration
- Security-First Workflow: Prevent credential leaks before they happen
Quick Security Scan (Recommended)
Run the comprehensive security scan pipeline in one command:
bash "${CLAUDE_PLUGIN_ROOT}/skills/git-security-checks/scripts/security-scan.sh"
bash "${CLAUDE_PLUGIN_ROOT}/skills/git-security-checks/scripts/security-scan.sh" --staged-only
The script checks: gitleaks scan, sensitive file patterns, .gitignore coverage, high-entropy strings in diffs, and pre-commit hook status. See scripts/security-scan.sh for details.
Gitleaks Workflow
Initial Setup
brew install gitleaks
go install github.com/gitleaks/gitleaks/v8@latest
gitleaks detect --source .
gitleaks detect --source . --verbose
Configuration
Create .gitleaks.toml for project-specific allowlists:
title = "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''',
]
Pre-commit Scan Workflow
Run gitleaks before every commit:
gitleaks detect --source .
gitleaks protect --staged
gitleaks detect --source . --config .gitleaks.toml
Managing False Positives
Gitleaks provides three declarative methods for handling false positives:
1. Inline comments — mark specific lines:
API_KEY = "fake-key-for-testing-only"
password = "test-fixture"
2. Path-based exclusions — in .gitleaks.toml:
[allowlist]
paths = [
'''test/fixtures/.*''',
'''.*\.example$''',
'''package-lock\.json$''',
]
3. Regex-based allowlists — for specific patterns:
[allowlist]
regexes = [
'''example\.com''',
'''localhost''',
'''PLACEHOLDER''',
]
4. Per-rule allowlists — target specific detection rules:
[[rules]]
id = "generic-api-key"
description = "Generic API Key"
[rules.allowlist]
regexes = ['''test-api-key-.*''']
paths = ['''test/.*''']
Complete Pre-commit Security Flow
gitleaks protect --staged
pre-commit run --all-files --show-diff-on-failure
git add src/file.ts
git status
git diff --cached --stat
git commit -m "feat(auth): add authentication module"
Pre-commit Hook Integration
.pre-commit-config.yaml
Example configuration with gitleaks:
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.22.1
hooks:
- id: gitleaks
Running Pre-commit Hooks
pre-commit run --all-files
pre-commit run
pre-commit run gitleaks
pre-commit run --all-files --show-diff-on-failure
pre-commit install
Common Secret Patterns
Gitleaks ships with 140+ built-in rules covering:
- API Keys: AWS, GitHub, Stripe, Google, Azure, etc.
- Authentication Tokens: JWT, OAuth tokens, session tokens
- Passwords: Hardcoded passwords in config files
- Private Keys: RSA, SSH, PGP private keys
- Database Credentials: Connection strings with passwords
- Generic Secrets: High-entropy strings that look like secrets
Examples of What Gets Detected
API_KEY = "sk_live_abc123def456ghi789"
aws_access_key_id = AKIAIOSFODNN7EXAMPLE
DB_URL = "postgresql://user:Pa$$w0rd@localhost/db"
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA...
Managing False Positives
Excluding Files
In .gitleaks.toml:
[allowlist]
paths = [
'''package-lock\.json$''',
'''.*\.lock$''',
'''test/.*\.py$''',
]
Inline Ignore Comments
api_key = "test-key-1234"
password = "fake-password"
Security Best Practices
Never Commit Secrets
- Use environment variables: Store secrets in .env files (gitignored)
- Use secret managers: AWS Secrets Manager, HashiCorp Vault, etc.
- Use CI/CD secrets: GitHub Secrets, GitLab CI/CD variables
- Rotate leaked secrets: If accidentally committed, rotate immediately
Secrets File Management
.env
.env.local
.env.*.local
*.pem
*.key
credentials.json
config/secrets.yml
.api_tokens
Handling Legitimate Secrets in Repo
For test fixtures or examples:
API_KEY = "fake-key-for-testing-only"
API_KEY = "<your-api-key-here>"
Emergency: Secret Leaked to Git History
If a secret is committed and pushed:
Immediate Actions
git reset --soft HEAD~1
git add .
git commit -m "fix(security): remove leaked credentials"
git push --force-with-lease origin branch-name
Full History Cleanup
pip install git-filter-repo
git filter-repo --path path/to/secret/file --invert-paths
git filter-repo --replace-text <(echo "SECRET_KEY=abc123==>SECRET_KEY=REDACTED")
Prevention
pre-commit run gitleaks
git diff --cached
echo ".env" >> .gitignore
echo ".api_tokens" >> .gitignore
Workflow Integration
Daily Development Flow
gitleaks protect --staged
pre-commit run --all-files
git add src/feature.ts
git diff --cached
gitleaks protect --staged
git commit -m "feat(feature): add new capability"
CI/CD Integration
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 }}
Troubleshooting
Too Many False Positives
gitleaks detect --source . --verbose 2>&1 | head -50
Pre-commit Hook Failing
pre-commit run gitleaks --verbose
gitleaks detect --source . --config .gitleaks.toml --verbose
pre-commit autoupdate
Scanning Git History
gitleaks detect --source . --log-opts="--all"
gitleaks detect --source . --log-opts="HEAD~10..HEAD"
gitleaks detect --source . --report-format json --report-path gitleaks-report.json
Tools Reference
Gitleaks Commands
gitleaks detect --source .
gitleaks protect --staged
gitleaks detect --source . --config .gitleaks.toml
gitleaks detect --source . --verbose
gitleaks detect --source . --report-format json --report-path report.json
gitleaks detect --source . --log-opts="--all"
gitleaks detect --source . --log-opts="main..HEAD"
pre-commit Commands
pre-commit install
pre-commit run --all-files
pre-commit run gitleaks
pre-commit autoupdate
pre-commit uninstall