custom

package
v1.6.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2026 License: MIT Imports: 6 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 custom provides a YAML-based custom rule detector. Users can define their own secret patterns in .leakwatch.yaml.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterCustomRules

func RegisterCustomRules(rules []RuleDef) (int, []error)

RegisterCustomRules parses RuleDefs, creates detectors, and registers them. Returns the count of successfully registered rules and any errors.

A rule whose ID collides with an already-registered detector (a built-in detector or a previously registered custom rule) is skipped with an error rather than registered, because detector.Register panics on duplicate IDs.

Types

type CustomDetector

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

CustomDetector implements detector.Detector for user-defined rules.

func NewFromDef

func NewFromDef(def RuleDef) (*CustomDetector, error)

NewFromDef creates a CustomDetector from a RuleDef. Returns an error if the regex pattern is invalid or exceeds the maximum length.

func (*CustomDetector) Description

func (d *CustomDetector) Description() string

Description returns a human-readable description of the custom detector.

func (*CustomDetector) ID

func (d *CustomDetector) ID() string

ID returns the unique identifier of the custom detector.

func (*CustomDetector) Keywords

func (d *CustomDetector) Keywords() []string

Keywords returns the Aho-Corasick pre-filter keywords for the custom detector.

func (*CustomDetector) Scan

func (d *CustomDetector) Scan(_ context.Context, data []byte) []detector.RawFinding

Scan searches the data for matches against the custom regex pattern. If an entropy threshold is defined, matches below it are skipped.

func (*CustomDetector) Severity

func (d *CustomDetector) Severity() finding.Severity

Severity returns the default severity level for the custom detector findings.

type RuleDef

type RuleDef struct {
	ID          string   `yaml:"id" mapstructure:"id"`
	Description string   `yaml:"description" mapstructure:"description"`
	Regex       string   `yaml:"regex" mapstructure:"regex"`
	Keywords    []string `yaml:"keywords" mapstructure:"keywords"`
	Severity    string   `yaml:"severity" mapstructure:"severity"`
	Entropy     float64  `yaml:"entropy" mapstructure:"entropy"`
}

RuleDef represents a user-defined custom detection rule from YAML config.

Jump to

Keyboard shortcuts

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