Documentation
¶
Index ¶
- Constants
- Variables
- type Allowlist
- type AllowlistMatchCondition
- type Config
- func (c *Config) CompileFilters(tokenizer *tiktoken.Tiktoken) error
- func (c *Config) CompileValidation() (*exprruntime.Runtime, error)
- func (c *Config) FilterProgram() exprruntime.Program
- func (c *Config) GetOrderedRules() []Rule
- func (c *Config) PrefilterProgram() exprruntime.Program
- func (c *Config) SetFilterProgram(p exprruntime.Program)
- func (c *Config) SetPrefilterProgram(p exprruntime.Program)
- func (c *Config) TranslateLegacyFilters() error
- type Extend
- type Required
- type Rule
Constants ¶
const DefaultRuleSpecificity = 100
Variables ¶
var ( //go:embed betterleaks.toml DefaultConfig string )
Functions ¶
This section is empty.
Types ¶
type Allowlist ¶
type Allowlist struct {
// Short human readable description of the allowlist.
Description string
// MatchCondition determines whether all criteria must match. Defaults to "OR".
MatchCondition AllowlistMatchCondition
// Commits is a slice of commit SHAs that are allowed to be ignored.
Commits []string
// Paths is a slice of path regular expressions that are allowed to be ignored.
Paths []*regexp.Regexp
// Can be `match` or `line`.
//
// If `match` the _Regexes_ will be tested against the match of the _Rule.Regex_.
//
// If `line` the _Regexes_ will be tested against the entire line.
//
// If RegexTarget is empty, it will be tested against the found secret.
RegexTarget string
// Regexes is slice of content regular expressions that are allowed to be ignored.
Regexes []*regexp.Regexp
// StopWords is a slice of stop words that are allowed to be ignored.
// This targets the _secret_, not the content of the regex match like the
// Regexes slice.
StopWords []string
// contains filtered or unexported fields
}
Allowlist allows a rule to be ignored for specific regexes, paths, and/or commits
func (*Allowlist) CommitAllowed ¶
CommitAllowed returns true if the commit is allowed to be ignored.
func (*Allowlist) PathAllowed ¶
PathAllowed returns true if the path is allowed to be ignored.
func (*Allowlist) RegexAllowed ¶
RegexAllowed returns true if the regex is allowed to be ignored.
type AllowlistMatchCondition ¶
type AllowlistMatchCondition int
const ( AllowlistMatchOr AllowlistMatchCondition = iota AllowlistMatchAnd )
func (AllowlistMatchCondition) String ¶
func (a AllowlistMatchCondition) String() string
type Config ¶
type Config struct {
Title string
Extend Extend
Path string
Description string
Rules map[string]Rule
Keywords map[string]struct{}
// KeywordToRules maps each lowercase keyword to the rule IDs that use it.
// This allows O(1) lookup from Aho-Corasick keyword matches to the rules
// that need to be checked, instead of iterating all rules.
KeywordToRules map[string][]string
// NoKeywordRules contains rule IDs that have no keywords and must always be checked.
NoKeywordRules []string
// used to keep sarif results consistent
OrderedRules []string
// Deprecated: use filter/prefilter Expr expressions instead. This is a shim for backwards-compatibility.
Allowlists []*Allowlist
MinVersion string
BetterleaksMinVersion string
// Prefilter is a global expression (attributes only) evaluated before any
// per-match work. Returns true = skip this fragment entirely; false = keep.
// Translated from global Allowlists path/commit checks.
Prefilter string
// Filter is a global expression (attributes + finding) evaluated per match.
// Returns true = skip (discard) this finding; false = keep.
// Translated from global Allowlists regex/stopword checks.
Filter string
// contains filtered or unexported fields
}
Config is a configuration struct that contains rules and an allowlist if present.
func ParseTOMLString ¶ added in v1.5.0
func (*Config) CompileFilters ¶ added in v1.6.0
CompileFilters compiles only the global prefilter needed before scanning. Global finding filters and per-rule filters compile lazily on first candidate.
func (*Config) CompileValidation ¶ added in v1.2.0
func (c *Config) CompileValidation() (*exprruntime.Runtime, error)
CompileValidation returns a runtime for per-rule validation expressions. Individual validation programs are compiled lazily by the detector. Returns (nil, nil) when no rules have validation expressions.
func (*Config) FilterProgram ¶ added in v1.2.0
func (c *Config) FilterProgram() exprruntime.Program
FilterProgram returns the compiled global filter program, or nil if not set.
func (*Config) GetOrderedRules ¶
func (*Config) PrefilterProgram ¶ added in v1.2.0
func (c *Config) PrefilterProgram() exprruntime.Program
PrefilterProgram returns the compiled global prefilter program, or nil if not set.
func (*Config) SetFilterProgram ¶ added in v1.2.0
func (c *Config) SetFilterProgram(p exprruntime.Program)
SetFilterProgram stores a compiled global filter program.
func (*Config) SetPrefilterProgram ¶ added in v1.2.0
func (c *Config) SetPrefilterProgram(p exprruntime.Program)
SetPrefilterProgram stores a compiled global prefilter program.
func (*Config) TranslateLegacyFilters ¶ added in v1.2.0
TranslateLegacyFilters converts deprecated Allowlists, Entropy, and TokenEfficiency fields into prefilter/filter expressions on the Config and its Rules. This is exported for use by the config generator, but is also called internally at the end of config translation (after all extends and targeted allowlists are populated). Translated expressions are logged at the debug level to help users migrate. Notes:
- Expressions return true (skip) or false (keep).
- Prefilters exist only at the global level (source/resource attributes-only, runs before regex).
- Rules only have filters (attributes + finding, runs per match).
type Extend ¶
type Extend struct {
Path string `toml:"path"`
URL string `toml:"url"`
UseDefault bool `toml:"useDefault"`
DisabledRules []string `toml:"disabledRules"`
}
Extend is a struct that allows users to define how they want their configuration extended by other configuration files.
type Rule ¶
type Rule struct {
// RuleID is a unique identifier for this rule
RuleID string
// Description is the description of the rule.
Description string
// Entropy is a float representing the minimum shannon
// entropy a regex group must have to be considered a secret.
Entropy float64
// SecretGroup is an int used to extract secret from regex
// match and used as the group that will have its entropy
// checked if `entropy` is set.
SecretGroup int
// Regex is a golang regular expression used to detect secrets.
Regex *regexp.Regexp
// Path is a golang regular expression used to
// filter secrets by path
Path *regexp.Regexp
// Tags is an array of strings used for metadata
// and reporting purposes.
Tags []string
// Specificity controls precedence when overlapping findings compete.
// Higher specificity findings suppress lower specificity findings.
Specificity int
// Keywords are used for pre-regex check filtering. Rules that contain
// keywords will perform a quick string compare check to make sure the
// keyword(s) are in the content being scanned.
Keywords []string
// Allowlists allows a rule to be ignored for specific commits, paths, regexes, and/or stopwords.
Allowlists []*Allowlist
// If a rule has RequiredRules, it makes the rule dependent on the RequiredRules.
// In otherwords, this rule is now a composite rule.
RequiredRules []*Required
SkipReport bool
// TokenEfficiency enables the Token Efficiency filter for this rule.
// When enabled, candidate secrets are evaluated using BPE tokenization
// to measure how "rare" or non-natural-language a string is. Strings that
// tokenize efficiently (i.e., common words/phrases) are filtered out.
TokenEfficiency bool
// ValidateExpr is the raw expression used for secret validation.
ValidateExpr string
// Filter is an expression evaluated against attributes + finding per regex match.
// Returns true = skip (discard this finding); false = keep.
// Deprecated legacy Allowlists, Entropy, and TokenEfficiency are translated into this field.
Filter string
// contains filtered or unexported fields
}
Rules contain information that define details on how to detect secrets
func (*Rule) FilterProgram ¶ added in v1.2.0
func (r *Rule) FilterProgram() exprruntime.Program
FilterProgram returns the compiled filter program for this rule, or nil.
func (*Rule) SetFilterProgram ¶ added in v1.2.0
func (r *Rule) SetFilterProgram(p exprruntime.Program)
SetFilterProgram stores a compiled filter program on the rule.
func (*Rule) SetValidationProgram ¶ added in v1.6.0
func (r *Rule) SetValidationProgram(p exprruntime.Program)
SetValidationProgram stores a compiled validation program on the rule.
func (*Rule) ValidationProgram ¶ added in v1.6.0
func (r *Rule) ValidationProgram() exprruntime.Program
ValidationProgram returns the compiled validation program for this rule, or nil.