cve

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var SupportedEcosystems = []string{
	"npm", "PyPI", "Go", "Maven", "crates.io", "RubyGems", "Packagist", "NuGet",
}

SupportedEcosystems are the ecosystems we download from OSV.

Functions

func DownloadDatabase

func DownloadDatabase(dbDir string, ecosystems []string, progress func(eco string, done bool)) error

DownloadDatabase downloads the OSV vulnerability database for all ecosystems. Files are stored as gzipped JSON in the specified directory.

Types

type Affected

type Affected struct {
	Ecosystem string         `json:"ecosystem"`           // "npm", "PyPI", "Go", "Maven", "crates.io", etc.
	Package   string         `json:"package"`             // Package name
	Ranges    []VersionRange `json:"ranges,omitempty"`    // Affected version ranges
	Versions  []string       `json:"versions,omitempty"`  // Specific affected versions
	Functions []string       `json:"functions,omitempty"` // Vulnerable functions (if known)
}

Affected describes an affected package or product.

type Aggregator

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

Aggregator combines CVE data from multiple sources into a single unified view. Priority: GHSA for package version ranges, NVD for CVSS scores, OSV for ecosystem data, KEV for active exploitation status, ExploitDB/GitHub for PoC existence.

func NewAggregator

func NewAggregator(nvdAPIKey, githubToken, cacheDir string, cacheTTLHours int) *Aggregator

func (*Aggregator) Close

func (a *Aggregator) Close()

Close releases cache resources.

func (*Aggregator) Lookup

func (a *Aggregator) Lookup(ctx context.Context, cveID string) (*CVE, error)

Lookup fetches a CVE from all sources and merges the results.

func (*Aggregator) QueryByCPE

func (a *Aggregator) QueryByCPE(ctx context.Context, cpe string) ([]CVE, error)

QueryByCPE queries NVD for CVEs matching a CPE string. Used by the network scanner to match service versions.

func (*Aggregator) QueryPackage

func (a *Aggregator) QueryPackage(ctx context.Context, ecosystem, pkg, version string) ([]CVE, error)

QueryPackage finds all CVEs affecting a specific package+version. This is the primary method used during codebase scanning.

func (*Aggregator) QueryPackageBatch

func (a *Aggregator) QueryPackageBatch(ctx context.Context, packages []struct {
	Ecosystem string
	Name      string
	Version   string
}) (map[string][]CVE, error)

QueryPackageBatch queries OSV for multiple packages at once. Returns a map of "ecosystem/package@version" -> []CVE.

func (*Aggregator) QueryRecent

func (a *Aggregator) QueryRecent(ctx context.Context, since time.Time) ([]CVE, error)

QueryRecent fetches CVEs published since a given date.

type CVE

type CVE struct {
	ID          string     `json:"id"`          // e.g. "CVE-2026-31337"
	Description string     `json:"description"` // Human-readable description
	Severity    string     `json:"severity"`    // "CRITICAL", "HIGH", "MEDIUM", "LOW"
	CVSSScore   float64    `json:"cvss_score"`  // 0.0 - 10.0
	CVSSVector  string     `json:"cvss_vector,omitempty"`
	Published   time.Time  `json:"published"`
	Modified    time.Time  `json:"modified"`
	References  []string   `json:"references,omitempty"` // URLs to advisories, patches
	Affected    []Affected `json:"affected"`             // Which packages/products are affected
	HasExploit  bool       `json:"has_exploit"`          // PoC exists on ExploitDB
	InTheWild   bool       `json:"in_the_wild"`          // In CISA KEV (actively exploited)
	Sources     []string   `json:"sources"`              // Which data sources contributed
}

CVE represents a normalized vulnerability from any source.

type CallSite

type CallSite struct {
	File     string `json:"file"`
	Line     int    `json:"line"`
	Function string `json:"function"` // The function being called
	Snippet  string `json:"snippet"`  // The line of code
}

CallSite is a location in code where a vulnerable function is called.

type ExploitDBClient

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

ExploitDBClient checks if a public exploit (PoC) exists for a CVE. Uses the ExploitDB website search since there's no official API. An alternative is to check GitHub for PoCs via the GitHub search API.

func NewExploitDBClient

func NewExploitDBClient() *ExploitDBClient

func (*ExploitDBClient) HasExploit

func (c *ExploitDBClient) HasExploit(ctx context.Context, cveID string) (bool, error)

HasExploit checks if ExploitDB has a PoC for this CVE. Uses a simple HTTP check against the ExploitDB search.

type Finding

type Finding struct {
	CVE          CVE         `json:"cve"`
	MatchedDep   MatchedDep  `json:"matched_dep"`             // Which dependency matched
	Reachable    bool        `json:"reachable"`               // Is the vulnerable function called?
	CallSites    []CallSite  `json:"call_sites,omitempty"`    // Where it's called
	TaintedInput bool        `json:"tainted_input"`           // Does user input reach it?
	InputSource  string      `json:"input_source,omitempty"`  // e.g. "HTTP POST body"
	Exposed      bool        `json:"exposed"`                 // Is it on a public endpoint?
	ExposurePath string      `json:"exposure_path,omitempty"` // e.g. "POST /api/import"
	Verdict      VerdictType `json:"verdict"`
	Fix          string      `json:"fix,omitempty"` // Remediation command
	FixBreaking  bool        `json:"fix_breaking"`  // Does the fix have breaking changes?
}

Finding represents a CVE matched against a specific project context.

type GHSAClient

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

GHSAClient queries the GitHub Advisory Database. Best source for ecosystem-specific version ranges (npm, pip, Maven, etc.). Rate limits: 60/hr without token, 5000/hr with GITHUB_TOKEN.

func NewGHSAClient

func NewGHSAClient(token string) *GHSAClient

func (*GHSAClient) LookupByCVE

func (c *GHSAClient) LookupByCVE(ctx context.Context, cveID string) (*CVE, error)

LookupByCVE searches GHSA for a specific CVE ID.

func (*GHSAClient) LookupByGHSA

func (c *GHSAClient) LookupByGHSA(ctx context.Context, ghsaID string) (*CVE, error)

LookupByGHSA fetches a single GHSA advisory by its ID (e.g., "GHSA-xxxx-xxxx-xxxx").

func (*GHSAClient) QueryByPackage

func (c *GHSAClient) QueryByPackage(ctx context.Context, ecosystem, pkg string) ([]CVE, error)

QueryByPackage searches GHSA for vulnerabilities in a specific package.

type KEVClient

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

KEVClient checks the CISA Known Exploited Vulnerabilities catalog. If a CVE is in this list, it's confirmed actively exploited in the wild.

func NewKEVClient

func NewKEVClient() *KEVClient

func (*KEVClient) IsExploited

func (c *KEVClient) IsExploited(ctx context.Context, cveID string) (bool, error)

IsExploited checks if a CVE is in the CISA KEV catalog.

type MatchedDep

type MatchedDep struct {
	Name       string `json:"name"`             // e.g. "lxml"
	Version    string `json:"version"`          // e.g. "4.9.1"
	Ecosystem  string `json:"ecosystem"`        // e.g. "PyPI"
	LockFile   string `json:"lock_file"`        // e.g. "requirements.txt"
	Transitive bool   `json:"transitive"`       // Is it a transitive (indirect) dependency?
	Parent     string `json:"parent,omitempty"` // If transitive, who depends on it?
}

MatchedDep is a dependency that matched a CVE's affected range.

type NVDClient

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

NVDClient queries the NVD (National Vulnerability Database) API v2.0. NVD is the authoritative source for CVSS scores and CPE matching. Rate limits: 5 req/30s without API key, 50 req/30s with API key.

func NewNVDClient

func NewNVDClient(apiKey string) *NVDClient

func (*NVDClient) LookupByID

func (c *NVDClient) LookupByID(ctx context.Context, cveID string) (*CVE, error)

LookupByID fetches CVE details from NVD by CVE ID.

func (*NVDClient) QueryByCPE

func (c *NVDClient) QueryByCPE(ctx context.Context, cpe string) ([]CVE, error)

QueryByCPE queries NVD for CVEs matching a CPE 2.3 string. Used for matching network service versions against known vulnerabilities.

func (*NVDClient) QueryRecent

func (c *NVDClient) QueryRecent(ctx context.Context, since time.Time) ([]CVE, error)

QueryRecent fetches CVEs published since a given date.

type OSVClient

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

OSVClient queries the OSV (Open Source Vulnerabilities) database. OSV is the best source for package-level vulnerability data because it uses ecosystem-native version ranges (not CPE matching like NVD).

func NewOSVClient

func NewOSVClient() *OSVClient

func (*OSVClient) LookupByID

func (c *OSVClient) LookupByID(ctx context.Context, id string) (*CVE, error)

LookupByID fetches a specific vulnerability by its OSV or CVE ID.

func (*OSVClient) QueryBatch

func (c *OSVClient) QueryBatch(ctx context.Context, queries []osvQueryRequest) ([][]CVE, error)

QueryBatch queries OSV for multiple packages at once (up to 1000). This is significantly faster than individual queries for large dependency lists.

func (*OSVClient) QueryByPackage

func (c *OSVClient) QueryByPackage(ctx context.Context, ecosystem, pkg, version string) ([]CVE, error)

QueryByPackage queries OSV for vulnerabilities affecting a specific package+version.

type OfflineDB

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

OfflineDB provides CVE lookups from a locally downloaded OSV database. This enables fully offline scanning without API calls.

func NewOfflineDB

func NewOfflineDB(dbDir string) (*OfflineDB, error)

NewOfflineDB loads a previously downloaded offline database.

func (*OfflineDB) EcosystemCount

func (db *OfflineDB) EcosystemCount() int

EcosystemCount returns the number of loaded ecosystems.

func (*OfflineDB) LookupByID

func (db *OfflineDB) LookupByID(id string) *CVE

LookupByID finds a vulnerability by ID.

func (*OfflineDB) QueryPackage

func (db *OfflineDB) QueryPackage(ecosystem, pkg, version string) []CVE

QueryPackage finds all CVEs affecting a specific package+version from the offline DB.

func (*OfflineDB) VulnCount

func (db *OfflineDB) VulnCount() int

VulnCount returns the total number of vulnerabilities loaded.

type ScanResult

type ScanResult struct {
	Target      string    `json:"target"`
	ScannedAt   time.Time `json:"scanned_at"`
	Duration    string    `json:"duration"`
	TotalDeps   int       `json:"total_deps"`
	Ecosystems  []string  `json:"ecosystems"`
	Findings    []Finding `json:"findings"`
	Exploitable int       `json:"exploitable"`
	Reachable   int       `json:"reachable"`
	Noise       int       `json:"noise"`
}

ScanResult holds the complete output of a scan.

type VerdictType

type VerdictType string

VerdictType classifies the exploitability of a finding.

const (
	VerdictExploitable VerdictType = "EXPLOITABLE" // Reachable + tainted input + exposed
	VerdictReachable   VerdictType = "REACHABLE"   // Code calls it, but can't prove exploitability
	VerdictNoise       VerdictType = "NOISE"       // Present but not reachable
)

type VersionRange

type VersionRange struct {
	Type         string `json:"type"`                 // "SEMVER", "ECOSYSTEM", "GIT"
	Introduced   string `json:"introduced,omitempty"` // First affected version
	Fixed        string `json:"fixed,omitempty"`      // First fixed version
	LastAffected string `json:"last_affected,omitempty"`
}

VersionRange describes a range of affected versions.

Jump to

Keyboard shortcuts

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