detect

package
v5.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 24 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// SlowWarningThreshold is the amount of time to wait before logging that a file is slow.
	// This is useful for identifying problematic files and tuning the allowlist.
	SlowWarningThreshold = 5 * time.Second
)

Variables

This section is empty.

Functions

func IsNew

func IsNew(finding *report.Finding, redact uint, baseline []report.Finding) bool

func LoadBaseline

func LoadBaseline(baselinePath string) ([]report.Finding, error)

Types

type Detector

type Detector struct {
	// Config is the configuration for the detector
	Config config.Config

	// Redact is a flag to redact findings. This is exported
	// so users using gitleaks as a library can set this flag
	// without calling `detector.Start(cmd *cobra.Command)`
	Redact uint

	// verbose is a flag to print findings
	Verbose bool

	// MaxDecodeDepths limits how many recursive decoding passes are allowed
	MaxDecodeDepth int

	// MaxArchiveDepth limits how deep the sources will explore nested archives
	MaxArchiveDepth int

	// files larger than this will be skipped
	MaxTargetMegaBytes int

	// caps the number of regex matches per rule per fragment
	MaxRuleMatchesPerFragment uint64

	// MaxSecretSize is the maximum allowed secret size in bytes.
	// Secrets larger than this will be ignored. 0 means no limit.
	MaxSecretSize uint64

	// followSymlinks is a flag to enable scanning symlink files
	FollowSymlinks bool

	// NoColor is a flag to disable color output
	NoColor bool

	// IgnoreGitleaksAllow is a flag to ignore gitleaks:allow comments.
	IgnoreGitleaksAllow bool

	// Sema (https://github.com/fatih/semgroup) controls the concurrency
	Sema *semgroup.Group

	// report-related settings.
	ReportPath string
	Reporter   report.Reporter

	TotalBytes atomic.Uint64
	// contains filtered or unexported fields
}

Detector is the main detector struct

func NewDetector

func NewDetector(cfg *config.Config) *Detector

NewDetector creates a new detector with the given config

func (*Detector) AddBaseline

func (d *Detector) AddBaseline(baselinePath, source string) error

func (*Detector) AddFinding

func (d *Detector) AddFinding(finding *report.Finding)

AddFinding synchronously adds a finding to the findings slice

func (*Detector) AddGitleaksIgnore

func (d *Detector) AddGitleaksIgnore(gitleaksIgnorePath string) error

func (*Detector) Detect

func (d *Detector) Detect(fragment *Fragment) []report.Finding

Detect scans the given fragment and returns a list of findings

func (*Detector) DetectBytes

func (d *Detector) DetectBytes(content []byte) []report.Finding

DetectBytes scans the given bytes and returns a list of findings

func (*Detector) DetectSource

func (d *Detector) DetectSource(ctx context.Context, source sources.Source) ([]report.Finding, error)

DetectSource scans the given source and returns a list of findings

func (*Detector) DetectString

func (d *Detector) DetectString(content string) []report.Finding

DetectString scans the given string and returns a list of findings

func (*Detector) Findings

func (d *Detector) Findings() []report.Finding

Findings returns the findings added to the detector

type Fragment deprecated

type Fragment sources.Fragment

Fragment is an alias for sources.Fragment for backwards compatibility

Deprecated: This will be replaced with sources.Fragment in v9

type Location

type Location struct {
	// contains filtered or unexported fields
}

Location represents a location in a file

Jump to

Keyboard shortcuts

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