Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Hardcoded secret detection and prevention in git repositories and codebases using Gitleaks. Identifies passwords, API keys, tokens, and credentials through regex-based pattern matching and entropy analysis. Use when: (1) Scanning repositories for exposed secrets and credentials, (2) Implementing pre-commit hooks to prevent secret leakage, (3) Integrating secret detection into CI/CD pipelines, (4) Auditing codebases for compliance violations (PCI-DSS, SOC2, GDPR), (5) Establishing baseline secret
.claude/skills/aiskillstore-secrets-gitleaks/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-15 | ✗→✓ | ▲ Improved | 159% | 0% |
| case-20 | ✗→✓ | ▲ Improved | 116% | 0% |
| case-01 | ✓→✓ | = Same ✓ | 123% | 0% |
| case-02 | ✓→✓ | = Same ✓ | 415% | 0% |
| case-03 | ✓→✓ | = Same ✓ | 362% | 0% |
Gitleaks is a secret detection tool that scans git repositories, files, and directories for hardcoded credentials including passwords, API keys, tokens, and other sensitive information. It uses regex-based pattern matching combined with Shannon entropy analysis to identify secrets that could lead to unauthorized access if exposed.
This skill provides comprehensive guidance for integrating Gitleaks into DevSecOps workflows, from pre-commit hooks to CI/CD pipelines, with emphasis on preventing secret leakage before code reaches production.
Scan current repository for secrets:
bash# Install gitleaks brew install gitleaks # macOS # or: docker pull zricethezav/gitleaks:latest # Scan current git repository gitleaks detect -v # Scan specific directory gitleaks detect --source /path/to/code -v # Generate report gitleaks detect --report-path gitleaks-report.json --report-format json
Scan existing repositories to identify exposed secrets:
bash# Full repository scan with verbose output gitleaks detect -v --source /path/to/repo # Scan with custom configuration gitleaks detect --config .gitleaks.toml -v # Generate JSON report for further analysis gitleaks detect --report-path findings.json --report-format json # Generate SARIF report for GitHub/GitLab integration gitleaks detect --report-path findings.sarif --report-format sarif
When to use: Initial security audit, compliance checks, incident response.
Prevent secrets from being committed in the first place:
bash# Install pre-commit hook (run in repository root) cat << 'EOF' > .git/hooks/pre-commit #!/bin/sh gitleaks protect --verbose --redact --staged EOF chmod +x .git/hooks/pre-commit
Use the bundled script for automated hook installation:
bash./scripts/install_precommit.sh
When to use: Developer workstation setup, team onboarding, mandatory security controls.
yamlname: gitleaks on: [push, pull_request] jobs: scan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 with: fetch-depth: 0 - uses: gitleaks/gitleaks-action@v2 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
yamlgitleaks: image: zricethezav/gitleaks:latest stage: test script: - gitleaks detect --report-path gitleaks.json --report-format json --verbose artifacts: paths: - gitleaks.json when: always allow_failure: false
When to use: Automated security gates, pull request checks, release validation.
Establish security baseline and track only new secrets:
bash# Create initial baseline gitleaks detect --report-path baseline.json --report-format json # Subsequent scans detect only new secrets gitleaks detect --baseline-path baseline.json --report-path new-findings.json -v
When to use: Legacy codebase remediation, phased rollout, compliance tracking.
Create custom .gitleaks.toml configuration:
tomltitle = "Custom Gitleaks Configuration" [extend] # Extend default config with custom rules useDefault = true [[rules]] id = "custom-api-key" description = "Custom API Key Pattern" regex = '''(?i)(custom_api_key|custom_secret)[\s]*[=:][\s]*['"][a-zA-Z0-9]{32,}['"]''' tags = ["api-key", "custom"] [allowlist] description = "Global allowlist" paths = [ '''\.md$''', # Ignore markdown files '''test/fixtures/''', # Ignore test fixtures ] stopwords = [ '''EXAMPLE''', # Ignore example keys '''PLACEHOLDER''', ]
Use bundled configuration templates in assets/:
assets/config-strict.toml - Strict detection (low false negatives)assets/config-balanced.toml - Balanced detection (recommended)assets/config-custom.toml - Template for custom rulesWhen to use: Reducing false positives, adding proprietary secret patterns, organizational standards.
--redact flag in logs and reports to prevent accidental secret exposuregit filter-repo or BFG Repo-CleanerLog the following for compliance and incident response:
scripts/)install_precommit.sh - Automated pre-commit hook installation with configuration promptsscan_and_report.py - Comprehensive scanning with multiple output formats and severity classificationbaseline_manager.py - Baseline creation, comparison, and incremental scan managementreferences/)detection_rules.md - Comprehensive list of built-in Gitleaks detection rules with CWE mappingsremediation_guide.md - Step-by-step secret remediation procedures including git history cleanupfalse_positives.md - Common false positive patterns and allowlist configuration strategiescompliance_mapping.md - Detailed mapping to PCI-DSS, SOC2, GDPR, and OWASP requirementsassets/)config-strict.toml - High-sensitivity configuration (maximum detection)config-balanced.toml - Production-ready balanced configurationconfig-custom.toml - Template with inline documentation for custom rulesprecommit-config.yaml - Pre-commit framework configurationgithub-action.yml - Complete GitHub Actions workflow templategitlab-ci.yml - Complete GitLab CI pipeline templateFirst-time secret scanning for security assessment:
bash# 1. Clone repository with full history git clone --mirror https://github.com/org/repo.git audit-repo cd audit-repo # 2. Run comprehensive scan gitleaks detect --report-path audit-report.json --report-format json -v # 3. Generate human-readable report ./scripts/scan_and_report.py --input audit-report.json --format markdown --output audit-report.md # 4. Review findings and classify false positives # Edit .gitleaks.toml to add allowlist entries # 5. Create baseline for future scans cp audit-report.json baseline.json
Protect developers from accidental secret commits:
bash# 1. Install gitleaks locally brew install gitleaks # macOS # or use package manager for your OS # 2. Install pre-commit hook ./scripts/install_precommit.sh # 3. Test hook with dummy commit echo "api_key = 'EXAMPLE_KEY_12345'" > test.txt git add test.txt git commit -m "test" # Should be blocked by gitleaks # 4. Clean up test git reset HEAD~1 rm test.txt
Progressive secret detection in continuous integration:
bash# In CI pipeline script: # 1. Check if baseline exists if [ -f ".gitleaks-baseline.json" ]; then # Incremental scan - only new secrets gitleaks detect \ --baseline-path .gitleaks-baseline.json \ --report-path new-findings.json \ --report-format json \ --exit-code 1 # Fail on new secrets else # Initial scan - create baseline gitleaks detect \ --report-path .gitleaks-baseline.json \ --report-format json \ --exit-code 0 # Don't fail on first scan fi # 2. Generate SARIF for GitHub Security tab if [ -f "new-findings.json" ] && [ -s "new-findings.json" ]; then gitleaks detect \ --baseline-path .gitleaks-baseline.json \ --report-path results.sarif \ --report-format sarif fi
Add organization-specific secret patterns:
toml# Add to .gitleaks.toml [[rules]] id = "acme-corp-api-key" description = "ACME Corp Internal API Key" regex = '''(?i)acme[_-]?api[_-]?key[\s]*[=:][\s]*['"]?([a-f0-9]{40})['"]?''' secretGroup = 1 tags = ["api-key", "acme-internal"] [[rules]] id = "acme-corp-database-password" description = "ACME Corp Database Password Format" regex = '''(?i)(db_pass|database_password)[\s]*[=:][\s]*['"]([A-Z][a-z0-9@#$%]{15,})['"]''' secretGroup = 2 tags = ["password", "database", "acme-internal"] # Test custom rules # gitleaks detect --config .gitleaks.toml -v
gitleaks/gitleaks-action@v2 for native integration with Security tabSymptoms: Legitimate code patterns flagged as secrets (test fixtures, examples, placeholders)
Solution:
grep -i "example\|test\|placeholder" gitleaks-report.json.gitleaks.toml:toml [allowlist] paths = ['''test/''', '''examples/''', '''\.md$'''] stopwords = ["EXAMPLE", "PLACEHOLDER", "YOUR_API_KEY_HERE"]
toml [allowlist] commits = ["commit-sha-here"]
references/false_positives.md for common patternsSymptoms: Scans taking excessive time (>10 minutes), high memory usage
Solution:
--log-opts to limit git history: gitleaks detect --log-opts="--since=2024-01-01"gitleaks detect --log-opts="origin/main"git clone --depth=1000Symptoms: Developers unable to commit code with legitimate patterns
Solution:
# gitleaks:allow.gitleaks.toml allowlist for the specific pattern--redact to safely review findings: gitleaks protect --staged --redactgit commit --no-verifySymptoms: Secrets detected in old commits, already removed from current code
Solution:
git filter-repo (recommended): git filter-repo --path-glob '*.env' --invert-pathsbfg --delete-files credentials.jsongit push --forcereferences/remediation_guide.md for detailed proceduresSymptoms: Organization-specific secrets not caught by default rules
Solution:
.gitleaks.toml:toml [[rules]] id = "custom-secret-id" description = "Description" regex = '''your-pattern-here''' secretGroup = 1 # Capture group containing actual secret
gitleaks detect --config .gitleaks.toml -v --no-gittoml [[rules.Entropies]] Min = "3.5" Max = "7.0" Group = "1"
For secrets without clear patterns, use Shannon entropy analysis:
toml[[rules]] id = "high-entropy-strings" description = "High entropy strings that may be secrets" regex = '''[a-zA-Z0-9]{32,}''' entropy = 4.5 # Shannon entropy threshold secretGroup = 0
Detect secrets spanning multiple lines or requiring context:
toml[[rules]] id = "multi-line-secret" description = "API key with usage context" regex = '''api_key[\s]*=''' [[rules.composite]] pattern = '''initialize_client''' location = "line" # Must be within same line proximity distance = 5 # Within 5 lines
toml# Global allowlist (highest precedence) [allowlist] description = "Organization-wide exceptions" paths = ['''vendor/''', '''node_modules/'''] # Rule-specific allowlist [[rules]] id = "generic-api-key" [rules.allowlist] description = "Exceptions only for this rule" regexes = ['''key\s*=\s*EXAMPLE''']
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | pass→pass | 15,327 | 13,306 | -13% | 1 | 1 | 0% | 3,016 | 6,733 | +123% | 0 | 0 | — |
case-02 | pass→pass | 5,376 | 4,578 | -15% | 1 | 1 | 0% | 956 | 4,926 | +415% | 0 | 0 | — |
case-03 | pass→pass | 5,801 | 4,483 | -23% | 1 | 1 | 0% | 1,077 | 4,972 | +362% | 0 | 0 | — |
case-04 | pass→pass | 4,627 | 4,332 | -6% | 1 | 1 | 0% | 841 | 4,945 | +488% | 0 | 0 | — |
case-05 | pass→pass | 13,868 | 13,866 | -0% | 1 | 1 | 0% | 2,455 | 6,629 | +170% | 0 | 0 | — |
case-06 | pass→pass | 13,641 | 13,759 | +1% | 1 | 1 | 0% | 2,294 | 6,446 | +181% | 0 | 0 | — |
case-07 | pass→pass | 14,788 | 11,834 | -20% | 1 | 1 | 0% | 2,703 | 6,394 | +137% | 0 | 0 | — |
case-08 | pass→pass | 3,688 | 4,672 | +27% | 1 | 1 | 0% | 544 | 4,673 | +759% | 0 | 0 | — |
case-09 | pass→pass | 3,568 | 3,504 | -2% | 1 | 1 | 0% | 655 | 4,728 | +622% | 0 | 0 | — |
case-10 | pass→pass | 3,161 | 3,041 | -4% | 1 | 1 | 0% | 552 | 4,585 | +731% | 0 | 0 | — |
case-11 | pass→pass | 8,327 | 4,549 | -45% | 1 | 1 | 0% | 1,633 | 4,895 | +200% | 0 | 0 | — |
case-12 | pass→pass | 3,930 | 2,267 | -42% | 1 | 1 | 0% | 724 | 4,508 | +523% | 0 | 0 | — |
case-13 | pass→pass | 4,077 | 5,535 | +36% | 1 | 1 | 0% | 772 | 5,081 | +558% | 0 | 0 | — |
case-14 | pass→pass | 4,938 | 2,609 | -47% | 1 | 1 | 0% | 765 | 4,643 | +507% | 0 | 0 | — |
case-15 | fail→pass | 10,121 | 4,230 | -58% | 1 | 1 | 0% | 1,851 | 4,788 | +159% | 0 | 0 | — |
case-16 | pass→pass | 2,788 | 4,223 | +51% | 1 | 1 | 0% | 433 | 4,419 | +921% | 0 | 0 | — |
case-17 | pass→pass | 8,002 | 3,361 | -58% | 1 | 1 | 0% | 1,501 | 4,708 | +214% | 0 | 0 | — |
case-18 | pass→pass | 3,129 | 3,112 | -1% | 1 | 1 | 0% | 642 | 4,741 | +638% | 0 | 0 | — |
case-19 | pass→pass | 2,465 | 2,056 | -17% | 1 | 1 | 0% | 386 | 4,474 | +1059% | 0 | 0 | — |
case-20 | fail→pass | 12,341 | 4,289 | -65% | 1 | 1 | 0% | 2,144 | 4,622 | +116% | 0 | 0 | — |
case-21 | pass→pass | 3,933 | 3,216 | -18% | 1 | 1 | 0% | 700 | 4,685 | +569% | 0 | 0 | — |
case-22 | pass→pass | 6,885 | 7,058 | +3% | 1 | 1 | 0% | 1,231 | 5,358 | +335% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted. The headline lift of +9 percentage points is the difference between those two pass rates over the 22 comparable cases.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
Other measured skills in the registry, with their headline benchmark lift.