Documentation
¶
Overview ¶
Package offline ships an air-gapped CVE database snapshot format and a thin "fendix db" CLI surface around it. Sprint 09 (Phase 4.1) — for customers whose CI runners can't reach osv.dev / proxy.golang.org / index.golang.org.
Snapshot file format (v1):
{
"schema": 1,
"generated_at": "2026-05-15T12:00:00Z",
"generator": "fendix vX.Y.Z db update --source ...",
"sources": ["osv.dev", "golang.org/x/vuln"],
"advisories": [
{
"id": "GHSA-...",
"aliases": ["CVE-..."],
"package": {"ecosystem": "PyPI", "name": "..."},
"ranges": [{"introduced": "1.0.0", "fixed": "1.0.3"}],
"summary": "...",
"references": ["https://..."]
},
...
]
}
The format is deliberately a subset of OSV's wire schema so we can hydrate it directly from an OSV.dev mirror without an intermediate translation step. Future versions can add fields without bumping `schema` as long as readers ignore unknowns (which the Go json decoder does by default).
The package itself ships the snapshot read/write + verify path. Sprint 09 deliberately leaves the *integration* with the per- ecosystem scanners (pip / npm / govulncheck) as follow-ups — the shape is set, but rewiring each scanner's HTTP path through a snapshot index is genuinely 2-3 days each. See the per-scanner TODO comments + the Sprint 09 Status section.
Index ¶
Constants ¶
const MaxAdvisories = 5_000_000
MaxAdvisories caps the count of advisories one snapshot can carry. Belt-and-braces with MaxSnapshotBytes so a pathological JSON with many short entries can't sneak past the byte cap.
const MaxSnapshotBytes = 200 << 20
MaxSnapshotBytes caps the on-disk size of a snapshot that Read / FromOSVExport will accept. A malformed or hostile input produces a clean error instead of OOMing the scanner. 200 MiB is generous for a full OSV.dev mirror (~100k advisories ≈ 70 MiB compressed JSON).
const SchemaVersion = 1
SchemaVersion is the on-disk format version. Bump when the format changes in a non-backward-compatible way.
Variables ¶
var ErrSchemaMismatch = errors.New("offline: snapshot schema version mismatch")
ErrSchemaMismatch is returned when the on-disk schema doesn't match SchemaVersion.
var ErrSnapshotMissing = errors.New("offline: snapshot file not found")
ErrSnapshotMissing is returned by Read when the path doesn't exist. Scan paths can errors.Is-check this to emit a clear "run `fendix db update` first" error.
Functions ¶
func CompareVersions ¶
CompareVersions is the exported form of compareVersions, for the pip and npm dependency scanners' upgrade-target selection (FIX-06). Returns -1, 0 or +1. The unexported body stays the single implementation, so the offline range matching above and the scanners' fix-version ranking can never drift apart — and TestCompareVersions keeps locking both.
Semantics, stated precisely because the callers depend on the edges:
- Dotted components compare numerically when both parse as ints ("1.2.0" < "1.10.0"), lexically otherwise; a missing trailing component is zero ("1.2" == "1.2.0").
- A leading "v" is stripped, and everything from the first '-' or '+' is discarded. So npm semver pre-releases ("1.0.0-rc.1") and build metadata ("1.0.0+build") both collapse to their release core — a pre-release pin compares EQUAL to its release, not less.
- PyPI suffixes with no separator are NOT normalised: "1.2.3.post1" and "1.2.3rc1" both sort ABOVE "1.2.3" (post1 correctly, rc1 incorrectly), and "1.2.3.dev0" sorts above "1.2.3" (incorrectly). PEP 440 epochs ("1!2.0") are not understood.
Callers MUST NOT read a non-positive result as "no fix exists" — see the fallback ladder in the scanners' fixCandidate, which is what keeps these pre/dev-release edges from turning into a false "no fix listed in OSV".
func DefaultDBPath ¶
func DefaultDBPath() string
DefaultDBPath is where `fendix db update` writes by default. Honours the XDG/fendix conventions used elsewhere in the codebase.
func Write ¶
Write encodes the snapshot as pretty JSON to the given path, creating parent directories. The file ends with a trailing newline so it round-trips through line-oriented tooling (jq, less, diff).
The write is durable: payload is written to a sibling temp file and then atomically renamed over `path`. A crash mid-write leaves either the previous snapshot intact or the new one — never a half-flushed JSON that subsequent Read would reject.
Types ¶
type Advisory ¶
type Advisory struct {
ID string `json:"id"`
Aliases []string `json:"aliases,omitempty"`
Package PackageRef `json:"package"`
Ranges []Range `json:"ranges,omitempty"`
Summary string `json:"summary,omitempty"`
References []string `json:"references,omitempty"`
}
Advisory mirrors the OSV.dev wire shape, but only the subset we actually consume. Unknown fields in real OSV data are silently dropped on decode.
func (Advisory) FirstFixedVersion ¶
FirstFixedVersion returns the first non-empty Fixed endpoint across the advisory's ranges, or "" when none is listed. Used to render the "upgrade to X" hint in offline findings.
func (Advisory) PrimaryAlias ¶
PrimaryAlias returns the first alias (typically the CVE-* id) or "".
type PackageRef ¶
type Snapshot ¶
type Snapshot struct {
Schema int `json:"schema"`
GeneratedAt time.Time `json:"generated_at"`
Generator string `json:"generator"`
Sources []string `json:"sources"`
Advisories []Advisory `json:"advisories"`
}
Snapshot is the in-memory shape of an on-disk DB.
func Decode ¶
Decode parses snapshot JSON bytes into a Snapshot, validating the schema version, the byte budget, the advisory count, and the per-advisory required fields. Required fields are non-empty ID, ecosystem, and package name — anything below that is a malformed snapshot we don't want to silently load.
func FromOSVExport ¶
FromOSVExport hydrates a Snapshot from a list of OSV advisory JSON objects. Used by `fendix db update --source` to ingest an OSV.dev `vulns.zip` extract.
func Read ¶
Read loads a snapshot from disk. Returns ErrSnapshotMissing when the path doesn't exist (a normal "user hasn't run update yet" outcome). Files larger than MaxSnapshotBytes are rejected before being read into memory — a malformed or hostile snapshot can't OOM the scanner.
func ReadFrom ¶
ReadFrom is a streaming variant for very large snapshots. Not used today (~few MB of advisories fits in memory comfortably), but available for the millions-of-advisories future.
func Verify ¶
Verify computes a SHA-256 hash of the snapshot file and returns hex-encoded. Callers can compare to a published checksum to catch integrity-corrupting transfers (especially over air-gapped sneakernet).
func (*Snapshot) LookupByPackage ¶
LookupByPackage returns every advisory matching (ecosystem, name). Ecosystem comparison is case-insensitive (OSV uses "PyPI", we might receive "pypi"); name comparison is case-sensitive (per OSV convention). Uses strings.EqualFold so non-ASCII ecosystems compare correctly.
func (*Snapshot) LookupVulnerable ¶
LookupVulnerable returns every advisory for (ecosystem, name) whose version ranges include the given installed version. It powers the air-gapped dep-CVE path: the pip and npm scanners call this in --offline mode instead of querying osv.dev, so the same snapshot that `fendix db` produces drives offline scanning.
Range semantics follow OSV's SEMVER/ECOSYSTEM model: a version is vulnerable when, for some range, version >= Introduced and (Fixed is empty OR version < Fixed). An advisory with no ranges is treated as "applies to every version" (matches OSV's "no fix known, all versions affected" convention). Versions that don't parse fall back to a conservative match so a malformed pin is reported rather than silently dropped — over-reporting is the safe failure mode for a security tool.