Documentation
¶
Overview ¶
Package suppress is the fourth pipeline stage: it alone decides whether a candidate is suppressed (test keys, inline allows, allowlists, ignore files, baselines) and records the reason.
Index ¶
Constants ¶
const Default = "default"
Default is the name of the default suppressor.
Variables ¶
var ErrInvalidBaseline = errors.New("suppress: invalid baseline")
ErrInvalidBaseline is returned by the default factory for a baseline with a schema version above model.BaselineSchemaVersion or a malformed finding id. The error names the finding index, never its value.
var ErrInvalidRule = errors.New("suppress: invalid ignore rule")
ErrInvalidRule is returned by the default factory for a rule that fails validation. The error names the rule index, never its value.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// IncludeTestKeys keeps findings from generated test keys unsuppressed.
IncludeTestKeys bool
// Rules are the ignore rules to apply.
Rules []model.IgnoreRule
// Baseline is the accepted set of findings Compare uses; nil means none.
Baseline *model.Baseline
}
Options configures a suppressor.
type Suppressor ¶
type Suppressor interface {
// Suppress decides on c as it stands: its Locations and c.Ctx (Allows and
// FirstID). It only ever sets Suppressed and SuppressionReason.
Suppress(c *candidate.Candidate)
// Hold reports whether c must wait for every location before its decision: its
// first location is covered by a location-level fact and no id or detector rule
// decides it already. Locations seen later may be uncovered, so a held
// candidate is decided again on the merged locations.
Hold(c candidate.Candidate) bool
// Compare sets NewVsBaseline on an unsuppressed finding when a baseline is
// loaded: false when f's id (its final id) is in the baseline, true otherwise.
// Suppressed findings and runs without a baseline keep it nil. It changes no
// other field and never changes a suppression decision.
Compare(f *model.Finding)
}
Suppressor is the suppress stage interface. Only suppress sets the Finding's Suppressed and SuppressionReason fields, and it never reads key material: it decides from the Finding's id, detector and locations and from the predicates detect precomputed (SuppressCtx).
Finding-level facts (an id or detector rule, the test marker) suppress the whole finding. Location-level facts (path and loc rules, inline allow markers) suppress it only when every location is covered by at least one of them. The reason is the first one in model.SuppressionReasons order among everything that matched.
func New ¶ added in v0.2.0
func New(o Options) (Suppressor, error)
New compiles the rules once and returns the default suppressor.