evals

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 19, 2026 License: Apache-2.0 Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package evals runs the security benchmark corpus and scores the scanner against it. It is the regression net: a detector that stops firing on a known vulnerability, or starts firing on a case that was fixed, fails here before it reaches anyone.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Case

type Case struct {
	ID       string `yaml:"id"`
	Category string `yaml:"category"`
	Class    Class  `yaml:"-"`
	Dir      string `yaml:"-"`

	// Notes explains what the case is testing. Required, because a corpus of
	// unlabelled fixtures rots into noise.
	Notes string `yaml:"notes"`

	Target CaseTarget `yaml:"target"`

	Expected Expectation `yaml:"expected"`

	// Analyzers restricts the scan. Empty means every applicable analyzer,
	// which is how cross-analyzer regressions get caught.
	Analyzers []string `yaml:"analyzers"`

	// Regression marks a case added because of a bug found in the field. These
	// are never removed and never allowed to fail.
	Regression bool `yaml:"regression"`
}

Case is one corpus entry, loaded from case.yaml next to the fixture

func Load

func Load(root string) ([]Case, error)

Load reads every case under root. A directory containing a case.yaml is a case; anything else is fixture material belonging to one.

func (Case) ScanTarget

func (c Case) ScanTarget() model.Target

ScanTarget builds the scan target for the case, resolved against its directory

type CaseTarget

type CaseTarget struct {
	Kind model.TargetKind `yaml:"kind"`
	Path string           `yaml:"path"`
	URL  string           `yaml:"url"`
}

CaseTarget describes what to scan, relative to the case directory

type Class

type Class string

Class is which part of the corpus a case belongs to

const (
	// ClassVulnerable must produce a finding
	ClassVulnerable Class = "vulnerable"
	// ClassFixed is the repaired version of a vulnerable case and must be quiet
	ClassFixed Class = "fixed"
	// ClassBenign is ordinary code that must be quiet
	ClassBenign Class = "benign"
	// ClassHoldout is benign or vulnerable code kept out of rule tuning
	ClassHoldout Class = "holdout"
)

type Expectation

type Expectation struct {
	Vulnerable      bool           `yaml:"vulnerable"`
	MinimumSeverity model.Severity `yaml:"minimum_severity"`
	// Rules that must appear. A case can require a specific detector rather
	// than accepting any finding at all, which stops an unrelated rule from
	// masking a regression.
	Rules []string `yaml:"rules"`
	// ForbiddenRules must not appear. Used for fixed and benign cases that
	// previously produced a specific false positive.
	ForbiddenRules []string `yaml:"forbidden_rules"`
	// Status the scan must reach. Defaults to COMPLETED
	Status model.ScanStatus `yaml:"status"`
}

Expectation is what the scan should produce

type Metrics

type Metrics struct {
	TP, TN, FP, FN int
	Gaps           int
}

Metrics is the confusion matrix and its derived rates.

Gaps sits outside the matrix on purpose: those cases hold a vulnerability the build cannot see and assert that the scan reports a gap instead of a clean result. Folding them into TN would let precision and recall rise by documenting more blind spots.

func (*Metrics) Add

func (m *Metrics) Add(classification string)

func (Metrics) F1

func (m Metrics) F1() float64

func (Metrics) Precision

func (m Metrics) Precision() float64

func (Metrics) Recall

func (m Metrics) Recall() float64

func (Metrics) String

func (m Metrics) String() string

type Outcome

type Outcome struct {
	Case   Case
	Result *model.ScanResult

	// Detected is whether the scan produced a qualifying finding
	Detected bool
	// Classification is TP, TN, FP, FN, or GAP for a case that pins a
	// blind spot rather than a detection
	Classification string
	// Problems lists why the case failed, empty when it passed
	Problems []string
}

Outcome is how one case turned out

func Run

func Run(ctx context.Context, s *scanner.Scanner, c Case, opts scanner.Options) Outcome

Run scans one case and judges it against its expectation

type Report

type Report struct {
	Overall    Metrics
	ByCategory map[string]*Metrics
}

Report aggregates outcomes overall and per category

func NewReport

func NewReport() *Report

func (*Report) Add

func (r *Report) Add(o Outcome)

func (*Report) String

func (r *Report) String() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL