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 ¶
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.