Documentation
¶
Overview ¶
Package config defines the scanner configuration schema (a superset of the gitleaks v8 TOML format), loads and merges configs, and compiles rules.
Index ¶
Constants ¶
const ( TokPrefix = `(?:^|[^0-9A-Za-z_+/-])(` TokSuffix = `)(?:[^0-9A-Za-z_+/-]|$)` SemiMarker = `[\w.-]{0,50}?(?i:` )
Token-rule wrapper and semi-generic marker, recognized by the compiler.
Variables ¶
var AutoConfigNames = []string{".secretscan.toml", "secretscan.toml", ".gitleaks.toml"}
AutoConfigNames are discovered (in order) in the scan root when no config is given explicitly.
var GenericStopwords = genericStopwords
GenericStopwords are substrings of common non-secret values. The detector applies them only to word-like values (see detect.genericNoise), so a random token that happens to contain "secret" or "token" is kept.
var Validators = map[string]bool{"basic-auth": true, "opaque-token": true}
Validators are the content checks a rule can name in Validate. The detector implements each one (detect.validators).
Functions ¶
func IsTokenChar ¶
IsTokenChar reports whether c can continue a token (for boundary checks).
func SeverityRank ¶
SeverityRank returns the ordinal of a severity, or -1 if unknown.
Types ¶
type Allowlist ¶
type Allowlist struct {
Description string `json:"description"`
Condition string `json:"condition"`
Commits []string `json:"commits"`
Paths []string `json:"paths"`
RegexTarget string `json:"regexTarget"` // secret (default) | match | line | prefix (match text before the secret)
Regexes []string `json:"regexes"`
Stopwords []string `json:"stopwords"`
TargetRules []string `json:"targetRules"` // global allowlists only
// TargetTags limits a global allowlist to rules carrying one of these
// tags (e.g. ["generic"]), so value-based suppressions written for noisy
// generic rules can never hide a structured provider token.
TargetTags []string `json:"targetTags"`
}
Allowlist suppresses findings. Within one allowlist, criteria combine with Condition (OR by default, or AND).
func DefaultAllowlists ¶
func DefaultAllowlists() []Allowlist
DefaultAllowlists are global allowlists shipped with the default pack.
type CompiledAllowlist ¶
type CompiledAllowlist struct {
Description string
And bool
Commits map[string]bool
Paths []*regexp.Regexp
Target string
Regexes []*regexp.Regexp
Stopwords []string
TargetRules map[string]bool
TargetTags map[string]bool
}
CompiledAllowlist is an allowlist ready for evaluation.
func (*CompiledAllowlist) Allowed ¶
func (a *CompiledAllowlist) Allowed(path, commit, secret, match, line string) bool
Allowed evaluates the allowlist against a candidate finding.
func (*CompiledAllowlist) AppliesTo ¶
func (a *CompiledAllowlist) AppliesTo(r *CompiledRule) bool
AppliesTo reports whether a global allowlist is scoped to this rule.
func (*CompiledAllowlist) PathAllowed ¶
func (a *CompiledAllowlist) PathAllowed(path string) bool
PathAllowed reports whether a path alone (no other criteria needed) is allowlisted, letting sources skip files cheaply.
type CompiledRule ¶
type CompiledRule struct {
Rule
Re *regexp.Regexp
PathRe *regexp.Regexp
LowerKeys []string
Allowlists []*CompiledAllowlist
Generic bool // tagged "generic": yields to specific rules on overlap
Multiline bool // regex can span lines; widens keyword windows
Bounded bool // token rule: boundary chars are checked in code, not regex
Semi bool // keyword-context rule ("name = value" with a provider charset)
Before int // keyword window radius before / after an occurrence
After int
// contains filtered or unexported fields
}
CompiledRule is a rule ready for matching.
func (*CompiledRule) HasTag ¶
func (r *CompiledRule) HasTag(t string) bool
HasTag reports whether the rule carries tag t.
func (*CompiledRule) NumGroups ¶
func (r *CompiledRule) NumGroups() int
NumGroups is the number of capture groups in the rule's regex.
type Config ¶
type Config struct {
Title string `json:"title"`
Description string `json:"description"`
Extend Extend `json:"extend"`
Rules []Rule `json:"rules"`
Allowlist *Allowlist `json:"allowlist"` // legacy single global allowlist
Allowlists []Allowlist `json:"allowlists"` // global allowlists
Remediation Remediation `json:"remediation"`
// Policy decides what blocks: "strict" (every finding) or "balanced"
// (high and medium confidence; low-confidence findings are reported for review).
Policy string `json:"policy"`
// TestFixtures decides whether balanced blocks generic values in
// test/example files: "block" (default) or "review". Provider-format
// secrets in test files always block.
TestFixtures string `json:"testFixtures"`
}
Config is the on-disk configuration. Field names match gitleaks so existing .gitleaks.toml files load unchanged.
func Load ¶
Load decodes config bytes. Unknown keys are reported as warnings, not errors, so newer gitleaks configs still load.
type Extend ¶
type Extend struct {
// UseDefault keeps the built-in rule pack. Unlike gitleaks, it defaults
// to true: custom rules are additive unless you set useDefault = false.
UseDefault *bool `json:"useDefault"`
Path string `json:"path"` // another config to extend
DisabledRules []string `json:"disabledRules"` // rule IDs to drop
}
Extend controls how this config relates to others.
type Options ¶
type Options struct {
ConfigPath string
NoDefaults bool
Patterns []string // "id=regex" or bare regex
PatternsFiles []string
EnableRules []string // if set, only these rule IDs
DisableRules []string
Tags []string // if set, only rules carrying one of these tags
ExcludePaths []string // extra global path allowlist regexes
SearchDirs []string // where to auto-discover a config
DefaultSeverity string
}
Options are CLI-level adjustments applied on top of file configs.
type Remediation ¶
type Remediation struct {
Store string `json:"store"` // env | vault | aws | azure | gcp: the secret store snippets target
Runbook string `json:"runbook"` // link to your internal secret-handling / rotation runbook
}
Remediation sets organization defaults for fix guidance.
type Rule ¶
type Rule struct {
ID string `json:"id"`
Description string `json:"description"`
Regex string `json:"regex"` // RE2 syntax; optional if Path is set
SecretGroup int `json:"secretGroup"` // capture group holding the secret
Entropy float64 `json:"entropy"` // minimum Shannon entropy of the secret
Keywords []string `json:"keywords"` // fast prefilter (case-insensitive)
Path string `json:"path"` // only scan matching paths; alone = file-name rule
Tags []string `json:"tags"`
Severity string `json:"severity"` // critical|high|medium|low|info (default high)
Allowlist *Allowlist `json:"allowlist"`
Allowlists []Allowlist `json:"allowlists"`
// Validate names a built-in content check (see Validators) a candidate
// must pass to qualify, e.g. "basic-auth": the value must decode to
// user:password. A candidate that fails it never qualified; it is not a
// suppression.
Validate string `json:"validate"`
// Self-tests, checked by `secretscan config validate`.
Examples []string `json:"examples"` // must produce a finding
Negatives []string `json:"negatives"` // must not produce a finding
}
Rule is one detector.
type Ruleset ¶
type Ruleset struct {
Rules []*CompiledRule
Allowlists []*CompiledAllowlist // global
Remediation Remediation
Policy string
TestFixtures string
}
Ruleset is a compiled config.