gitleaks

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 16, 2026 License: MIT Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gitleaks is an OPT-IN external-scanner adapter for the transcript redaction path (iss-96). It is off by default and adds nothing — no dependency invoked, no process spawned, no cost — until a repo asks for it by dropping an enabled .abcd/config/gitleaks.json. This realises abcd's host-delegated boundary (AGENTS.md: "native/CLI/API/MCP oracles are opt-in adapters"): the always-on native scanner (internal/adapter/scanner) stays the default, and a repo that wants deeper coverage over the unstructured prose of a captured transcript arms this adapter, which shells out to a gitleaks binary and folds its findings into the same redaction the native scanner already runs.

Reach and cost. The native pattern set is prefix-anchored and misses unanchored, labelled, high-entropy values in prose (iss-96's residue). gitleaks' generic-api-key rule reaches keyword+delimiter+entropy values that the native set does not. Its findings AUGMENT native redaction — they are masked by the same scanner.Redact discipline and counted in the record's audit counters — they never replace it.

Fail-closed, never a silent no-op. When a repo has opted in but the gitleaks binary is not found (not on PATH and no valid configured path), Scan returns ErrConfiguredNotFound rather than quietly skipping the deeper scan: a repo that armed the adapter must not believe it is covered when it is not. The history store surfaces that error and refuses the write, exactly as it fails closed on a degraded native scanner.

Binary admission (GHSA-fg9r-3f8g-89m6). The config that names the binary is COMMITTED content, so it is trusted for nothing: a candidate binary — a configured path or a PATH lookup result alike — runs only when it is an absolute path to a regular executable named gitleaks that lies outside the repository both lexically and after symlink resolution (admitBinary). A refusal is ErrConfiguredPathRefused, as loud as the not-found case and never a fallback to PATH, and it names the remedy: a repository rooted at $HOME (a dotfiles checkout) contains ~/.local/bin and ~/go/bin, so an install there is "inside the repository" and must move outside it, or the path must be unset.

Testability. The binary lookup and the process execution are both injected (Adapter.LookPath, Adapter.Runner), so the gate, the loud-stage and the augmentation path are all exercised with a fake — no real gitleaks binary is required to test this package.

Index

Constants

This section is empty.

Variables

View Source
var ErrConfiguredNotFound = errors.New("gitleaks configured but not found")

ErrConfiguredNotFound is returned when the repo opted in but no gitleaks binary could be located. It is deliberately loud: the message names the opt-in so an operator sees "gitleaks configured but not found" rather than a silent skip.

View Source
var ErrConfiguredPathRefused = errors.New("gitleaks configured path refused")

ErrConfiguredPathRefused is returned when a binary WAS located but fails the admission rule (admitBinary): it is relative, lies inside the repository, is reached through a symlink that does, is not a regular file, or is not executable. It is distinct from ErrConfiguredNotFound because the operator's remedy differs — the file exists; it is where it is that is the problem — and it is equally loud: the history store fails closed on it, and the adapter never falls back to PATH after refusing a configured path.

View Source
var ErrFindingNotLocated = errors.New("gitleaks finding not located in the text")

ErrFindingNotLocated is returned when gitleaks reported a finding whose Secret and Match both occur nowhere in the scanned text, so there is no span to redact. It is loud for the reason ErrConfiguredNotFound is: a repo that armed the adapter must not store a transcript the external scanner flagged while the record counts zero findings (GHSA-j7v5-q7x6-v3rp). The history store fails closed on it; the remedy is the rule that reported the value, or enabled:false.

Functions

func Scan

func Scan(repoRoot, text, logical string) ([]scanner.Finding, error)

Scan is the transcript-path entry point the history store calls. It loads the per-repo config and delegates to the default adapter. When the repo has NOT opted in it returns (nil, nil) having invoked nothing.

Types

type Adapter

type Adapter struct {
	// LookPath resolves a bare binary name to a full path (defaults to
	// exec.LookPath). It returns an error when the binary is absent.
	LookPath func(string) (string, error)
	// Runner executes the located binary over the text.
	Runner Runner
}

Adapter augments native redaction with gitleaks findings. Construct it with NewDefault for the production wiring (real PATH lookup, real exec runner), or build one directly with a fake LookPath/Runner in tests.

func NewDefault

func NewDefault() *Adapter

NewDefault returns the production adapter: exec.LookPath for discovery and a real gitleaks shell-out for execution.

func (*Adapter) Augment

func (a *Adapter) Augment(ctx context.Context, repoRoot string, cfg Config, text, logical string) ([]scanner.Finding, error)

Augment scans text with gitleaks when cfg opts in, returning findings to fold into the native redaction. Behaviour by state:

  • not opted in (cfg.Enabled false): returns (nil, nil), invokes NOTHING — no lookup, no process. This is the gate that keeps the default path free.
  • opted in, binary absent: returns ErrConfiguredNotFound (loud-stage).
  • opted in, binary present but inadmissible (admitBinary): returns ErrConfiguredPathRefused (loud-stage), with no fallback to PATH.
  • opted in, binary present and admitted: runs it and converts its findings; a report it cannot place in the text is ErrFindingNotLocated (loud-stage), never a dropped finding.

type Config

type Config struct {
	SchemaVersion int    `json:"schema_version"`
	Enabled       bool   `json:"enabled"`
	Path          string `json:"path,omitempty"` // optional explicit binary path
}

Config is the on-disk opt-in shape (.abcd/config/gitleaks.json). Absent file means not opted in (the default).

func LoadConfig

func LoadConfig(repoRoot string) (Config, error)

LoadConfig reads the per-repo opt-in config with the same trust-boundary discipline the native scanner applies to pii.json: an os.Root-contained, size-capped, symlink-refusing read. An ABSENT config is the default-off case and returns a disabled Config with no error — the whole point of opt-in is that a repo which did nothing pays nothing. A PRESENT but unreadable or invalid config fails closed with an error, so a repo that tried to arm the adapter and got it wrong is told, not silently left unprotected.

type Runner

type Runner interface {
	Run(ctx context.Context, binPath, text string) ([]byte, error)
}

Runner executes gitleaks over text and returns its raw JSON report bytes. It is the single seam that touches a process, injected so tests need no binary.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL