Documentation
¶
Overview ¶
Package report turns scan findings into what a person reads and what a pipeline greps.
One Report, several renderers. The model is built once from the enriched findings, the dependency graphs, any defence lookups and any recorded compensating controls; the packages, findings, tree, plain and GitHub renderers all read it. A wording change lands everywhere at once, and the renderers cannot disagree about what a package's urgency or fix is, because neither is computed in a renderer.
The unit is the package, not the advisory. Nobody upgrades an advisory: they upgrade a package, once, to a version that clears every advisory on it.
Index ¶
- Constants
- Variables
- func AttachDefences(r *Report, found map[string]defences.Summary, checked bool, reason string)
- func DefenceIDs(r Report) []string
- func MergeSummaries(id string, in []defences.Summary) defences.Summary
- func ParseList(values ...string) []string
- func Render(view string, r Report, o Options, t *display.Terminal) string
- func RenderCode(r CodeReport, o Options, t *display.Terminal) string
- func RenderCodeExplain(r CodeReport, query string, o Options, t *display.Terminal) (string, bool)
- func RenderCodeGitHub(r CodeReport) string
- func RenderCodePlain(r CodeReport, o Options, t *display.Terminal) string
- func RenderDefend(v DefendView, o Options, t *display.Terminal) string
- func RenderExplain(r Report, query string, o Options, t *display.Terminal) (string, bool)
- func RenderFindings(r Report, o Options, t *display.Terminal) string
- func RenderGitHub(r Report) string
- func RenderJSON(r Report) ([]byte, error)
- func RenderPackages(r Report, o Options, t *display.Terminal) string
- func RenderPlain(r Report, o Options, t *display.Terminal) string
- func RenderTree(r Report, o Options, t *display.Terminal) string
- func ResolveView(o Options, t *display.Terminal, ci bool) string
- func Set(values []string) map[string]bool
- func SevWord(level string) string
- func SortedNames(m map[string]bool) []string
- func StepSummary(r Report) string
- func Validate(flag string, values, allowed []string) error
- type Advisory
- type CodeFinding
- type CodeReport
- type Counts
- type DefendView
- type Fix
- type FixState
- type Group
- type Input
- type Meta
- type Options
- type Package
- type Report
- type Signal
- type Style
- func (s *Style) Bad(t string) string
- func (s *Style) Bold(t string) string
- func (s *Style) Cmd(t string) string
- func (s *Style) Defence(t string) string
- func (s *Style) Dim(t string) string
- func (s *Style) Good(t string) string
- func (s *Style) Hot(t string) string
- func (s *Style) Path(t string) string
- func (s *Style) Rule(width int) string
- func (s *Style) Sev(level, text string) string
- func (s *Style) Warn(t string) string
Constants ¶
const ( ViewAuto = "auto" ViewPackages = "packages" ViewFindings = "findings" ViewTree = "tree" ViewTable = "table" ViewPlain = "plain" ViewJSON = "json" )
Views are the names `--view` accepts. "table" is the legacy eighteen-column table; it is drawn by the scan command itself and never reaches this package.
const JSONSchema = "vulnetix/report/v1"
JSONSchema names the shape RenderJSON emits. It changes only by adding fields.
Variables ¶
var ( Views = []string{ViewAuto, ViewPackages, ViewFindings, ViewTree, ViewTable, ViewPlain, ViewJSON} FilterNames = []string{"kev", "exploited", "reachable", "fixable", "nofix", "defended", "unprotected", "direct", "transitive"} ShowParts = []string{"paths", "files", "clean", "scores", "defences"} HideParts = []string{"fixes", "exploits", "defences", "not-affected"} SortKeys = []string{"threat", "severity", "package"} )
Allowed values for the list-valued flags. They are the single source for both validation and shell completion.
Functions ¶
func AttachDefences ¶
AttachDefences records lookup results on the no-fix packages. found is keyed by the identifier that was looked up; a package whose advisories were never indexed gets StateNotIndexed rather than being left silent.
func DefenceIDs ¶
DefenceIDs lists the identifiers worth looking up: one entry per indexed advisory on each package that has no fix. Duplicates are removed.
func MergeSummaries ¶
MergeSummaries combines per-advisory summaries into one for the package.
func RenderCode ¶
func RenderCode(r CodeReport, o Options, t *display.Terminal) string
RenderCode draws code findings in the packages view's grammar: a verdict line, then the files, worst first, then the next command.
func RenderCodeExplain ¶
RenderCodeExplain shows the rule behind a finding and where it fired.
func RenderCodeGitHub ¶
func RenderCodeGitHub(r CodeReport) string
RenderCodeGitHub emits workflow-command annotations, one per finding, on the file and line.
func RenderCodePlain ¶
func RenderCodePlain(r CodeReport, o Options, t *display.Terminal) string
RenderCodePlain is the pipe and CI form: one line per finding.
func RenderDefend ¶
func RenderDefend(v DefendView, o Options, t *display.Terminal) string
RenderDefend draws the read view: what exists, in which lane, how sure the rule is, how it should be started, and what it does not cover. Block and detect are separate sections, because one stops the request and the other only tells you it happened.
func RenderExplain ¶
RenderExplain shows the working behind each matching finding. It returns false when nothing matched.
func RenderFindings ¶
RenderFindings is the flat view: one line per advisory, grouped like the packages view but without collapsing a package's advisories.
func RenderGitHub ¶
RenderGitHub emits workflow commands that GitHub Actions turns into annotations on the manifest line, one per package. Findings that need action are errors, the rest warnings, and anything with a recorded control a notice.
func RenderJSON ¶
RenderJSON is the machine-readable view: every package with its group, fix and, for each advisory, the verdict and the working behind it. Findings the verdict rules out are included under ruledOut; nothing is dropped.
func RenderPackages ¶
RenderPackages draws the default view: a verdict, then packages grouped by what to do about them, then the next command.
func RenderPlain ¶
RenderPlain is the pipe and CI renderer: one line per package, stable columns, ASCII only. It is a documented output format, so scripts may rely on it.
func RenderTree ¶
RenderTree groups packages under the manifest that declared them.
func ResolveView ¶
ResolveView picks the renderer. An explicit --view wins; otherwise a pipe, a file or CI gets the plain renderer and a person at a terminal gets packages.
func SortedNames ¶
SortedNames returns the keys of a set in a stable order, for messages.
func StepSummary ¶
StepSummary renders the report as Markdown for $GITHUB_STEP_SUMMARY.
Types ¶
type Advisory ¶
type Advisory struct {
ID string
Severity string // normalised: critical high medium low info
CVSS float64
EPSS float64
KEV bool
Exploits int
Verdict scan.VerdictResult
Signals []Signal
// Reach is the raw reachability outcome; ReachAt is a file:line when known.
Reach string
ReachAt string
// Fix is the version this advisory alone recommends, if any.
Fix string
// FixSource says where Fix came from: "recommended" or "advisory" (the upper
// bound of its affected range).
FixSource string
// AnyUpgrade is set when moving to any other version clears this advisory.
AnyUpgrade bool
// FixAvailability is the server's word: available, partial, no_fix.
FixAvailability string
// AlsoKnownAs lists the other identifiers of the same vulnerability that were
// folded into this one (see foldAliases).
AlsoKnownAs []string
Ev scan.EnrichedVuln
}
Advisory is one vulnerability on one package.
type CodeFinding ¶
type CodeFinding struct {
RuleID string
Name string
Severity string
Kind string // sast | secrets | iac | oci
Path string
Line int
EndLine int
Message string
// Snippet is the matched source. It is never printed for secrets.
Snippet string
Description string
HelpURI string
CWE []int
TestSuite bool
}
CodeFinding is one finding from the rule engine: static analysis, secrets, infrastructure as code or container files. They share a layout because they share a shape: a place in a file, a rule, a message.
func FindCodeExplain ¶
func FindCodeExplain(r CodeReport, query string) []CodeFinding
FindCodeExplain returns the findings a --explain query names: a rule id, or a file path.
type CodeReport ¶
type CodeReport struct {
Findings []CodeFinding
// Label names what ran: "SAST", "Secrets", "IaC", "Containers".
Label string
RulesLoaded int
RulesTotal int
}
CodeReport is the engine's result, ready to draw.
type Counts ¶
Counts is the header's partition. Every package with a counting advisory is in exactly one of Action, Wait, Protected, Monitored, so the numbers add up.
type DefendView ¶
type DefendView struct {
PackageLabel string
ID string
Fix Fix
// Exploit is a one-line description of the public exploit, when known.
Exploit string
Summary defences.Summary
// Fits are the enforcement points inferred from the repository.
Fits map[defences.Kind]defences.Hint
}
DefendView is everything `vulnetix defend` shows for one finding.
type Fix ¶
type Fix struct {
State FixState
// Target is the version to move to. Empty with FixAvailable means a fix is
// reported to exist but its version was not given.
Target string
// Clears and Of describe a partial fix: "2 of 3".
Clears, Of int
}
Fix is the lowest version that clears the package's advisories.
type FixState ¶
type FixState int
FixState is the package-level answer to "how do I fix it".
const ( // FixUnknown means the data carried no remediation either way. FixUnknown FixState = iota // FixAvailable means one version clears every advisory. FixAvailable // FixPartial means a version clears some advisories and not all. FixPartial // FixNone means no version clears any advisory. FixNone )
type Group ¶
type Group string
Group says what to do about a package, which is not the same as how severe it is. A critical advisory nothing reaches can wait; a medium one under active exploitation cannot.
const ( // GroupAction is exploited, reachable, on a KEV list or malicious. GroupAction Group = "action" // GroupWait is affected but with no signal that raises urgency. GroupWait Group = "wait" // GroupUnverified is matched by name where the advisory's range cannot be // compared with the installed version (a git commit, say). It still counts: // unknown is not safe. It does not claim urgency, because nobody has // established the package is affected at all. GroupUnverified Group = "unverified" // GroupProtected has an unexpired recorded control that blocks the request. // It is still affected, and still counted. GroupProtected Group = "protected" // GroupMonitored has an unexpired recorded control that only detects, or a // blocking rule still in log-only mode. It stops nothing. GroupMonitored Group = "monitored" // GroupNotAffected was matched by name and ruled out by version. GroupNotAffected Group = "not_affected" )
type Input ¶
type Input struct {
Vulns []scan.EnrichedVuln
Groups []scan.ManifestGroup
Controls defences.ControlSet
Meta Meta
// Strict counts not-affected and likely-not-affected findings anyway.
Strict bool
Now time.Time
}
Input is everything Build needs. Nothing in it is read from the environment.
type Meta ¶
type Meta struct {
ScannedPackages int
Manifests int
// Kinds are the scanners that ran: "sca", "sast", ...
Kinds []string
Elapsed time.Duration
// VEXSuppressed is how many findings third-party VEX closed.
VEXSuppressed int
// Strict records that not-affected findings were counted anyway.
Strict bool
}
Meta is run context for the header.
type Options ¶
type Options struct {
View string
Filters []string
MinSeverity string
Sort string
Show, Hide map[string]bool
// Verbosity is 0 normally, 1 for -v, 2 for -vv.
Verbosity int
Quiet bool
ASCII bool
// Width forces a width; zero uses the terminal's.
Width int
Now time.Time
// Command names the subcommand in plain output: "scan", "sca", and so on.
Command string
}
Options shape what is shown. None of them changes what is found, counted in JSON or SARIF, or gated: they are about the terminal.
type Package ¶
type Package struct {
Name, Version, Ecosystem, Scope string
// Source is the manifest (or image, or pipeline file) that declared it.
Source string
// MoreSources counts further manifests that declare the same package.
MoreSources int
Direct bool
// Via is the chain from a direct dependency to this one, excluding it.
Via []string
Severity string
Malicious bool
// Advisories are those that count: affected or unverified, worst first.
Advisories []Advisory
// RuledOut are advisories matched by name and excluded by version.
RuledOut []Advisory
Fix Fix
Signals []Signal
Group Group
// Defence is set only for packages with no fix, and only when asked.
Defence *defences.Summary
// DefenceID is the identifier the defence lookup used.
DefenceID string
// Controls are the unexpired recorded controls covering this package.
Controls []defences.Control
// Lapsed is a recorded control that has expired, if one was found.
Lapsed *defences.Control
// Covered reports that every counted advisory has an active control.
Covered bool
// contains filtered or unexported fields
}
Package is one dependency and everything known about its problems.
func FindExplain ¶
FindExplain returns the packages (and the advisory, when the query named one) that a --explain query refers to. The query is an advisory id, a package name or name@version, compared case-insensitively. The report passed in must be the unfiltered one: explaining a finding the display filters hid is the point.
func Unprotected ¶
Unprotected lists the packages with no fix and no recorded, unexpired control: the "no fix and no plan" set that `--fail-on unprotected` fails on.
type Report ¶
Report is the whole result.
func Apply ¶
Apply returns the report with the display options applied: filtered, hidden and sorted. The input is not modified.
type Style ¶
type Style struct {
T *display.Terminal
G glyphs
Width int
// contains filtered or unexported fields
}
Style draws text for one terminal. With colour off every method returns its input unchanged, so tests and pipes see exactly the characters, no escapes.