Documentation
¶
Overview ¶
Package osv queries the OSV (Open Source Vulnerabilities) database for a set of ecosystem/name/version coordinates, and parses the lockfile formats that produce those coordinates in the first place
Index ¶
- func PackageLockDevOnly(data []byte) map[Coordinate]bool
- func PoetryLockDevOnly(data []byte) map[Coordinate]bool
- func QueryAll(ctx context.Context, q Querier, coords []Coordinate) (map[Coordinate][]Vuln, error)
- func UvLockDevOnly(data []byte) map[Coordinate]bool
- type Affected
- type BatchQuerier
- type Coordinate
- func ParseCargoLock(data []byte) ([]Coordinate, error)
- func ParseGoMod(data []byte) (coords []Coordinate, notes []string, err error)
- func ParseGoSum(data []byte) ([]Coordinate, error)
- func ParsePackageLock(data []byte) (coords []Coordinate, notes []string, err error)
- func ParsePoetryLock(data []byte) (coords []Coordinate, notes []string, err error)
- func ParseRequirementsTxt(data []byte) (coords []Coordinate, unpinned, included int, err error)
- func ParseUvLock(data []byte) (coords []Coordinate, notes []string, err error)
- type Event
- type HTTPClient
- type Querier
- type Range
- type Vuln
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func PackageLockDevOnly ¶ added in v1.2.0
func PackageLockDevOnly(data []byte) map[Coordinate]bool
PackageLockDevOnly returns the coordinates an npm package-lock.json marks "dev": true at every place they appear. npm leaves those out of a production install (npm ci --omit=dev), so they are not part of a server installed that way. "devOptional" is not dev-only: it may be installed.
func PoetryLockDevOnly ¶ added in v1.2.0
func PoetryLockDevOnly(data []byte) map[Coordinate]bool
PoetryLockDevOnly returns the packages a poetry.lock records as development-only: category = "dev" in lock files before Poetry 1.2, or a groups list without "main" in Poetry 2 lock files. A lock file that records neither marks nothing.
func QueryAll ¶
func QueryAll(ctx context.Context, q Querier, coords []Coordinate) (map[Coordinate][]Vuln, error)
QueryAll looks up every coordinate, stopping early on context cancellation. It returns partial results alongside any error so a caller can still report what it managed to check.
func UvLockDevOnly ¶ added in v1.2.0
func UvLockDevOnly(data []byte) map[Coordinate]bool
UvLockDevOnly returns the registry packages reachable only through the project's development groups. The project's own packages are the roots: what their dependencies and extras reach is installed with the server; what only their dev-dependencies reach is not (uv sync --no-dev).
Types ¶
type Affected ¶
type Affected struct {
Package struct {
Ecosystem string `json:"ecosystem"`
Name string `json:"name"`
Purl string `json:"purl,omitempty"`
} `json:"package"`
Ranges []Range `json:"ranges,omitempty"`
Versions []string `json:"versions,omitempty"`
DatabaseSpecific map[string]any `json:"database_specific,omitempty"`
}
Affected is one package's affected-version data within a Vuln
type BatchQuerier ¶
type BatchQuerier interface {
Querier
QueryBatch(ctx context.Context, coords []Coordinate) (map[Coordinate][]Vuln, error)
}
BatchQuerier is a Querier that can also look up many coordinates in one round trip. QueryAll uses it when the Querier passed in implements it - HTTPClient does - and falls back to Query per coordinate otherwise, which is what a test double implementing only Querier gets.
type Coordinate ¶
Coordinate identifies one package version to check. Ecosystem follows OSV's own vocabulary: "npm", "PyPI", "Go", "crates.io".
func ParseCargoLock ¶
func ParseCargoLock(data []byte) ([]Coordinate, error)
ParseCargoLock extracts coordinates from a Cargo.lock file
func ParseGoMod ¶
func ParseGoMod(data []byte) (coords []Coordinate, notes []string, err error)
ParseGoMod extracts required-module coordinates from a go.mod file's require directives (both the single-line and block forms). Prefer ParseGoSum when a go.sum is available: it lists the versions actually selected, including transitive dependencies go.mod alone does not show.
func ParseGoSum ¶
func ParseGoSum(data []byte) ([]Coordinate, error)
ParseGoSum extracts module coordinates from a go.sum file. go.sum lists each module twice (a content hash and a "/go.mod" hash); the /go.mod line is skipped so each module@version is reported once
func ParsePackageLock ¶
func ParsePackageLock(data []byte) (coords []Coordinate, notes []string, err error)
ParsePackageLock extracts coordinates from an npm package-lock.json, handling both the v2/v3 "packages" map and the legacy v1 "dependencies" tree
func ParsePoetryLock ¶
func ParsePoetryLock(data []byte) (coords []Coordinate, notes []string, err error)
ParsePoetryLock extracts coordinates from a poetry.lock file
func ParseRequirementsTxt ¶
func ParseRequirementsTxt(data []byte) (coords []Coordinate, unpinned, included int, err error)
ParseRequirementsTxt extracts pinned coordinates from a requirements.txt and counts, separately, the two kinds of dependency it cannot look up. Unpinned entries are reported as unqueryable; included files are unread content and therefore downgrade coverage.
func ParseUvLock ¶ added in v1.2.0
func ParseUvLock(data []byte) (coords []Coordinate, notes []string, err error)
ParseUvLock extracts registry coordinates from a uv.lock. The project's own packages (editable, virtual, a local directory) are not on the registry; a git or URL source is a note, as in poetry.lock.
func (Coordinate) String ¶
func (c Coordinate) String() string
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 point in an affected-version range
type HTTPClient ¶
HTTPClient is a Querier backed by the public OSV API. Its client is guarded by httpx: no private-network destination, dial-time enforcement, no cross-origin redirect followed - the same policy a registry fetch gets, since this is the same class of fixed, third-party network call.
func NewHTTPClient ¶
func NewHTTPClient() *HTTPClient
NewHTTPClient builds a Querier against the public OSV API
func (*HTTPClient) Query ¶
func (c *HTTPClient) Query(ctx context.Context, coord Coordinate) ([]Vuln, error)
func (*HTTPClient) QueryBatch ¶
func (c *HTTPClient) QueryBatch(ctx context.Context, coords []Coordinate) (map[Coordinate][]Vuln, error)
QueryBatch sends bounded chunks and maps each positional response back to its coordinate. A short response is an error because treating the missing positions as empty would report unchecked packages as clean.
type Querier ¶
type Querier interface {
Query(ctx context.Context, coord Coordinate) ([]Vuln, error)
}
Querier looks up vulnerabilities for one coordinate. The HTTP client below implements it against the live API; tests implement it against a fixed set of recorded responses.
type Range ¶
Range is one affected-version range, e.g. a SEMVER range with an "introduced" and a "fixed" event
type Vuln ¶
type Vuln struct {
ID string `json:"id"`
Aliases []string `json:"aliases,omitempty"` // typically CVE and/or GHSA ids
Summary string `json:"summary,omitempty"`
Details string `json:"details,omitempty"`
Affected []Affected `json:"affected,omitempty"`
DatabaseSpecific map[string]any `json:"database_specific,omitempty"`
}
Vuln is one OSV record
func (Vuln) FixedVersions ¶
FixedVersions collects every "fixed" event across every range for the named package, so a report can tell a reader what to upgrade to
func (Vuln) Severity ¶
Severity returns OSV's own severity label when the record carries one, preferring the top-level field and falling back to the first affected entry that has one. It returns "" when OSV did not classify it, which callers should treat as "confirmed affected, severity unknown" rather than as a reason to drop the finding.