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 BuildSARIF(r Report, root, toolVersion string) *sarif.Log
- 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 RenderBinaries(b BinarySummary, 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 RenderMalscan(m MalscanReport, o Options, t *display.Terminal) string
- 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 BinaryRow
- type BinarySummary
- type CodeFinding
- type CodeReport
- type Counts
- type DefendView
- type Fix
- type FixState
- type Group
- type Input
- type MalscanFinding
- type MalscanReport
- type MalscanTarget
- 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", "tests"} 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 BuildSARIF ¶
BuildSARIF returns the report's SCA findings as a single-run SARIF log with the code scanning category vulnetix/sca/. root is the scan root the package sources are relative to; it is read only to find the declaring line.
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 RenderBinaries ¶
func RenderBinaries(b BinarySummary, o Options, t *display.Terminal) string
RenderBinaries draws the ELF pass as one section in the container report's grammar. It is a summary of what the files are, not a list of findings: the malware verdict and the packages inside travel on their own channels.
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 rules grouped by what to do, then the next commands.
func RenderCodeExplain ¶
RenderCodeExplain shows the rule behind a finding and every place it fired: production code first, grouped by file, then test code. A file path query explains each rule that fired in that file.
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, worst first.
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 RenderMalscan ¶
func RenderMalscan(m MalscanReport, o Options, t *display.Terminal) string
RenderMalscan draws a malware scan in the same grammar as the other scanners. A scan that checked nothing never reads as clean.
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 BinaryRow ¶
type BinaryRow struct {
Path string
Weaknesses []string
// Package is the OS package that installed it, when the lookup knew.
Package string
}
BinaryRow is one ELF file the container scan inspected.
type BinarySummary ¶
BinarySummary is the ELF pass of a container scan, ready to draw.
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
// Resource is the thing the finding sits in: "aws_s3_bucket.logs",
// "Deployment/api", "service api". ResourceLine is where it starts. The
// caller reads both from the file; they are empty where a file has no such
// notion.
Resource string
ResourceLine int
// Where a secret entered the history, from git blame. Blamed is false when
// nothing could be asked (not a git tree), so "unknown" is never "clean".
Blamed bool
// InHistory marks a copy found in a past commit, not in the working tree.
InHistory bool
Committed bool
Commit string
CommittedAt time.Time
}
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 MalscanFinding ¶
type MalscanFinding struct {
Ecosystem string
Package string // "" when the file belongs to no package
Location string // where the package is installed: "node_modules"
Title string
RuleID string
File string
Line int
Snippet string
Severity string
// Class is the engine's grade of the evidence: "evidence" convicts a package,
// "trigger" and "context" only make it worth a look.
Class string
IOCType string
IOCValue string
}
MalscanFinding is one piece of evidence from the malware scan, attributed to the installed package it was found in.
type MalscanReport ¶
type MalscanReport struct {
Findings []MalscanFinding
Targets []MalscanTarget
// Indicators is how many known-bad indicators were loaded to compare with.
Indicators int
// FeedsEnabled is false under --no-ioc-feeds, when zero indicators is chosen.
FeedsEnabled bool
IncludeHome bool
Warnings []string
}
MalscanReport is a malware scan, ready to draw.
type MalscanTarget ¶
MalscanTarget is one place dependencies are installed and what was checked in it.
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
// Unchecked are packages the advisory lookup could not answer for after retries.
// A report that omits them is incomplete, and must not read as "clean".
Unchecked []string
// 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
// RulePacks maps an upper-cased rule id to the external pack ("org/repo")
// that supplied it; an embedded rule maps to "". A suggested command loads
// the pack again, or the rule it names never runs.
RulePacks map[string]string
// Replay holds, per scanner, the input flags this run was given that a
// suggested command must repeat to see the same thing (--path, --exclude,
// --rule-registry, ...), already filtered to the flags that scanner takes.
// --rule is not in it: packs come from RulePacks.
Replay map[string][]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.