vuln

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package vuln is the engine module for vulnerability scanning (CAPABILITY_SPEC domain 2). It consumes the SBOM produced by internal/sbom — it never re-walks the image — matches each component against a local, offline advisory database (internal/vulndb), enriches matches with CVSS/EPSS/CISA-KEV, applies VEX statements and waivers to cut false positives, ranks by real exploitability, and projects the survivors into the unified Finding model.

The design is "deterministic core, optional intelligence layer": matching and ranking are pure and reproducible with zero models or network present; the reachability-aware VEX auto-generation (reachability.go) is an off-by-default enrichment behind a clean interface. Given the same SBOM and the same pinned advisory DB, the findings are byte-identical — with one exception: DS-RAT-VULN-EOL falls back to the wall clock (time.Now().UTC()) when Options.Now is zero, so EOL findings are time-dependent unless a clock is explicitly injected via Options.Now. Pin Options.Now to get fully byte-identical output including EOL.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Command

func Command(args []string) int

Command implements `dsecrat vuln <subcommand>`. It returns a process exit code.

dsecrat vuln update --from <dir> [--url <mirror>] [--ecosystems <list>] --out <path> [--source <label>]
dsecrat vuln info   [--db <path>]

func Register

func Register(r *engine.Registry)

Register adds the vuln module to the registry. The master agent calls this from modules.Default() during integration; this package never edits the shared registry file itself (SHARED_CONTRACT §2).

Types

type Evidence

type Evidence struct {
	Component   sbom.Component
	Coord       vulndb.Coord
	UsedSymbols map[string]bool // symbols/imports observed in the artifact
	HaveSymbols bool            // whether symbol evidence was available at all
}

Evidence is what an analyzer gets to reason over.

type Fix

type Fix struct {
	// Type is "upgrade" when a fixed version exists, else "no-fix".
	Type      string `json:"type"`
	Ecosystem string `json:"ecosystem"`
	Package   string `json:"package"`
	From      string `json:"from"`
	To        string `json:"to,omitempty"`
	// Action is a terse imperative an agent can act on directly.
	Action string `json:"action"`
}

Fix is a structured, model-consumable remediation.

type MapSymbolSource

type MapSymbolSource map[string][]string

MapSymbolSource is a trivial SymbolSource backed by an in-memory map, keyed by component PURL (falling back to name). It exists so callers and tests can inject symbol evidence without a binary analyzer.

func (MapSymbolSource) Symbols

func (m MapSymbolSource) Symbols(c sbom.Component) (map[string]bool, bool)

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module is the vulnerability-scanning capability.

func New

func New() *Module

New returns a vuln module using the embedded advisory snapshot and safe defaults (no suppression).

func NewWithOptions

func NewWithOptions(o Options) *Module

NewWithOptions returns a vuln module with explicit options, used by tests and by the frontends that pre-load a DB / VEX / waivers.

func (*Module) Analyze

func (m *Module) Analyze(ctx context.Context, t *engine.Target) ([]engine.Finding, error)

Analyze generates the SBOM for the target, matches every component against the advisory DB, and returns the resulting findings plus a summary.

func (*Module) Description

func (m *Module) Description() string

func (*Module) Domains

func (m *Module) Domains() []string

func (*Module) Name

func (m *Module) Name() string

func (*Module) Supports

func (m *Module) Supports(t engine.TargetType) bool

Supports mirrors the SBOM module: vulnerability matching applies to anything we can build an SBOM from.

type Options

type Options struct {
	// DB is the advisory source. When nil, the module loads DBPath if set,
	// otherwise the embedded bootstrap snapshot.
	DB     *vulndb.DB
	DBPath string

	// Now is the injected clock used for DB staleness and waiver expiry. Zero
	// disables both time-dependent behaviors, keeping analysis deterministic.
	Now time.Time

	// VEX holds OpenVEX statements that suppress not-affected/fixed findings.
	VEX []VEXStatement
	// Waivers are operator allowlist entries with a justification and expiry.
	Waivers []Waiver

	// Reachability, when set, judges whether a vulnerable symbol is plausibly
	// reached and can emit not_reachable VEX drafts. Nil means "always
	// reachable" — the safe default that suppresses nothing.
	Reachability Reachability
	// Symbols supplies per-component symbol evidence for reachability. Nil means
	// no evidence, so reachability never concludes not-reached (no false
	// negatives from a missing symbol table).
	Symbols SymbolSource
}

Options configures a vuln module. The zero value is valid: it uses the embedded advisory snapshot, no VEX/waivers, and reachability off (nothing is suppressed). Frontends may also pass configuration per-run via Target.Metadata (see optionsFromTarget), which is how the CLI/HTTP layers reach this module without a bespoke API.

type Reachability

type Reachability interface {
	Reached(ev Evidence, adv vulndb.Advisory) Verdict
}

Reachability judges whether a vulnerability's code is plausibly reached.

type SymbolReachability

type SymbolReachability struct{}

SymbolReachability is the deterministic heuristic analyzer. Enable it (with a SymbolSource) to cut confirmed noise.

func (SymbolReachability) Reached

Reached applies the symbol-level rule:

  • advisory declares no symbols → reachable (unknown, be safe)
  • no symbol evidence for the component → reachable (be safe)
  • evidence present, none of the advisory's symbols used → NOT reached
  • otherwise (an affected symbol is used) → reachable

type SymbolSource

type SymbolSource interface {
	// Symbols returns the set of symbols/imports observed for a component and
	// whether any symbol information was available.
	Symbols(c sbom.Component) (used map[string]bool, have bool)
}

SymbolSource supplies per-component symbol evidence to the reachability layer. A real implementation reads symbol tables from binaries or import graphs from lockfiles; the module ships without one, so reachability stays inert until a caller wires evidence in.

type VEXStatement

type VEXStatement struct {
	Vuln          string   // CVE/GHSA id the statement is about
	Products      []string // product identifiers (PURLs); empty = applies to all
	Status        vexStatus
	Justification string
}

VEXStatement is a normalized single VEX assertion.

func LoadVEXFile

func LoadVEXFile(path string) ([]VEXStatement, error)

LoadVEXFile reads and parses an OpenVEX document from disk.

func ParseVEX

func ParseVEX(data []byte) ([]VEXStatement, error)

ParseVEX parses an OpenVEX document into normalized statements. It tolerates both the object and string spellings OpenVEX allows for vulnerability and product fields.

type Verdict

type Verdict struct {
	Reached    bool
	Reason     string
	Confidence string // "high" | "medium" | "low"
}

Verdict is a reachability judgement for one component/advisory pair.

type Waiver

type Waiver struct {
	Vulnerability string    // CVE/GHSA id, or "*"/"" for any
	Package       string    // package name, or "*"/"" for any
	Reason        string    // required justification (audit trail)
	Expires       time.Time // zero = never expires
}

Waiver is an allowlist entry.

func LoadWaiversFile

func LoadWaiversFile(path string) ([]Waiver, error)

LoadWaiversFile reads a JSON array of waivers. Expiry is an RFC 3339 string.

Jump to

Keyboard shortcuts

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