Documentation
¶
Overview ¶
Package enrich adds end-of-life dates from endoflife.date and known vulnerabilities from OSV to a tool's versions, and reads the Go build info of installed binaries.
Index ¶
- Constants
- Variables
- func Affects(r *Record, pkg Package, v string) (bool, bool)
- func CycleName(e registry.EOL, s version.Scheme, v version.V) string
- func EPSSScore(e *EPSS) float64
- func FixedIn(r *Record, pkg Package, v string) string
- func GoPrefixes(path string) []string
- func GoSemver(s string) string
- func KEVFirst(a, b *KEV) int
- func NameReason(name string) (string, bool)
- func PackagesFor(pkgs []registry.OSVPackage, s version.Scheme, v version.V) []registry.OSVPackage
- func QueryVersion(p registry.OSVPackage, tag string, v version.V) string
- func Rating(score float64) string
- func SkipReason(name string, err error) string
- type Affected
- type Binary
- type BinaryFinder
- type Coverage
- type Cycle
- type EOL
- type EOLClient
- type EOLStatus
- type EPSS
- type EPSSClient
- type Enricher
- func (e *Enricher) BinaryVulns(ctx context.Context, bins []*Binary) ([]Problem, error)
- func (e *Enricher) Enrich(ctx context.Context, reqs []Request) (map[string]Result, []Problem, error)
- func (e *Enricher) SetFeeds(kev *KEVClient, epss *EPSSClient)
- func (e *Enricher) SetPrivacy(p Privacy)
- func (e *Enricher) SetSuppressor(s Suppressor)
- type Event
- type Fix
- type GoPrivate
- type Hit
- type KEV
- type KEVClient
- type OSVClient
- type Package
- type Privacy
- type Problem
- type Query
- type Range
- type Record
- type Repo
- type Request
- type Result
- type Score
- type SentField
- type Severity
- type Subject
- type Suppression
- type Suppressor
- type VersionLister
- type Visibility
- type Vuln
Constants ¶
const ( ReasonNoSource = "no-advisory-source" // no curated osv list and no backend or repository OSV knows ReasonPrivate = "private-source" // a host or registry relgap never sends to OSV ReasonNotExact = "not-exact" // a constraint, range, branch, channel or bare SHA ReasonUnresolved = "unresolved" // the pin resolves to no tool ReasonOffline = "offline" // --offline and no cached answer ReasonFailed = "failed" // OSV failed for this pin )
Reasons a pin is unchecked: relgap didn't ask OSV about it, so it is never reported as clean.
const ( SourceEOL = "endoflife.date" SourceOSV = "osv" SourceKEV = "kev" SourceEPSS = "epss" )
Sources an Problem can name.
const ( KEVHost = "www.cisa.gov" EPSSHost = "api.first.org" KEVURL = "https://" + KEVHost + "/sites/default/files/feeds/known_exploited_vulnerabilities.json" EPSSURL = "https://" + EPSSHost + "/data/v1/epss" )
Prioritization feeds: the CISA Known Exploited Vulnerabilities catalog and FIRST EPSS.
const ( SentQueryBatch = "POST /v1/querybatch" SentVuln = "GET /v1/vulns/{id}" )
The requests of SentField.
const ( SuppressedByIgnore = "ignore" // a vulns.ignore entry SuppressedByVEX = "vex" // an OpenVEX statement )
Suppression kinds.
const ( EcosystemGo = "Go" EcosystemGit = "GIT" // EcosystemActions holds GitHub Actions advisories. OSV doesn't evaluate their ECOSYSTEM // ranges for a version, so relgap asks without one and matches the ranges itself. EcosystemActions = "GitHub Actions" )
OSV ecosystems and range types relgap handles specially.
const EndOfLifeURL = "https://endoflife.date/api/v1"
EndOfLifeURL is the endoflife.date API v1 base URL.
const OSVURL = "https://api.osv.dev"
OSVURL is the OSV API base URL.
const RatingUnknown = "unknown"
RatingUnknown is the rating of an advisory that neither it nor a GHSA alias rates.
const ReachabilityNote = "matched by Go version and module version only: relgap doesn't check " +
"whether the binary calls the vulnerable code"
ReachabilityNote says what binary mode can't tell, unlike govulncheck's symbol analysis.
Variables ¶
var ErrNoProduct = errors.New("not an endoflife.date product")
ErrNoProduct is returned when endoflife.date has no such product.
var ErrNotPublic = errors.New("the repository isn't public")
ErrNotPublic means a forge answered that a repository is private, internal or not visible.
Functions ¶
func Affects ¶
Affects reports whether the record lists version v of pkg as affected, following the OSV schema: v is in versions, or inside a range's introduced..fixed (or ..last_affected). The second result is false when a range that could hold v can't be compared and no versions list covers it.
func CycleName ¶
CycleName fills the registry cycle template for v; an empty template means {major}.{minor}.
func EPSSScore ¶ added in v0.13.0
EPSSScore returns the score of e, or -1 without one, so advisories without a score sort last.
func GoPrefixes ¶ added in v0.13.0
GoPrefixes returns the prefixes of a Go package path that could be its module, longest first.
func GoSemver ¶
GoSemver turns a Go version or tag (go1.24, 1.24.3, go1.25rc1) into the semver form OSV uses for the Go ecosystem (1.24.0, 1.24.3, 1.25.0-rc.1). Other text comes back trimmed of a v.
func KEVFirst ¶ added in v0.13.0
KEVFirst orders an advisory in the KEV catalog (a) before one that isn't (b): it returns -1 when only a is listed, 1 when only b is, and 0 otherwise.
func NameReason ¶ added in v0.13.0
NameReason returns the unchecked reason of a pin whose tool name alone says OSV is never asked about it: an image (private-source on a registry relgap never sends to, else no-advisory-source) or a chart. Neither takes a curated entry, so it needs no lookup. The second result is false for every other name.
func PackagesFor ¶
func PackagesFor(pkgs []registry.OSVPackage, s version.Scheme, v version.V) []registry.OSVPackage
PackagesFor returns the OSV packages that describe major version line of v. A Go module path ending in /vN belongs to major N only; one without a suffix belongs to majors 0 and 1 when the list has suffixed paths too, and to every major otherwise.
func QueryVersion ¶
QueryVersion is the version string OSV expects for v of a package: the tag for GIT, the Go semver form for Go, and the version itself elsewhere.
func SkipReason ¶ added in v0.13.0
SkipReason returns why a pin of the tool name isn't checked when resolving name failed with err: a tool relgap doesn't know is unresolved, a registry it may not read or that wants an account is private, and a failed lookup is offline or failed.
Types ¶
type Affected ¶
type Affected struct {
Package Package `json:"package"`
Ranges []Range `json:"ranges"`
Versions []string `json:"versions"`
Severity []Severity `json:"severity"`
DatabaseSpecific struct {
Severity string `json:"severity"`
} `json:"database_specific"`
}
Affected lists the affected versions of one package.
type Binary ¶
type Binary struct {
Tool string `json:"tool"`
Path string `json:"path"`
GoVersion string `json:"go_version"` // as OSV takes it, such as 1.24.3
Module string `json:"module,omitempty"` // the main module path
ModuleVersion string `json:"module_version,omitempty"` // absent for (devel) builds
// ModuleUnchecked says why OSV wasn't asked about the main module, such as private-source.
ModuleUnchecked string `json:"module_unchecked,omitempty"`
Queries []Query `json:"queries"`
Vulns []Vuln `json:"vulns"`
// contains filtered or unexported fields
}
Binary is an installed Go executable of a tool and what OSV knows about its Go version and main module.
func ReadBinary ¶
ReadBinary reads the Go build info of the executable of tool t at path and the OSV queries it implies: the standard library at the Go version, and the main module unless it was built as (devel). Enricher.BinaryVulns drops the main module when it may be private.
type BinaryFinder ¶
type BinaryFinder struct {
Lookup func(key string) (string, bool) // environment
// Which resolves a mise shim to the executable it runs, as `mise which` does; nil skips
// shims, whose targets the installs directory has anyway.
Which func(ctx context.Context, name string) (string, error)
}
BinaryFinder finds a tool's executables on PATH and among mise's installed versions.
type Coverage ¶ added in v0.13.0
type Coverage struct {
Packages []registry.OSVPackage // queried at the version
GoPath string // a go: package path; its longest prefix OSV knows is queried at the version
Repo Repo // the repository the packages name; zero for a curated list or a package backend
Reason string // why nothing is queried; empty when the tool is checked
}
Coverage is what relgap asks OSV about one tool version, or why it asks nothing.
func CoverageOf ¶ added in v0.13.0
CoverageOf returns what relgap asks OSV about version v of tool t, whose pins name it name (the name `relgap digest` accepts, such as chart:argo/argo-cd). A curated osv list wins. Otherwise a package backend names the package, an action its GitHub Actions package, and a github.com tool gets its Go module and a GIT query on its repository, the mapping mise audit uses. Hosts other than github.com and gitlab.com are never sent.
type Cycle ¶
type Cycle struct {
Name string `json:"name"`
IsEOL bool `json:"isEol"`
EOLFrom string `json:"eolFrom"` // date; empty when not announced
IsMaintained bool `json:"isMaintained"`
Latest struct {
Name string `json:"name"`
} `json:"latest"`
}
Cycle is one release cycle of an endoflife.date product.
type EOL ¶
type EOL struct {
Product string `json:"product"`
Current *EOLStatus `json:"current"`
Target *EOLStatus `json:"target,omitempty"`
}
EOL is the end-of-life state of a tool's current and target versions.
type EOLClient ¶
type EOLClient struct {
// contains filtered or unexported fields
}
EOLClient reads products from the endoflife.date API v1.
func NewEOLClient ¶
NewEOLClient returns a client that sends requests through hc to base (empty means EndOfLifeURL).
type EOLStatus ¶
type EOLStatus struct {
Version string `json:"version"`
Cycle string `json:"cycle"`
IsEOL *bool `json:"is_eol,omitempty"` // absent when endoflife.date doesn't list the cycle
EOLFrom string `json:"eol_from,omitempty"` // date the cycle reaches or reached its end
LatestInCycle string `json:"latest_in_cycle,omitempty"` // newest release of the cycle
Note string `json:"note,omitempty"`
}
EOLStatus is the end-of-life state of one version's cycle.
type EPSS ¶ added in v0.13.0
type EPSS struct {
CVE string `json:"cve"`
Score float64 `json:"score"` // probability of exploitation in the next 30 days, 0 to 1
Percentile float64 `json:"percentile"` // share of scored CVEs at or below this score, 0 to 1
Date string `json:"date"` // YYYY-MM-DD the score was computed
}
EPSS is an advisory's FIRST EPSS score.
type EPSSClient ¶ added in v0.13.0
type EPSSClient struct {
// contains filtered or unexported fields
}
EPSSClient reads EPSS scores, each CVE once per client.
func NewEPSSClient ¶ added in v0.13.0
func NewEPSSClient(hc *http.Client, url string) *EPSSClient
NewEPSSClient returns a client that sends its requests through hc to url (empty means EPSSURL).
type Enricher ¶
type Enricher struct {
// contains filtered or unexported fields
}
Enricher looks tools up on endoflife.date and OSV.
func NewEnricher ¶
NewEnricher returns an enricher that uses eol and osv with up to concurrency requests at once. A nil eol skips endoflife.date.
func (*Enricher) BinaryVulns ¶
BinaryVulns queries OSV for every binary's queries in one batch and fills in their vulns, marking the ones the suppressor names and adding the feeds' fields. It returns the feeds that failed as problems, and an error when OSV failed.
func (*Enricher) Enrich ¶
func (e *Enricher) Enrich(ctx context.Context, reqs []Request) (map[string]Result, []Problem, error)
Enrich answers every request. It asks endoflife.date and OSV at the same time, fetches each product's cycles once, sends all OSV queries in batches and fetches each record once. A failed source becomes a Problem; only a canceled context is an error.
func (*Enricher) SetFeeds ¶ added in v0.13.0
func (e *Enricher) SetFeeds(kev *KEVClient, epss *EPSSClient)
SetFeeds makes the enricher add the KEV entry and the EPSS score of each advisory's CVE aliases. A nil client skips its feed.
func (*Enricher) SetPrivacy ¶ added in v0.13.0
SetPrivacy sets what the enricher keeps away from OSV.
func (*Enricher) SetSuppressor ¶ added in v0.13.0
func (e *Enricher) SetSuppressor(s Suppressor)
SetSuppressor makes the enricher suppress the advisories s names before it works out the fix targets. A nil s suppresses nothing.
type Event ¶
type Event struct {
Introduced string `json:"introduced,omitempty"`
Fixed string `json:"fixed,omitempty"`
LastAffected string `json:"last_affected,omitempty"`
Limit string `json:"limit,omitempty"`
}
Event is one introduced, fixed, last_affected or limit event.
type Fix ¶ added in v0.13.0
type Fix struct {
Lowest string `json:"lowest,omitempty"` // absent when no release qualifies
LowestInLine string `json:"lowest_in_line,omitempty"` // the same within the current version's line
Latest string `json:"latest"` // the newest stable release
// LatestAffected says whether OSV lists an advisory for Latest, named in LatestAffectedBy.
LatestAffected bool `json:"latest_affected"`
LatestAffectedBy []string `json:"latest_affected_by,omitempty"`
// Unfixed lists the advisories of the current version that Latest still has: no release fixes
// them.
Unfixed []string `json:"unfixed,omitempty"`
}
Fix is the release a tool version can move to: the lowest stable release above it that every advisory with a fix has left behind and that has no fixable advisory of its own.
type GoPrivate ¶ added in v0.13.0
type GoPrivate struct {
// contains filtered or unexported fields
}
GoPrivate holds the module path patterns of GOPRIVATE, GONOPROXY and GONOSUMDB, which Go keeps away from its proxy and checksum database.
func NewGoPrivate ¶ added in v0.13.0
NewGoPrivate returns the patterns of a GOPRIVATE value: comma-separated globs on path prefixes.
func ReadGoPrivate ¶ added in v0.13.0
ReadGoPrivate reads GOPRIVATE, GONOPROXY and GONOSUMDB as the go command does: a non-empty environment variable, else the file `go env -w` writes ($GOENV, or go/env in the user config directory of goos). GONOPROXY and GONOSUMDB default to GOPRIVATE, so the patterns add up.
type Hit ¶ added in v0.13.0
type Hit struct {
ID string `json:"id"`
Modified string `json:"modified"` // RFC 3339, as querybatch returns it
}
Hit is a record a query returned, with the time OSV last changed it.
type KEV ¶ added in v0.13.0
type KEV struct {
CVE string `json:"cve"`
DateAdded string `json:"date_added"` // YYYY-MM-DD
DueDate string `json:"due_date"` // YYYY-MM-DD, the remediation deadline for US federal agencies
Ransomware bool `json:"ransomware"` // CISA knows of its use in ransomware campaigns
}
KEV is an advisory's entry in the CISA Known Exploited Vulnerabilities catalog.
type KEVClient ¶ added in v0.13.0
type KEVClient struct {
// contains filtered or unexported fields
}
KEVClient reads the CISA KEV catalog once per client.
func NewKEVClient ¶ added in v0.13.0
NewKEVClient returns a client that sends its request through hc to url (empty means KEVURL).
type OSVClient ¶
type OSVClient struct {
// contains filtered or unexported fields
}
OSVClient queries the OSV API.
func NewOSVClient ¶
NewOSVClient returns a client that sends requests through hc to base (empty means OSVURL).
func (*OSVClient) Known ¶ added in v0.13.0
Known reports, for each package, whether OSV has any record of it. It reads one page per package, sent as versionless queries in batches.
func (*OSVClient) OldestAge ¶ added in v0.13.0
OldestAge returns the largest Age header of the responses read so far: how long ago the oldest answer was stored in a cache. The second result is false when no response had one.
func (*OSVClient) QueryBatch ¶
QueryBatch returns the records of each query, in query order. It follows each result's next_page_token.
func (*OSVClient) Vuln ¶
Vuln returns the record of id. A modified time from a querybatch hit keeps the record cached for 7 days while it is unchanged; such an answer is current, so its Age doesn't count for OSVClient.OldestAge. Empty modified caches the record like any other OSV answer.
type Privacy ¶ added in v0.13.0
type Privacy struct {
Go GoPrivate
// Repos answers for the repositories the user named: a github: or gitlab: pin, a
// tools.<name>.repo entry, a --guess or an action. nil treats each of them as private.
Repos Visibility
}
Privacy says what relgap keeps away from OSV beyond the hosts it never sends.
type Problem ¶
type Problem struct {
Source string
Tool string // empty for a feed that failed for every tool (KEV, EPSS)
Err error
}
Problem is a source that failed for a tool. The rest of the report stands.
type Query ¶
type Query struct {
Package Package `json:"package"`
Version string `json:"version,omitempty"` // empty asks about every version
}
Query asks which vulnerabilities affect one version of a package.
type Range ¶
type Range struct {
Type string `json:"type"`
Repo string `json:"repo,omitempty"`
Events []Event `json:"events"`
}
Range is an OSV affected range: events in a SEMVER, ECOSYSTEM or GIT ordering. GIT ranges name their repository instead of a package.
type Record ¶
type Record struct {
ID string `json:"id"`
Aliases []string `json:"aliases"`
Summary string `json:"summary"`
Details string `json:"details"`
Severity []Severity `json:"severity"`
Affected []Affected `json:"affected"`
DatabaseSpecific struct {
Severity string `json:"severity"`
} `json:"database_specific"`
Withdrawn time.Time `json:"withdrawn,omitzero"` // set when the record no longer applies
}
Record is an OSV vulnerability record, reduced to the fields relgap reads.
type Repo ¶ added in v0.13.0
type Repo struct {
Host string // forge.GitHub or forge.GitLab
Path string // owner/repo, or the project path
}
Repo is a repository on github.com or gitlab.com.
func (Repo) ModulePath ¶ added in v0.13.0
ModulePath is the repository as a Go module path, such as github.com/acme/tool.
type Request ¶
type Request struct {
Key string // the caller's key for the result
Name string // the pin's tool name, such as chart:argo/argo-cd; empty means Tool.Name
Tool registry.ToolSpec
Current version.V
Target version.V // zero when there is no target
// Versions lists the tool's releases for the fix target; nil skips it. It runs only when OSV
// lists an advisory for Current.
Versions VersionLister
// Refs are other values the pins give the version, such as an action's commit SHA, which a
// VEX statement can name instead of the tag.
Refs []string
// contains filtered or unexported fields
}
Request asks for the EOL state and vulnerabilities of one tool version, and how a target version compares.
type Result ¶
type Result struct {
EOL *EOL
Vulns []Vuln
Unchecked string // a Reason* constant; empty when OSV answered
Fix *Fix
}
Result is what enrichment found for one request. A nil EOL means the tool has no endoflife.date product or the source failed (see Problem). Vulns is nil when OSV wasn't asked or failed, and Unchecked says which. Fix is nil without an advisory of the current version, or when its version list or OSV failed.
type Score ¶
type Score struct {
Score float64 `json:"score,omitempty"`
Rating string `json:"rating"` // none, low, medium, high, critical or unknown
Vector string `json:"vector,omitempty"` // the CVSS vector the score comes from
From string `json:"from,omitempty"` // the GHSA alias the score comes from
}
Score is a record's severity: the highest CVSS base score among its vectors with its rating, only the advisory's own rating when it has no vector, or the rating unknown.
type SentField ¶ added in v0.13.0
type SentField struct {
Request string `json:"request"` // the method and path of the request
Name string `json:"name"` // the JSON path of the field in the body, or the path parameter
Description string `json:"description"`
}
SentField is one value that a request to OSV carries.
type Subject ¶ added in v0.13.0
type Subject struct {
Tool string // as pins show it, such as kubectl or action:actions/checkout
Version string // the version OSV was asked about
PURLs []purl.PURL // the package URLs of its OSV packages and repository, at the version
}
Subject is a tool version as suppression rules name it.
type Suppression ¶ added in v0.13.0
type Suppression struct {
Kind string `json:"kind"` // ignore or vex
Reason string `json:"reason"`
Until string `json:"until,omitempty"` // the ignore entry's last day
Source string `json:"source,omitempty"` // the VEX document's path
Status string `json:"status,omitempty"` // the VEX status: not_affected or fixed
Justification string `json:"justification,omitempty"` // the VEX justification label
}
Suppression says why an advisory doesn't count: a vulns.ignore entry or an OpenVEX statement. A suppressed advisory stays in the report and is left out of counts, gates and fix targets.
type Suppressor ¶ added in v0.13.0
type Suppressor interface {
// Suppress returns why the advisory is suppressed for s, or nil, and counts a match as a use
// of its rule.
Suppress(s Subject, names []string) *Suppression
// Covers reports whether a rule suppresses the advisory for s, without counting a use.
Covers(s Subject, names []string) bool
}
Suppressor decides which advisories of a tool version are suppressed. names holds the advisory's ID and aliases.
type VersionLister ¶ added in v0.13.0
VersionLister returns a tool's released versions.
type Visibility ¶ added in v0.13.0
type Visibility interface {
// Public returns, for each repository, nil when it is public, an error wrapping
// [ErrNotPublic] when it isn't, and the lookup's error when the forge didn't say. The error
// is set only for a canceled context.
Public(ctx context.Context, repos []Repo) (map[Repo]error, error)
}
Visibility looks up whether repositories are public.
type Vuln ¶
type Vuln struct {
ID string `json:"id"`
Aliases []string `json:"aliases,omitempty"`
Summary string `json:"summary,omitempty"`
Package Package `json:"package"`
Severity *Score `json:"severity,omitempty"`
FixedIn string `json:"fixed_in,omitempty"` // lowest fixed version above the current one
AffectsCurrent bool `json:"affects_current"`
// FixedByTarget says whether the target version is outside every affected range. It is
// absent without a target or when the record's ranges can't be compared locally.
FixedByTarget *bool `json:"fixed_by_target,omitempty"`
// Suppressed says why the advisory doesn't count; absent when it does.
Suppressed *Suppression `json:"suppressed,omitempty"`
KEV *KEV `json:"kev,omitempty"` // with --kev, when a CVE alias is in the catalog
EPSS *EPSS `json:"epss,omitempty"` // with --epss, when EPSS scores a CVE alias
// contains filtered or unexported fields
}
Vuln is one known vulnerability of a tool's current version.