-
Notifications
You must be signed in to change notification settings - Fork 0
feat: add gitleaks and trufflehog secret scanning hooks #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| #!/usr/bin/env bash | ||
| # gitleaks — scan staged changes for secrets using pattern matching. | ||
| # Catches 150+ secret types: API keys, tokens, passwords, connection strings. | ||
| # | ||
| # Requires: gitleaks in PATH | ||
| # brew install gitleaks (macOS) | ||
| # apt-get install gitleaks (Debian/Ubuntu) | ||
| # | ||
| # Per-repo config: place .gitleaks.toml in repo root to customize rules. | ||
| # See: https://github.com/gitleaks/gitleaks#configuration | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if ! command -v gitleaks &> /dev/null; then | ||
| echo "⚠ gitleaks not found — secret scanning skipped" | ||
| echo " Install: brew install gitleaks" | ||
| exit 0 | ||
| fi | ||
|
|
||
| repo_root="$(git rev-parse --show-toplevel)" | ||
|
|
||
| # Use per-repo config if present, otherwise use gitleaks defaults | ||
| config_args=() | ||
| if [[ -f "$repo_root/.gitleaks.toml" ]]; then | ||
| config_args=(--config "$repo_root/.gitleaks.toml") | ||
| fi | ||
|
|
||
| if ! gitleaks protect --staged --source "$repo_root" --exit-code 1 --no-banner "${config_args[@]}" 2>&1; then | ||
| echo "" | ||
| echo "✗ gitleaks: secrets detected in staged changes" | ||
| echo " Remove secrets, then re-stage the corrected files." | ||
| echo " False positive? Add an allowlist entry to .gitleaks.toml" | ||
| echo " To bypass (emergency only): git commit --no-verify" | ||
| exit 1 | ||
| fi |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #!/usr/bin/env bash | ||
| # trufflehog — scan for verified secrets using entropy analysis + pattern matching. | ||
| # Uses --only-verified to suppress noise: only reports secrets that were confirmed | ||
| # active against the issuing service (reduces false positives significantly). | ||
| # | ||
| # Requires: trufflehog in PATH | ||
| # brew install trufflehog (macOS) | ||
| # See: https://github.com/trufflesecurity/trufflehog#installation | ||
| # | ||
| # Note: complements gitleaks (pattern-based). TruffleHog's verification step | ||
| # catches live secrets that pattern-only tools would flag as low-confidence. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| if ! command -v trufflehog &> /dev/null; then | ||
| echo "⚠ trufflehog not found — verified secret scanning skipped" | ||
| echo " Install: brew install trufflehog" | ||
| exit 0 | ||
| fi | ||
|
|
||
| repo_root="$(git rev-parse --show-toplevel)" | ||
|
|
||
| if ! trufflehog git "file://$repo_root" \ | ||
| --since-commit HEAD \ | ||
| --only-verified \ | ||
| --fail \ | ||
| --no-update \ | ||
|
Comment on lines
+23
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Functional Concern: This command may not properly scan staged (uncommitted) changes. The For a pre-commit hook to catch secrets in staged changes (matching gitleaks behavior with
Reference: gitleaks explicitly uses |
||
| 2>&1; then | ||
| echo "" | ||
| echo "✗ trufflehog: verified live secrets detected" | ||
| echo " Revoke these credentials immediately, then remove from code." | ||
| echo " To bypass (emergency only): git commit --no-verify" | ||
| exit 1 | ||
| fi | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In a pre-commit hook context,
--since-commit HEADwill not scan the changes currently being committed (the staged changes). To ensure that secrets in the current commit attempt are caught, you should use the--stagedflag instead.