Documentation
¶
Overview ¶
Package seed produces leads: deterministic, model-free observations that start an investigation. A lead is not a verdict. Seeders are either built-in rule sets or adapters around an installed scanner.
Index ¶
- Constants
- Variables
- func IsExternal(name string) bool
- func RememberSecrets(ctx context.Context, files []walk.File)
- func RunAll(ctx context.Context, seeders []Seeder, root string, files []walk.File, ...) ([]Lead, []Status)
- func RunAllIn(ctx context.Context, seeders []Seeder, root string, files []walk.File, ...) (leads []Lead, statuses []Status, leftOut int)
- func RunAllScoped(ctx context.Context, seeders []Seeder, root string, files []walk.File, ...) (leads []Lead, statuses []Status, leftOut, outside int)
- func UnknownBuiltinRules(ids []string) []string
- type Lead
- type NetworkUser
- type Noter
- type Rule
- type RuleInfo
- type Seeder
- type Status
- type Versioner
Constants ¶
const ( // MaxLeadsPerRuleFile is how many leads one rule may report in one file. MaxLeadsPerRuleFile = 50 // MaxLeadsPerSeeder is how many leads one seeder may report in one run. MaxLeadsPerSeeder = 5000 )
Lead caps. A generated or vendored file can match one rule thousands of times. Past a point more leads of the same rule in the same file add nothing a reader can use, and each one costs a ledger line and a finding.
Variables ¶
var TestedVersions = map[string]string{
"gitleaks": "8.30.1",
"hadolint": "2.15.1",
"osv-scanner": "2.7.1",
"semgrep": "1.187.0",
"trivy": "0.76.2",
}
TestedVersions are the scanner versions the adapters are tested against: the pins of .github/workflows/scanners.yml, which a test keeps equal to this table. Another version may rename a flag or a field, and the adapter would then read nothing from it.
Functions ¶
func IsExternal ¶ added in v0.2.0
IsExternal reports whether name is one of the external scanners.
func RememberSecrets ¶ added in v0.2.1
RememberSecrets runs the infrastructure checks over files only so the credentials they find are registered for redaction (see redact.Remember), and drops the leads. Modes that read files without seeding them all (debug mode, a diff scan) call it first, so a credential in a file that is not seeded is still hidden when the model reads that file.
func RunAll ¶
func RunAll(ctx context.Context, seeders []Seeder, root string, files []walk.File, texts *walk.Texts) ([]Lead, []Status)
RunAll runs every available seeder and returns the merged, sorted leads. One failing seeder does not stop the others: its error is recorded in its Status and the run continues. texts may hold file texts that an earlier stage already read; nil means every file is read here.
func RunAllIn ¶ added in v0.2.0
func RunAllIn(ctx context.Context, seeders []Seeder, root string, files []walk.File, texts *walk.Texts, only map[string]bool) (leads []Lead, statuses []Status, leftOut int)
RunAllIn is RunAll for a diff scan: only, when not nil, holds the files (relative paths) whose leads are wanted. The built-in seeders read only those files, and the leads of the other seeders in any other file are dropped before a seeder's lead cap applies, so leads elsewhere cannot crowd out a lead in a wanted file. A lead with no file is dropped too. leftOut is how many leads were dropped that way.
func RunAllScoped ¶ added in v0.2.0
func RunAllScoped(ctx context.Context, seeders []Seeder, root string, files []walk.File, texts *walk.Texts, only map[string]bool, keep func(Lead) bool) (leads []Lead, statuses []Status, leftOut, outside int)
RunAllScoped is RunAllIn with a second, finer filter for the leads in the wanted files: when keep is not nil, a lead it returns false for is dropped too, before the lead cap, and counted in outside. A diff scan limited to the changed lines uses it.
func UnknownBuiltinRules ¶ added in v0.2.0
UnknownBuiltinRules returns the entries of a disable_rules list that look like built-in rule ids (a built-in prefix such as py- or docker-, or a builtin-* source) but name no built-in rule, which is most likely a typo. Other ids may belong to an external scanner and are not checked.
Types ¶
type Lead ¶
type Lead struct {
ID string `json:"id"` // stable; see (*Lead).Finalize
Source string `json:"source"` // seeder name: builtin-code, builtin-secrets, semgrep, ...
RuleID string `json:"rule_id"` // rule within the seeder
Title string `json:"title"` // short, specific, no trailing period
Class string `json:"class"` // a class known to finding.DefaultVector
Surface string `json:"surface"` // finding.SurfaceCode, SurfaceInfra or SurfaceDAST
CWE []string `json:"cwe,omitempty"` // "CWE-89"
OWASP []string `json:"owasp,omitempty"` // "A03:2021 Injection"
// Severity is the seeder's hint: critical, high, medium or low.
Severity string `json:"severity"`
File string `json:"file,omitempty"` // forward-slash, relative to the target root
Line int `json:"line,omitempty"` // 1-based
EndLine int `json:"end_line,omitempty"`
Method string `json:"method,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
Param string `json:"param,omitempty"`
// Snippet is the matched source or traffic, already redacted. It must
// never contain a secret value.
Snippet string `json:"snippet,omitempty"`
Detail string `json:"detail"` // what is wrong, in one or two sentences
Fix string `json:"fix"` // the concrete remediation, in one or two sentences
// Evidence names stored artifacts (for DAST, the exchange ids).
Evidence []string `json:"evidence,omitempty"`
}
Lead is one observation from a seeder.
type NetworkUser ¶ added in v0.2.0
type NetworkUser interface {
UsesNetwork() bool
}
NetworkUser is implemented by a seeder that may use the network when it runs. Offline mode promises that nothing leaves the machine, so it does not run a seeder that reports true.
type Noter ¶
type Noter interface {
Note() string
}
Noter is implemented by seeders that have something to say about their last Run beyond the leads, such as how many scanner results were dropped because they could not be classified. Callers may type-assert a Seeder to Noter after Run.
type Rule ¶
type Rule struct {
ID string
Langs []string // walk.File.Lang values the rule applies to
// Pattern must match the line.
Pattern *regexp.Regexp
// Exclude, when set, suppresses the rule if it matches the same line.
// It expresses the safe variant of the pattern (a literal argument, a
// safe loader) which RE2 cannot express as a negative lookahead.
Exclude *regexp.Regexp
// Require, when set, must also match the same line.
Require *regexp.Regexp
// Near, when set, must match some line within NearLines of the hit.
// It is for settings that are only dangerous together.
Near *regexp.Regexp
NearLines int
Title string
Class string
CWE string
OWASP string
Severity string
Detail string
Fix string
}
Rule is one line-oriented source pattern. The engine is deliberately simple: a lead is a starting point for an investigation, so a rule only has to be precise enough that most of its hits deserve a look.
type RuleInfo ¶ added in v0.2.0
type RuleInfo struct {
Source string `json:"source"` // the seeder that reports it
ID string `json:"id"`
Title string `json:"title"`
Class string `json:"class"`
Severity string `json:"severity"`
CWE string `json:"cwe"`
Langs []string `json:"languages"`
}
RuleInfo describes one built-in rule for a listing: what `spackle rules` prints and what `[scan] disable_rules` can name.
func BuiltinRules ¶ added in v0.2.0
func BuiltinRules() []RuleInfo
BuiltinRules lists every rule of the built-in seeders, by source and id.
type Seeder ¶
type Seeder interface {
// Name is the stable seeder name used in Lead.Source and in doctor output.
Name() string
// Available reports whether the seeder can run here, with a note that
// says how to get it when it cannot (for example an install hint).
Available() (ok bool, note string)
// Run examines the target. files is the safe file listing of root;
// seeders must read target files only through it or through
// walk.Resolve, never by walking the tree themselves.
Run(ctx context.Context, root string, files []walk.File) ([]Lead, error)
}
Seeder produces leads for a target on disk.
type Status ¶
type Status struct {
Name string `json:"name"`
Available bool `json:"available"`
Note string `json:"note,omitempty"`
Leads int `json:"leads"`
Error string `json:"error,omitempty"`
// Version is the installed version of an external scanner, when it
// could be told.
Version string `json:"version,omitempty"`
}
Status records how one seeder fared in a run.