How do you handle false positives in Gitleaks?
IntermediateHands-onGitleaks
Answer
Short answer
Tell Gitleaks what to ignore as narrowly as possible: an inline gitleaks:allow comment for a single line, a .gitleaksignore file listing specific finding fingerprints, or an allowlist in .gitleaks.toml for paths, regexes or known test values. Never disable whole rules just to get a green build.
Options
1. Inline (one line)
TEST_TOKEN = "ghp_exampleexampleexampleexample00" # gitleaks:allow
2. .gitleaksignore (specific findings by fingerprint)
4f1c2a9e:tests/fixtures/sample.env:generic-api-key:3
The fingerprint is printed in the report (commit:file:rule:line).
3. Allowlist in .gitleaks.toml
[extend]
useDefault = true
[allowlist]
description = "Test fixtures and docs"
paths = ['''tests/fixtures/''', '''docs/examples/''']
regexes = ['''EXAMPLE''', '''dummy-password''']
Good practice
- Review allowlist changes in PRs like code.
- Prefer obviously fake test values (
AKIAIOSFODNN7EXAMPLE) so they don't look real. - Use a baseline for old historical findings you've already rotated, so only new leaks fail the build.
What to say in the interview
"I suppress as narrowly as possible: gitleaks:allow for one line, .gitleaksignore fingerprints for specific findings, and path or regex allowlists in .gitleaks.toml for fixtures. Allowlists are code-reviewed, and a baseline covers historical findings that were already rotated."
More on Gitleaks
What is Gitleaks and how do you use it?BeginnerWhat is a secret leak and why is it dangerous?BeginnerWhat is Gitleaks?BeginnerHow do you scan a repository's full history with Gitleaks and create a report?BeginnerHow do you stop secrets before they're committed using a pre-commit hook?BeginnerHow do you run Gitleaks in a CI pipeline and fail the build on findings?Beginner