Sachin Chaurasiya

Secure · Secrets detection

Gitleaks

Gitleaks scans commits, branches and directories for credentials using regex and entropy rules. Runs in pre-commit hooks and CI, with SARIF/JSON reporting and fingerprint-based ignores.

Stage
Secure
Category
Secrets detection
Documentation
Official docs
License
MIT
On this page

What it does

Scans Git history (gitleaks git) or a directory (gitleaks dir) for secrets using an extensible TOML ruleset. Findings carry a fingerprint that can be allowlisted in .gitleaksignore.

Where it fits

Secure stage, but its best location is the developer’s machine as a pre-commit hook, backed by a CI job on merge requests and a nightly full-history scan.

Quick start

gitleaks git --redact --exit-code 1 --report-format sarif --report-path gitleaks.sarif .
gitleaks dir --redact .

Common pitfalls

  • Forgetting --redact turns the CI log into a second leak.
  • Shallow CI clones (GIT_DEPTH: 1) scan almost nothing in git mode.
  • Allowlisting whole directories to silence noise; allowlist lockfiles and fixtures by path instead.

On this site

  • Secrets and Configuration Security: where secret detection fits in the lifecycle, and what Gitleaks and Trivy both missed in a build context (a random database password with no keyword).

Hands-on labs using Gitleaks

Lab

Scan Git Repositories with Gitleaks

Seed a repository with realistic fake secrets, catch them with Gitleaks in history and working-tree modes, ignore a confirmed false positive by fingerprint, and block the next one at commit time.

beginner 25 minutes Gitleaks

Articles about Gitleaks

DevSecOps beginner

Secrets Detection with Gitleaks

Stop credentials from reaching Git: run Gitleaks in pre-commit hooks and CI, tune rules and allowlists, handle findings without leaking them further, and decide when history rewriting is worth it.

8 min read
CI/CD intermediate

Building a Secure CI/CD Pipeline with Jenkins

A declarative Jenkins pipeline with secrets scanning, SAST, image scanning and least-privilege credential handling — and the agent, plugin and Docker decisions that keep it that way.

9 min read