Documentation
¶
Overview ¶
Package feeds fetches and caches the exploitability datasets Draugr can enrich findings with: CISA's Known Exploited Vulnerabilities catalog and FIRST's EPSS scores.
Fetching is never implicit. A scan that silently reaches the internet is not reproducible, and the gate has to be. So the network is touched when someone asks for it, by running `draugr feeds update` or by passing `auto`, and a scan otherwise reads a local cache with no network access at all. That keeps the air-gapped path and the connected path the same code.
The cache records where each feed came from and when, because "we escalated this to critical because it was on KEV as of 2026-08-01" is an auditable statement and "KEV said so" is not.
Index ¶
- Constants
- Variables
- func CheckGoVulnDB(path string) error
- func Describe(n Name) string
- func Dir() (string, error)
- func GoVulnAliases(path string) (map[string][]string, error)
- func HumanAge(d time.Duration) string
- func HumanBytes(n int64) string
- func IndexOSVArchive(zipPath string) ([]byte, error)
- func Load(dir string) map[Name]Record
- func Path(dir string, n Name) string
- func ShortDuration(d time.Duration) string
- func URL(n Name) string
- type LocalGoVulnDB
- type Name
- type OSVRecord
- type Record
Constants ¶
const DefaultMaxAge = 24 * time.Hour
DefaultMaxAge is how old a cached feed may be before `auto` refetches it and a scan warns.
One day, because EPSS is republished daily: a score is a 30-day probability recomputed every morning, so a week-old copy silently mis-ranks. KEV changes far less often and is held to the same bar deliberately, two staleness rules to explain is worse than one that is slightly strict for one feed.
Variables ¶
var Ecosystems = map[string]Name{"npm": OSVNpm, "pypi": OSVPyPI, "crates.io": OSVCrates, "go": OSVGo}
Ecosystems maps the value config.exploitability.advisories takes to the feed it reads.
var ErrNoLocalGoVulnDB = errors.New("no local Go vulnerability database")
ErrNoLocalGoVulnDB means no local copy of the Go vulnerability database has been fetched.
Functions ¶
func CheckGoVulnDB ¶ added in v0.133.0
CheckGoVulnDB reports whether path holds a Go vulnerability database govulncheck can answer from: an index that parses, and at least one module in it.
The shape is the documented offline form (`index/db.json`, `index/modules.json`, `ID/*.json`). Both checks exist because govulncheck reports "No vulnerabilities found" against a database that is empty or unreadable, and a scan must never read that as a clean result.
func Dir ¶
Dir is the feed cache: feeds/ under $DRAUGR_HOME when it is set, and ~/.draugr/feeds otherwise. Beside the tools rather than apart from them, because a machine that moves where Draugr writes, a container whose home is read-only or a runner with one shared cache, needs the datasets moved with the scanners that read them.
func GoVulnAliases ¶ added in v0.181.0
GoVulnAliases reads the record index of the Go vulnerability database at path, index/vulns.json, as each record's id mapped to the aliases it lists.
The database documents the index as one entry per vulnerability, each with its `id`, `modified` time and `aliases`, "IDs of the same vulnerability in other databases": the CVE and GitHub advisory ids beside the `GO-…` one. An index that is missing, unreadable or empty is an error rather than an empty map, because a lookup against no records finds no CVE for every finding and would read as though none had one.
func HumanAge ¶ added in v0.135.0
HumanAge renders a duration the way someone reads a staleness report: the largest unit that still says something useful, and never more precision than the answer deserves.
func HumanBytes ¶ added in v0.135.0
HumanBytes renders a size in the largest unit that keeps it under four digits.
func IndexOSVArchive ¶ added in v0.190.0
IndexOSVArchive reads an OSV.dev ecosystem archive at zipPath into the index the cache keeps: every record's id, aliases and stated license, sorted by id.
Records of the OpenSSF Malicious Packages project (`MAL-…`) are left out. They describe a package published to do harm, not a flaw with a CVE, and Draugr reads them through its own malicious package check. An archive with no record left is an error rather than an empty index, because a lookup against no records finds no CVE for every finding and would read as though none had one.
func Load ¶
Load reads the manifest. A missing or unreadable manifest is an empty one: the feeds it described are then treated as absent, which is the safe direction, worst case a refetch.
func ShortDuration ¶ added in v0.160.0
ShortDuration renders a duration the way it is written in a descriptor or a config file: 24h, not 24h0m0s.
Types ¶
type LocalGoVulnDB ¶ added in v0.133.0
LocalGoVulnDB is a local copy of the Go vulnerability database that passed its checks.
func FindGoVulnDB ¶ added in v0.133.0
FindGoVulnDB returns the cached Go vulnerability database if it is usable as of now: fetched, no older than maxAge, and structurally sound. The error names the check that failed.
Age is measured from when Draugr fetched the copy, not from the database's own modified date, which moves only when an advisory changes and so can lag a copy fetched this morning by days.
type Name ¶
type Name string
Name identifies a feed.
const ( KEV Name = "kev" EPSS Name = "epss" // GoVulnDB is the Go vulnerability database govulncheck reads, kept as a local copy for a // runner that cannot reach vuln.go.dev. GoVulnDB Name = "govulndb" )
The feeds Draugr knows how to fetch.
const ( OSVNpm Name = "osv-npm" OSVPyPI Name = "osv-pypi" OSVCrates Name = "osv-crates.io" OSVGo Name = "osv-go" )
The OSV.dev advisory feeds, one per ecosystem. Each is read only to find the CVE of a finding its scanner named by another advisory id, so KEV and EPSS can match it, and only where a descriptor asks for that ecosystem in config.exploitability.advisories.
func AdvisoryNames ¶ added in v0.190.0
func AdvisoryNames() []Name
AdvisoryNames lists the OSV.dev advisory feeds, in the order commands present them. They are kept apart from Names because nothing reads them unless a descriptor opts in, and an archive can weigh hundreds of megabytes.
type OSVRecord ¶ added in v0.190.0
type OSVRecord struct {
ID string `json:"id"`
Aliases []string `json:"aliases,omitempty"`
License string `json:"license,omitempty"`
}
OSVRecord is one OSV.dev record as the advisory index keeps it: its id, the ids it lists as the same vulnerability elsewhere, and the license its source states on the record, where it states one.
func ReadOSVIndex ¶ added in v0.190.0
ReadOSVIndex reads the advisory index a fetch wrote at path. A missing, unreadable or empty index is an error, for the reason IndexOSVArchive refuses an empty archive.
type Record ¶
type Record struct {
URL string `json:"url"`
FetchedAt time.Time `json:"fetchedAt"`
SHA256 string `json:"sha256"` // of the decompressed bytes on disk
Bytes int64 `json:"bytes"`
}
Record is what the cache knows about one fetched feed.
func Fetch ¶
Fetch downloads one feed into dir, decompressing it if the upstream is gzipped, and records what it fetched. It returns the resulting cache entry.
The write is atomic: a temporary file in the same directory, renamed into place. A fetch interrupted halfway must not leave a half a catalog behind for the next scan to parse as though it were complete.