feat: add gitleaks and trufflehog secret scanning hooks#3
feat: add gitleaks and trufflehog secret scanning hooks#3injectedfusion wants to merge 1 commit intomainfrom
Conversation
Adds defense-in-depth secret detection: - gitleaks: 150+ patterns for staged changes (gitleaks protect --staged) - trufflehog: entropy + pattern + live verification (--only-verified) Both are language: system / graceful-skip when binary not in PATH. no-hardcoded-secrets retained for backward compat with repos not on system binaries. Closes: will reference from rk1-k8s-apps and other injectedfusion repos
Summary of ChangesHello @injectedfusion, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the repository's security posture by introducing two new pre-commit hooks: Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
Claude finished @injectedfusion's task in 56s —— View job Code Review: Secret Scanning HooksStatus: 🔄 Needs Changes ✅ StrengthsShell Script Quality:
Hook Configuration (.pre-commit-hooks.yaml):
Security Posture:
|
| if ! trufflehog git "file://$repo_root" \ | ||
| --since-commit HEAD \ | ||
| --only-verified \ | ||
| --fail \ | ||
| --no-update \ |
There was a problem hiding this comment.
Functional Concern: This command may not properly scan staged (uncommitted) changes. The --since-commit HEAD flag scans commits since HEAD, but pre-commit hooks run on staged files that haven't been committed yet.
For a pre-commit hook to catch secrets in staged changes (matching gitleaks behavior with --staged), trufflehog needs to scan the current working state. Consider:
- Verify with
trufflehog git file://... --since-commit HEAD~1..HEADto check recent commits, OR - Use
trufflehog filesystemmode to scan the working directory, OR - Document this limitation if the intent is to only catch committed secrets
Reference: gitleaks explicitly uses gitleaks protect --staged to scan only staged changes. This hook should have equivalent behavior.
There was a problem hiding this comment.
Code Review
The addition of gitleaks and trufflehog provides a robust multi-layered approach to secret detection. The scripts are well-implemented with graceful fallbacks when binaries are missing. However, there is a significant logic issue in the trufflehog hook configuration that prevents it from scanning the staged changes during a commit.
| repo_root="$(git rev-parse --show-toplevel)" | ||
|
|
||
| if ! trufflehog git "file://$repo_root" \ | ||
| --since-commit HEAD \ |
There was a problem hiding this comment.
Summary
gitleaks protect --staged): 150+ regex patterns covering API keys, tokens, passwords, connection strings. Runs on every commit, gracefully skips if binary missing.--only-verified): Entropy + pattern matching with live verification against issuing services. Only fails on confirmed active secrets — far lower FP rate than pattern-only tools.no-hardcoded-secretsretained for repos that cannot install system binaries (backward compat).Defense in depth
no-hardcoded-secretsgitleakstrufflehogInstallation requirement
Both hooks use
language: scriptwith graceful skip when binary not found:Test plan
AKIA...AWS key pattern) in staged file