gitleaksrules

package
v0.167.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: MIT Imports: 19 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 gitleaksrules scans unified diffs with the gitleaks default ruleset embedded in the gk binary, so secret scanning works without the gitleaks binary installed.

rules.json is generated by tools/genrules from a pinned gitleaks release (see `make gen-rules`). The engine mirrors the gitleaks detection steps that the default config relies on: keyword prefilter, regex, secret group, entropy, path rules, and global and per-rule allowlists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GKRuleCount added in v0.158.0

func GKRuleCount() int

GKRuleCount returns the number of rules that gk adds to the gitleaks ruleset.

func MaskLines added in v0.167.0

func MaskLines(path string, lines []string) []string

MaskLines returns a copy of lines with every secret the ruleset finds masked in place, for callers that print source lines outside a scan report, such as `gk find`. path is the file the lines came from, or "" when they came from no file. The lines are scanned as one block, so a match that spans lines is found.

It is stricter than a scan in three ways. The rules run with no path, so the path allowlists, which a scan uses to skip test fixtures and lock files, do not apply: a line that is printed must not depend on where it came from. Only the rules that are limited to a path, such as the Terraform password rule, run with path. A secret found only in decoded text, such as a base64 value, cannot be located in the line, so the whole line is replaced. So is a line that is one opaque run of base64, such as a line of a PEM block: apart from the block around it, it matches no rule.

An encoded value folded over several lines, as in a YAML block, is not joined back: the decoder reads one line at a time, so only a piece that holds a whole secret or is an opaque run is masked. `gk find`, the one caller, prints one line of a diff at a time and passes each alone, so it never has the other pieces of such a value to join.

func RuleCount

func RuleCount() int

RuleCount returns the number of embedded gitleaks rules.

func ScanDiff

func ScanDiff(diff string) []secrets.Finding

ScanDiff scans the added lines of a unified diff (`git diff` or `git log -p` output) and returns one finding per matched secret.

func ScanFile added in v0.154.0

func ScanFile(path, content string) []secrets.Finding

ScanFile scans the whole content of one file, the unit gitleaks scans in dir mode. FileLine counts from the first line of content.

func Version

func Version() string

Version returns the gitleaks release the embedded ruleset came from.

Types

This section is empty.

Directories

Path Synopsis
Package codec decodes base64, hex, percent, and unicode escapes in place so the rules can run on the decoded text, and maps decoded matches back to their location in the original text.
Package codec decodes base64, hex, percent, and unicode escapes in place so the rules can run on the decoded text, and maps decoded matches back to their location in the original text.

Jump to

Keyboard shortcuts

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