Gitleaks — Find Secrets in Git Repos and Code
Gitleaks is a fast SAST tool for detecting hardcoded secrets like passwords, API keys, and tokens in Git repositories. It scans commit history and source code using regex patterns, preventing secret leaks before they reach production.
Staging sûr pour cet actif
Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.
npx -y tokrepo@latest install 40b108c4-372b-11f1-9bc6-00163e2b0d79 --target codexStage les fichiers d'abord; l'activation exige la revue du README et du plan staged.
What it is
Gitleaks is a fast static application security testing (SAST) tool for detecting hardcoded secrets in Git repositories. It scans commit history and source code using regex patterns to find AWS keys, database passwords, API tokens, private keys, and other credentials that should never be committed.
Gitleaks is designed for security engineers and developers who want to prevent secret leaks before they reach production, integrated into CI/CD pipelines and pre-commit hooks.
How it saves time or tokens
Gitleaks scans entire Git histories in seconds, catching secrets that were committed and later deleted but still exist in history. Running it as a pre-commit hook prevents secrets from being committed in the first place. This avoids the costly process of rotating compromised credentials after a leak.
How to use
- Install Gitleaks:
brew install gitleaks
# Or: go install github.com/gitleaks/gitleaks/v8@latest
- Scan your repository:
# Scan all commits
gitleaks detect
# Scan only staged changes (pre-commit)
gitleaks protect --staged
# Scan a directory without Git
gitleaks dir -s ./src
- Add as a pre-commit hook for continuous protection
Example
# Output results as JSON for CI integration
gitleaks detect --report-format json --report-path results.json
# Custom config for additional patterns
cat > .gitleaks.toml << 'EOF'
[[rules]]
id = 'custom-api-key'
description = 'Custom API Key'
regex = '''MYAPP_API_KEY=[a-zA-Z0-9]{32}'''
[rules.allowlist]
paths = ['test/', 'docs/']
EOF
gitleaks detect -c .gitleaks.toml
Related on TokRepo
- Security tools — security scanning and auditing resources
- DevOps tools — CI/CD pipeline integration tools
Common pitfalls
- Not scanning Git history (use
detectnot justdir), which misses secrets in deleted commits - Generating too many false positives without configuring allowlists for test data
- Running Gitleaks only in CI without a pre-commit hook, allowing secrets to enter the repo first
Questions fréquentes
Gitleaks scans the entire Git history by default and comes with a comprehensive built-in ruleset for common secret patterns. git-secrets by AWS focuses on preventing commits and requires manual rule configuration. Gitleaks is faster and has broader pattern coverage.
Yes. Gitleaks provides a GitHub Action, and works in any CI system. Run gitleaks detect in your pipeline and fail the build on findings. JSON output integrates with security dashboards.
Add a .gitleaks.toml config with allowlists for specific paths, commits, or patterns. You can also add inline comments with gitleaks:allow to suppress specific findings.
Yes. Use gitleaks dir -s ./path to scan any directory without Git history. This is useful for scanning build artifacts, config files, or code before it enters version control.
Gitleaks detects AWS keys, GCP credentials, Azure tokens, GitHub tokens, private keys, database connection strings, API keys for major services, JWTs, and many more through its built-in regex rules.
Sources citées (3)
- Gitleaks GitHub— Gitleaks SAST tool for detecting secrets
- Gitleaks Documentation— Secret detection regex patterns
- OWASP SAST— Static application security testing best practices
En lien sur TokRepo
Fil de discussion
Actifs similaires
Trivy — All-in-One Security Scanner for Containers & Code
Trivy is an open-source, comprehensive security scanner that finds vulnerabilities, misconfigurations, secrets, and SBOM issues in containers, Kubernetes, code repos, and clouds.
fd — A Simple Fast User-Friendly Alternative to find
fd is a simple, fast, and user-friendly alternative to the venerable find command. Written in Rust with smart defaults: color output, gitignore-aware, parallel traversal, and intuitive syntax. Used by VS Code, Helix, and many dev tools.
Sealed Secrets — One-Way Encrypted Kubernetes Secrets
Sealed Secrets is a Bitnami Labs controller and kubeseal CLI that lets teams commit encrypted secrets safely to Git, and have a cluster-side controller decrypt them into real Secrets at apply time.
External Secrets Operator — Sync Secrets from Any Vault to Kubernetes
CNCF operator that pulls secrets from AWS Secrets Manager, Vault, GCP, Azure, 1Password, Doppler, and 25+ other backends into native Kubernetes Secret objects.