Documentation
¶
Overview ¶
Package benchmark defines the interfaces and result types for Fendix's internal accuracy + performance benchmark suite (v0.20 — Establish Baselines).
This is INTERNAL tooling. It never changes scan behavior, CLI flags, or output format. A BenchmarkTarget (OWASP Benchmark, DVWA, Juice Shop) scores a Fendix ScanResult against a known-vulnerable corpus, producing precision / recall / FP / FN plus scan duration and peak memory. Those numbers become the committed baseline (see baseline.go) that every future release is compared against — the v0.20 exit criterion.
Index ¶
Constants ¶
const DefaultBaselinePath = "benchmarks/baselines/baseline.json"
DefaultBaselinePath is where the committed baseline lives, relative to the engine repo root. `fendix benchmark` commands resolve it from the current working directory; pass an explicit path to override.
Variables ¶
var DurationRegressionThreshold = 1.00
DurationRegressionThreshold is the separate, much wider band for wall-clock metrics. Accuracy is deterministic — the same binary on the same corpus yields the same precision every time, so 10% there is a real signal. Scan duration is not: the DAST targets time a Docker container answering HTTP on a shared CI runner, and that measurement carries the runner's load, not just the scanner's cost.
Measured on ONE unchanged commit (v1.2.0): 25.6s locally, 33.0s on the rc1 runner, 35.5s on the v1.2.0 runner — a 39% spread, with the slowest run logging an HTTP `context deadline exceeded` mid-scan. Under the shared 10% band that failed two consecutive release tags for a cost the code never incurred.
Duration still gates, because Rule 6 treats performance regressions as bugs (the v1.1 work took a scan from ~50 min to 9 s, and losing that silently would be a real failure). 100% is chosen to sit far above observed runner jitter (~25%) while still catching anything that genuinely doubles the scan's cost.
var RegressionThreshold = 0.10
RegressionThreshold is the fraction a metric may move in its "worse" direction (relative to the baseline value) before it counts as a regression. The roadmap fixes this at 10% — "any metric worse by > 10% = REGRESSION". It is a package var (not a const) so a future release can tighten the gate without touching the comparator.
Functions ¶
func MatchFinding ¶
MatchFinding reports whether f corresponds to label l: same rule identity (see ruleMatches), same normalized file, and line within ±3 of the anchor. The file+line anchor applies in ALL rule-matching paths.
func NormalizePath ¶
NormalizePath makes a repo-relative path stable for matching: forward slashes, no leading "./".
Types ¶
type Baseline ¶
type Baseline struct {
// Version is the fendix version that produced this baseline.
Version string `json:"version"`
// CreatedAt is when the baseline was captured.
CreatedAt time.Time `json:"created_at"`
// Results maps target name -> stored result.
Results map[string]BenchmarkResult `json:"results"`
}
Baseline is the committed snapshot of benchmark numbers that every future run is compared against. Results is keyed by target name so adding a new target never disturbs existing baselines.
func Load ¶
Load reads a baseline from path. A missing file is reported as fs.ErrNotExist (wrapped) so callers can treat "no baseline yet" as the first-run case rather than a hard failure.
func (*Baseline) Compare ¶
func (b *Baseline) Compare(current []BenchmarkResult) *RegressionReport
Compare scores current results against the baseline and returns a per-metric regression report. Targets present in current but not in the baseline are reported under NewTargets and never flagged.
type BenchmarkResult ¶
type BenchmarkResult struct {
Target string `json:"target"`
TruePos int `json:"true_pos"`
FalsePos int `json:"false_pos"`
TrueNeg int `json:"true_neg"`
FalseNeg int `json:"false_neg"`
ScanDuration time.Duration `json:"scan_duration"`
MemoryPeakMB float64 `json:"memory_peak_mb"`
Timestamp time.Time `json:"timestamp"`
}
BenchmarkResult is the scored outcome of one target run. The four confusion-matrix counts are stored; the rate metrics (Precision, Recall, FPRate, FNRate, F1) are computed methods rather than stored fields so a result is always internally consistent and the persisted JSON stays compact and unambiguous.
func (*BenchmarkResult) F1 ¶
func (r *BenchmarkResult) F1() float64
F1 is the harmonic mean of Precision and Recall — the single accuracy number the existing heavy-eval gate is expressed in, kept here so the new baseline and the old Track-4 thresholds speak the same language. Returns 0 when precision and recall are both 0.
func (*BenchmarkResult) FNRate ¶
func (r *BenchmarkResult) FNRate() float64
FNRate is FN / (FN + TP): of every real vulnerability, the fraction Fendix missed. Returns 0 when the corpus has no positives.
func (*BenchmarkResult) FPRate ¶
func (r *BenchmarkResult) FPRate() float64
FPRate is FP / (FP + TN): of every safe case, the fraction Fendix wrongly flagged. Returns 0 when the corpus has no negatives.
func (*BenchmarkResult) Precision ¶
func (r *BenchmarkResult) Precision() float64
Precision is TP / (TP + FP): of everything Fendix flagged, the fraction that was a real vulnerability. Returns 0 when nothing was flagged (TP+FP == 0), which is the conventional, regression-safe choice — an empty prediction set has no precision to brag about.
func (*BenchmarkResult) Recall ¶
func (r *BenchmarkResult) Recall() float64
Recall is TP / (TP + FN): of every real vulnerability in the corpus, the fraction Fendix caught. Returns 0 when the corpus has no positives.
type BenchmarkTarget ¶
type BenchmarkTarget interface {
// Name is the stable identifier used in output tables and as the key
// under which this target's result is stored in the baseline
// (e.g. "owasp", "dvwa", "juiceshop"). It must be lowercase and stable
// across releases — renaming it orphans the stored baseline.
Name() string
// Run scores result against the target's known vulnerabilities and
// returns the computed BenchmarkResult. Implementations MUST NOT
// mutate result. Errors are wrapped with the target name for context.
Run(ctx context.Context, result *ScanResult) (*BenchmarkResult, error)
}
BenchmarkTarget is implemented by each benchmark corpus. Run scores an already-produced ScanResult against the target's ground truth. The scan itself (Docker spin-up, corpus download, invoking fendix) is the concern of the concrete target in internal/benchmark/targets — the interface keeps scoring separate from scan production so each half can be tested in isolation.
type FPClass ¶
type FPClass string
FPClass is the false-positive taxonomy (design §5). It is also the enum used in a label's `fp_class:` field, so a labels file can never name a class the fixes don't track.
const ( FPConstantAuthority FPClass = "constant-authority" FPReceiverConfusion FPClass = "receiver-confusion" FPSafeAPIMisread FPClass = "safe-api-misread" FPConstFoldMiss FPClass = "const-fold-miss" FPGuardDominance FPClass = "guard-dominance" FPTestFixture FPClass = "test-fixture" FPHTTP4xxContext FPClass = "http-4xx-context" FPStaticAssetCtx FPClass = "static-asset-context" FPDoubleSanitize FPClass = "double-sanitize" FPHeuristicOverfire FPClass = "heuristic-overfire" FPVersionRangeFloor FPClass = "version-range-floor" FPFabricatedChain FPClass = "fabricated-chain" )
type Label ¶
type Label struct {
Rule string `yaml:"rule"`
File string `yaml:"file"`
Line int `yaml:"line"`
Verdict Verdict `yaml:"verdict"`
FPClass FPClass `yaml:"fp_class,omitempty"`
Note string `yaml:"note,omitempty"`
}
Label is one ground-truth entry keyed by a STABLE (rule+file+line) tuple, not a fingerprint — fingerprints embed evidence text that legitimate fixes change, silently orphaning labels (design §4.3).
type LabelSet ¶
type LabelSet struct {
Labels []Label
}
LabelSet is the parsed labels.yaml for one corpus entry.
func LoadLabelSet ¶
LoadLabelSet reads and validates a labels.yaml. verdict:fp requires a valid fp_class; any verdict other than tp/fp is rejected.
type MetricDelta ¶
type MetricDelta struct {
Target string `json:"target"`
Metric string `json:"metric"`
Baseline float64 `json:"baseline"`
Current float64 `json:"current"`
PctChange float64 `json:"pct_change"`
Regression bool `json:"regression"`
}
MetricDelta is one metric's movement from baseline to current. PctChange is signed and relative to the baseline value (current-base)/base.
type RealWorldResult ¶
type RealWorldResult struct {
Entry string
TruePos int
FalsePos int
Unknown int
FalseNeg int
PerClass map[FPClass]int
// Unknowns is the triage list: findings that matched no label.
Unknowns []models.Finding
// LabelNotes are the matched labels that carry a reviewer `note:` — the
// recorded justification for a tp/fp verdict. Collected so the triage
// report can show WHY a finding was classed the way it was; without it the
// note field is written by humans and read by nobody.
LabelNotes []Label
LOC int
}
RealWorldResult is the scored outcome of one real-world corpus entry. It is richer than BenchmarkResult (which the baseline stores): it carries the unknown bucket, the per-fp_class breakdown, and the noise-density metric.
func ScoreRealWorld ¶
func ScoreRealWorld(entry string, ls *LabelSet, findings []models.Finding, loc int) *RealWorldResult
ScoreRealWorld matches each finding to at most one label and buckets it.
func (*RealWorldResult) FindingsPerKLOC ¶
func (r *RealWorldResult) FindingsPerKLOC() float64
FindingsPerKLOC is noise density over emitted findings that carry a label (tp+fp); unknowns are excluded so density tracks the same defensible set as precision.
func (*RealWorldResult) Precision ¶
func (r *RealWorldResult) Precision() float64
Precision is over LABELED findings only (tp/(tp+fp)); unknowns are excluded until triaged, which is what makes the number defensible (design §4.3).
type RegressionReport ¶
type RegressionReport struct {
GeneratedAt time.Time `json:"generated_at"`
Deltas []MetricDelta `json:"deltas"`
// NewTargets lists current results with no baseline entry (first run
// for that target — recorded, never a regression).
NewTargets []string `json:"new_targets,omitempty"`
}
RegressionReport is the result of comparing a set of current results against the stored baseline.
func (*RegressionReport) HasRegression ¶
func (rr *RegressionReport) HasRegression() bool
HasRegression reports whether any metric regressed past the threshold.
type ScanResult ¶
type ScanResult struct {
// Findings is everything the scan emitted for this target.
Findings []models.Finding
// ScanDuration is wall-clock time for the scan that produced Findings.
ScanDuration time.Duration
// MemoryPeakMB is the peak RSS observed during the scan, in MiB.
MemoryPeakMB float64
}
ScanResult is the raw output of running Fendix against a benchmark target: the findings it produced plus the cost of producing them. It is deliberately decoupled from the reporters' on-disk report shape so the benchmark package never depends on output formatting (and so changing a report format can never silently move a baseline number).
Directories
¶
| Path | Synopsis |
|---|---|
|
Package targets implements the concrete benchmark corpora for the v0.20 baseline suite: OWASP Benchmark (white-box / SAST), DVWA, and OWASP Juice Shop (black-box / DAST).
|
Package targets implements the concrete benchmark corpora for the v0.20 baseline suite: OWASP Benchmark (white-box / SAST), DVWA, and OWASP Juice Shop (black-box / DAST). |