Introducing a new way to review your PRs.

Read the announcement

gitleaks / gitleaks

Find secrets with Gitleaks 🔑

View on GitHub

10 documents · Updated Nov 16, 2026

overview

Knowledge Base updated: 2026-11-16

Knowledge Base Index

Orientation

Gitleaks is a Go CLI secret scanner. Its highest-level flow is: a user invokes a Cobra command, configuration/rules are loaded, scan sources produce fragments, the detector finds secrets, and reporters render findings.

Main parts:

  • cmd/ and main.go — CLI entrypoint, command wiring, scan/protect/diagnostics/generation commands.
  • config/ — rule, allowlist, and default configuration loading.
  • sources/ — file, directory, git, and fragment source abstractions.
  • detect/ — core detection pipeline, baseline handling, locations, git/file/reader scanning.
  • detect/codec/ — encoded-secret decoding support.
  • report/ and report_templates/ — finding models and output formats.
  • logging/, regexp/, version/ — cross-cutting runtime helpers.

Critical state is local and process-scoped: scan targets come from the filesystem, stdin, git history, or SCM inputs; rules come from config files/default embedded config; findings are emitted to stdout or report files. There is no database, cache, queue, or long-running server state in this repository.

Architecture diagrams

flowchart TD
  User[User / CI] --> Main[main.go]
  Main --> Cmd[cmd CLI commands]

  subgraph CLI[cmd]
    Cmd --> ScanCommands[detect/git/directory/stdin/protect]
    Cmd --> Generate[cmd/generate]
    Cmd --> Diagnostics[diagnostics/version/scm]
  end

  subgraph Inputs[scan inputs]
    Files[filesystem]
    Git[git repositories]
    Stdin[stdin]
    SCM[SCM integrations]
  end

  ScanCommands --> Config[config rules and allowlists]
  ScanCommands --> Sources[sources fragments]
  Files --> Sources
  Git --> Sources
  Stdin --> Sources
  SCM --> Sources

  Sources --> Detect[detect engine]
  Config --> Detect
  Codecs[detect/codec decoders] --> Detect
  Regex[regexp backend] --> Detect
  Detect --> Report[report formats]
  Report --> Output[stdout / files / CI reports]

  Logging[logging] --> Cmd
  Version[version] --> Cmd
flowchart LR
  Target[CLI scan target] --> Source[sources.Source]
  Source --> Fragment[Fragment content + metadata]
  Fragment --> Decoder[detect/codec optional decoding]
  Decoder --> Rules[config.Rule matching]
  Rules --> Allowlists[allowlist filtering]
  Allowlists --> Finding[report.Finding]
  Finding --> Baseline[baseline comparison]
  Baseline --> Formatter[JSON/CSV/JUnit/SARIF/template]
flowchart TD
  Dev[Developer] --> GenerateCmd[cmd/generate]
  GenerateCmd --> ConfigGen[generate config/rules]
  GenerateCmd --> SecretGen[generate secrets data]
  ConfigGen --> ConfigFiles[config assets]
  SecretGen --> TestData[test fixtures/data]
  ConfigFiles --> RuntimeConfig[config package]
  TestData --> Tests[repository tests]

Glossary

  • Gitleaks — the CLI/tool implemented by this repo for detecting secrets in source code and git history.
  • Rule — a configured secret-detection pattern with metadata and optional allowlist behavior, represented under config/.
  • Finding — a detected secret occurrence that can be filtered, baselined, and rendered by report/.
  • Fragment — a unit of source content plus metadata passed from sources/ into detection.
  • Baseline — prior findings used by detect/ to suppress already-known results.

Codebase-wide invariants

  • The project is a single Go module rooted at go.mod, with the executable entrypoint in main.go and first-level packages such as cmd/, config/, detect/, report/, and sources/.
  • User-facing command code is organized under cmd/: top-level commands are in cmd/*.go, SCM-specific command support is in cmd/scm/**, and developer generation commands are in cmd/generate/**.
  • Core scanning is separated into source production and detection: scan inputs live under sources/**, while matching, location, baseline, and reader/git/file detection code lives under detect/*.go.
  • Output formatting is centralized under report/**, with bundled template assets under report_templates/**.
  • Encoded-content handling is isolated from the main detector in detect/codec/**, rather than being spread through detect/*.go.

Routing table