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 FixedIn(r *Record, pkg Package, v string) string
- func GoSemver(s string) string
- 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
- type Affected
- type Binary
- type BinaryFinder
- type Cycle
- type EOL
- type EOLClient
- type EOLStatus
- type Enricher
- type Event
- type OSVClient
- type Package
- type Problem
- type Query
- type Range
- type Record
- type Request
- type Result
- type Score
- type Severity
- type Vuln
Constants ¶
const ( SourceEOL = "endoflife.date" SourceOSV = "osv" )
Sources an Problem can name.
const ( EcosystemGo = "Go" EcosystemGit = "GIT" )
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 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.
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 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 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.
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
Queries []Query `json:"queries"`
Vulns []Vuln `json:"vulns"`
}
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 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).
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 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 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.
func (*Enricher) BinaryVulns ¶
BinaryVulns queries OSV for every binary's queries in one batch and fills in their vulns.
func (*Enricher) Enrich ¶
func (e *Enricher) Enrich(ctx context.Context, reqs []Request) (map[string]Result, []Problem, error)
Enrich answers every request. It 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.
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 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) QueryBatch ¶
QueryBatch returns the vulnerability IDs of each query, in query order. It follows each result's next_page_token.
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"`
}
Record is an OSV vulnerability record, reduced to the fields relgap reads.
type Request ¶
type Request struct {
Key string // the caller's key for the result
Tool registry.ToolSpec
Current version.V
Target version.V // zero when there is no target
}
Request asks for the EOL state and vulnerabilities of one tool version, and how a target version compares.
type Result ¶
Result is what enrichment found for one request. A nil EOL or Vulns means the tool has no endoflife.date product or OSV package, or the source failed (see Problem).
type Score ¶
type Score struct {
Score float64 `json:"score,omitempty"`
Rating string `json:"rating"` // none, low, medium, high or critical
Vector string `json:"vector,omitempty"` // the CVSS vector the score comes from
}
Score is a record's severity: the highest CVSS base score among its vectors with its rating, or only the advisory's own rating when it has no vector.
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"`
}
Vuln is one known vulnerability of a tool's current version.