enrich

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: Apache-2.0 Imports: 29 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const (
	SourceEOL = "endoflife.date"
	SourceOSV = "osv"
)

Sources an Problem can name.

View Source
const (
	EcosystemGo  = "Go"
	EcosystemGit = "GIT"
)

OSV ecosystems and range types relgap handles specially.

View Source
const EndOfLifeURL = "https://endoflife.date/api/v1"

EndOfLifeURL is the endoflife.date API v1 base URL.

View Source
const OSVURL = "https://api.osv.dev"

OSVURL is the OSV API base URL.

View Source
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

View Source
var ErrNoProduct = errors.New("not an endoflife.date product")

ErrNoProduct is returned when endoflife.date has no such product.

Functions

func Affects

func Affects(r *Record, pkg Package, v string) (bool, bool)

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

func CycleName(e registry.EOL, s version.Scheme, v version.V) string

CycleName fills the registry cycle template for v; an empty template means {major}.{minor}.

func FixedIn

func FixedIn(r *Record, pkg Package, v string) string

FixedIn returns the lowest fixed version above v in the ranges of pkg, or "".

func GoSemver

func GoSemver(s string) string

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

func QueryVersion(p registry.OSVPackage, tag string, v version.V) string

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 Rating

func Rating(score float64) string

Rating returns the qualitative rating of a CVSS score.

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

func ReadBinary(tool, path string) (*Binary, error)

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.

func (BinaryFinder) Find

Find returns the executables named in t.Bin (default: the tool name), resolved paths without duplicates: PATH first, then $MISE_DATA_DIR/installs/<tool>/<version>/ and its bin/. Version aliases (symlinks such as latest or 1.17) are skipped.

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

func NewEOLClient(hc *http.Client, base string) *EOLClient

NewEOLClient returns a client that sends requests through hc to base (empty means EndOfLifeURL).

func (*EOLClient) Cycles

func (c *EOLClient) Cycles(ctx context.Context, product string) ([]Cycle, error)

Cycles returns the release cycles of product. It wraps ErrNoProduct for 404.

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.

func Status

func Status(cycles []Cycle, e registry.EOL, s version.Scheme, v version.V) *EOLStatus

Status looks up the cycle of v among cycles.

type Enricher

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

Enricher looks tools up on endoflife.date and OSV.

func NewEnricher

func NewEnricher(logger *slog.Logger, eol *EOLClient, osv *OSVClient, concurrency int) *Enricher

NewEnricher returns an enricher that uses eol and osv with up to concurrency requests at once.

func (*Enricher) BinaryVulns

func (e *Enricher) BinaryVulns(ctx context.Context, bins []*Binary) error

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 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.

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

func NewOSVClient(hc *http.Client, base string) *OSVClient

NewOSVClient returns a client that sends requests through hc to base (empty means OSVURL).

func (*OSVClient) QueryBatch

func (c *OSVClient) QueryBatch(ctx context.Context, qs []Query) ([][]string, error)

QueryBatch returns the vulnerability IDs of each query, in query order. It follows each result's next_page_token.

func (*OSVClient) Vuln

func (c *OSVClient) Vuln(ctx context.Context, id string) (*Record, error)

Vuln returns the record of id.

type Package

type Package struct {
	Ecosystem string `json:"ecosystem"`
	Name      string `json:"name"`
}

Package is a package in an OSV ecosystem.

type Problem

type Problem struct {
	Source string
	Tool   string
	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"`
}

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"`
}

Record is an OSV vulnerability record, reduced to the fields relgap reads.

func (*Record) Score

func (r *Record) Score(pkg Package) *Score

Score returns the highest score among the record's CVSS vectors for pkg, as osv-scanner does, or the advisory's database-specific rating (GitHub's MODERATE, HIGH). It returns nil when the record has neither, as Go vulnerability database records don't.

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

type Result struct {
	EOL   *EOL
	Vulns []Vuln
}

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 Severity

type Severity struct {
	Type  string `json:"type"`
	Score string `json:"score"`
}

Severity is one severity score of a record, such as a CVSS 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.

Jump to

Keyboard shortcuts

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