Files
pruefwerk/compliance-core/src/models/cve.rs
T
Sharang ParnerkarandClaude Opus 5.5 3a07768024
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 11m16s
fix(vex): keep the alert's purl for components that left the SBOM
A resolved CVE alert (its component updated past the fix) was exported
as pkg:generic/<name>@<version> in OpenVEX, CycloneDX VEX, the CSAF VEX
draft and the evidence pack, because the exporters looked the purl up in
the current SBOM. CveAlert now stores the purl of its component (OSV,
NVD/CPE incl. CODESYS and embedded, CSAF matching), a rescan backfills it
on stored alerts (scan upsert and the hourly CVE monitor), and the
exporters use it before the SBOM lookup and the generic fallback.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
2026-10-08 23:21:51 +02:00

186 lines
6.8 KiB
Rust

use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "lowercase")]
pub enum CveSource {
Osv,
Nvd,
SearXNG,
/// A vendor's CSAF advisory (CERT@VDE, Siemens ProductCERT, CISA; #515).
Csaf,
}
/// A vendor advisory that names a CVE alert's component (#515).
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct AdvisoryRef {
/// The provider's key in the advisory index (`codesys`, `siemens`).
pub provider: String,
/// The advisory's id (`VDE-2026-094`, `SSA-019113`).
pub id: String,
pub title: String,
/// The advisory's page; Siemens' terms ask every use to link it.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub url: Option<String>,
/// What the vendor recommends for the component (`vendor_fix: Update to
/// version 3.5.22.40.`).
#[serde(default, skip_serializing_if = "Option::is_none")]
pub remediation: Option<String>,
}
/// What is known about the exploitation of one CVE (#493), from public
/// sources: CISA's Known Exploited Vulnerabilities catalog, FIRST's EPSS and
/// CISA's Vulnrichment SSVC decision points.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Exploitation {
/// The CVE's entry in CISA's KEV catalog: exploited in the wild.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub kev: Option<KevEntry>,
/// FIRST's EPSS: the probability of exploitation in the next 30 days.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub epss: Option<EpssScore>,
/// The SSVC "Exploitation" decision point CISA's Vulnrichment gives the
/// CVE: `none`, `poc` or `active`.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub ssvc_exploitation: Option<String>,
}
impl Exploitation {
/// Whether the CVE is known to be exploited: listed in KEV, or SSVC
/// exploitation `active`.
pub fn actively_exploited(&self) -> bool {
self.kev.is_some() || self.ssvc_exploitation.as_deref() == Some("active")
}
/// Whether nothing is known.
pub fn is_empty(&self) -> bool {
self.kev.is_none() && self.epss.is_none() && self.ssvc_exploitation.is_none()
}
}
/// A CVE's entry in CISA's Known Exploited Vulnerabilities catalog.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct KevEntry {
/// When CISA added it (`2021-12-10`).
pub date_added: String,
/// Whether it is known to be used in ransomware campaigns (KEV's
/// `knownRansomwareCampaignUse` is `Known`).
#[serde(default)]
pub known_ransomware: bool,
}
/// A CVE's EPSS score.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct EpssScore {
/// Probability of exploitation activity in the next 30 days, 0 to 1.
pub score: f64,
/// Share of all scored CVEs with a lower or equal score, 0 to 1.
pub percentile: f64,
/// The day the score is for (`2026-10-05`).
#[serde(default)]
pub date: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct CveAlert {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
pub id: Option<bson::oid::ObjectId>,
pub cve_id: String,
pub repo_id: String,
pub affected_package: String,
pub affected_version: String,
/// The purl of the SBOM component the alert is about, kept so that the
/// VEX exports still name it once the component has left the SBOM (a
/// `fixed` statement after an update); `None` for a component without a
/// purl and for alerts stored before it was recorded.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub purl: Option<String>,
pub source: CveSource,
pub severity: Option<String>,
pub cvss_score: Option<f64>,
pub summary: Option<String>,
pub llm_impact_summary: Option<String>,
pub references: Vec<String>,
/// Other ids of the same advisory (a GHSA's `CVE-…`).
#[serde(default)]
pub aliases: Vec<String>,
/// The versions of the affected package that fix it, when the advisory
/// names them.
#[serde(default)]
pub fixed_versions: Vec<String>,
/// Whether and how likely the CVE is exploited (CISA KEV, FIRST EPSS,
/// CISA Vulnrichment SSVC); `None` when it was not looked up.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub exploitation: Option<Exploitation>,
/// The vendor advisories that name it (#515).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub advisories: Vec<AdvisoryRef>,
/// The VEX statement on it (#498); none until someone states one.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub vex: Option<super::vex::VexAssessment>,
/// When a complete scan last found it gone (the component removed or
/// past a fixed version); `None` while it is reported.
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "super::serde_helpers::opt_bson_datetime"
)]
pub resolved_at: Option<DateTime<Utc>>,
/// When a scan first found it actively exploited (CISA KEV, SSVC
/// `active`): when the manufacturer could become aware of it, from which
/// the CRA's reporting deadlines run (Article 14(2); #498). Set once.
#[serde(
default,
skip_serializing_if = "Option::is_none",
with = "super::serde_helpers::opt_bson_datetime"
)]
pub exploited_seen_at: Option<DateTime<Utc>>,
#[serde(with = "super::serde_helpers::bson_datetime")]
pub created_at: DateTime<Utc>,
}
impl CveAlert {
/// The CVE id of the advisory: its own id, or a `CVE-` alias of a GHSA
/// or ecosystem advisory; otherwise its own id.
pub fn cve(&self) -> &str {
if self.cve_id.starts_with("CVE-") {
return &self.cve_id;
}
self.aliases
.iter()
.find(|a| a.starts_with("CVE-"))
.map_or(self.cve_id.as_str(), String::as_str)
}
pub fn new(
cve_id: String,
repo_id: String,
affected_package: String,
affected_version: String,
source: CveSource,
) -> Self {
Self {
id: None,
cve_id,
repo_id,
affected_package,
affected_version,
purl: None,
source,
severity: None,
cvss_score: None,
summary: None,
llm_impact_summary: None,
references: Vec::new(),
aliases: Vec::new(),
fixed_versions: Vec::new(),
exploitation: None,
advisories: Vec::new(),
vex: None,
resolved_at: None,
exploited_seen_at: None,
created_at: Utc::now(),
}
}
}