From 2c71385989811ce68694a068bcde9c9fac623761 Mon Sep 17 00:00:00 2001 From: Sharang Parnerkar <30073382+mighty840@users.noreply.github.com> Date: Tue, 10 Nov 2026 12:13:32 +0100 Subject: [PATCH] feat(dashboard): CVEs by severity and VEX status as a clickable grid (#957) The target's "Schwachstellen und VEX" card now opens with a grid of severity rows against VEX-status columns (offen, in Pruefung, betroffen, nicht betroffen, behoben), each count shaded on one blue scale and a button into the CVE list narrowed to that cell. The choice sits in the URL (?cve_severity=high&cve_vex=open), with a breadcrumb and a way back; a table toggle shows the same numbers, and a tile counts the CVEs nobody has assessed yet. The agent counts the still-reported alerts in GET /api/v1/targets/{id}/cve-matrix; the bucketing lives in compliance-core so the dashboard narrows the list the same way. Co-Authored-By: Claude Opus 5.5 --- .../src/api/handlers/cve_matrix.rs | 114 +++++ compliance-agent/src/api/handlers/mod.rs | 1 + compliance-agent/src/api/routes.rs | 4 + compliance-core/src/cve_matrix.rs | 442 ++++++++++++++++++ compliance-core/src/lib.rs | 1 + compliance-dashboard/assets/main.css | 212 +++++++++ compliance-dashboard/src/app.rs | 60 ++- .../src/components/cve_matrix.rs | 418 +++++++++++++++++ compliance-dashboard/src/components/mod.rs | 1 + .../src/components/vex_panel.rs | 19 +- compliance-dashboard/src/i18n/texts.rs | 132 ++++++ .../src/infrastructure/cve_matrix.rs | 30 ++ .../src/infrastructure/mod.rs | 1 + compliance-dashboard/src/pages/compliance.rs | 2 +- .../src/pages/graph_explorer.rs | 2 +- compliance-dashboard/src/pages/target.rs | 8 +- compliance-dashboard/src/pages/targets.rs | 4 +- docs/guide/sbom.md | 2 + 18 files changed, 1442 insertions(+), 11 deletions(-) create mode 100644 compliance-agent/src/api/handlers/cve_matrix.rs create mode 100644 compliance-core/src/cve_matrix.rs create mode 100644 compliance-dashboard/src/components/cve_matrix.rs create mode 100644 compliance-dashboard/src/infrastructure/cve_matrix.rs diff --git a/compliance-agent/src/api/handlers/cve_matrix.rs b/compliance-agent/src/api/handlers/cve_matrix.rs new file mode 100644 index 0000000..4c8b013 --- /dev/null +++ b/compliance-agent/src/api/handlers/cve_matrix.rs @@ -0,0 +1,114 @@ +//! A target's CVE alerts counted by severity and VEX status (#957), for the +//! grid the dashboard's "CVEs & VEX" view opens with. + +use axum::extract::{Extension, Path}; +use axum::http::StatusCode; +use axum::Json; +use mongodb::bson::{doc, Document}; +use serde::Deserialize; + +use compliance_core::cve_matrix::{CveCell, CveMatrix}; +use compliance_core::models::VexStatus; +use compliance_core::tenant_ctx::TenantCtx; + +use super::dto::{collect_cursor_async, tenant_db, AgentExt, ApiResponse, ApiResult}; + +/// The fields of a stored alert the grid reads. +#[derive(Debug, Deserialize)] +struct MatrixRow { + #[serde(default)] + severity: Option, + #[serde(default)] + cvss_score: Option, + #[serde(default)] + vex: Option, +} + +/// The status of an alert's VEX statement; the rest of it is not read. +#[derive(Debug, Deserialize)] +struct MatrixVex { + status: VexStatus, +} + +impl MatrixRow { + fn cell(&self) -> CveCell { + CveCell::of( + self.severity.as_deref(), + self.cvss_score, + self.vex.as_ref().map(|v| v.status), + ) + } +} + +/// The alerts of target `id` the grid counts: still reported, as in +/// [`compliance_core::cve_matrix::counts`]. `null` matches a missing +/// `resolved_at` and one stored as `null`. +fn still_reported(id: &str) -> Document { + doc! { "repo_id": id, "resolved_at": null } +} + +/// GET /api/v1/targets/{id}/cve-matrix — the target's still-reported CVE +/// alerts counted per severity and VEX status. Scoped to the requester's +/// tenant like `GET /api/v1/targets/{id}/cves`; the org-role middleware +/// lets every reading role in. +/// +/// # Errors +/// +/// 500 when the tenant's database or the alerts cannot be read. +#[tracing::instrument(skip_all, fields(target_id = %id))] +pub async fn target_cve_matrix( + Extension(agent): AgentExt, + tenant: TenantCtx, + Path(id): Path, +) -> ApiResult { + let db = tenant_db(&agent, &tenant).await?; + // Only the three fields the bucketing reads, not the summaries and + // references of every alert. A row that does not decode is skipped with + // a warning, as the CVE list skips it. + let cursor = db + .cve_alerts() + .clone_with_type::() + .find(still_reported(&id)) + .projection(doc! { "_id": 0, "severity": 1, "cvss_score": 1, "vex.status": 1 }) + .await + .map_err(|e| { + tracing::warn!("CVE matrix not read: {e}"); + StatusCode::INTERNAL_SERVER_ERROR + })?; + let rows: Vec = collect_cursor_async(cursor).await; + let matrix = CveMatrix::from_cells(rows.iter().map(MatrixRow::cell)); + Ok(Json(ApiResponse { + total: Some(matrix.total()), + data: matrix, + page: None, + })) +} + +#[cfg(test)] +mod tests { + use super::*; + use compliance_core::cve_matrix::{CveSeverity, VexColumn}; + + #[test] + fn only_alerts_still_reported_are_read() { + let filter = still_reported("t1"); + assert_eq!(filter.get_str("repo_id").ok(), Some("t1")); + assert_eq!(filter.get("resolved_at"), Some(&mongodb::bson::Bson::Null)); + } + + #[test] + fn a_projected_row_is_bucketed_like_the_alert() { + let row: MatrixRow = mongodb::bson::from_document(doc! { + "severity": "MODERATE", + "vex": { "status": "not_affected" }, + }) + .expect("a projected alert"); + let cell = row.cell(); + assert_eq!(cell.severity, CveSeverity::Medium); + assert_eq!(cell.vex, VexColumn::NotAffected); + + let bare: MatrixRow = mongodb::bson::from_document(doc! { "severity": null }) + .expect("an alert without severity or statement"); + assert_eq!(bare.cell(), CveCell::of(None, None, None)); + } +} diff --git a/compliance-agent/src/api/handlers/mod.rs b/compliance-agent/src/api/handlers/mod.rs index 41a7d5d..2068e76 100644 --- a/compliance-agent/src/api/handlers/mod.rs +++ b/compliance-agent/src/api/handlers/mod.rs @@ -1,5 +1,6 @@ pub mod admin; pub mod chat; +pub mod cve_matrix; pub mod dast; pub mod demo_seed; pub mod dto; diff --git a/compliance-agent/src/api/routes.rs b/compliance-agent/src/api/routes.rs index e066373..b5fb37f 100644 --- a/compliance-agent/src/api/routes.rs +++ b/compliance-agent/src/api/routes.rs @@ -112,6 +112,10 @@ pub fn build_router() -> Router { "/api/v1/targets/{id}/cves", get(handlers::vex::list_target_cves), ) + .route( + "/api/v1/targets/{id}/cve-matrix", + get(handlers::cve_matrix::target_cve_matrix), + ) .route("/api/v1/targets/{id}/vex", get(handlers::vex::export_vex)) .route("/api/v1/targets/{id}/csaf", get(handlers::vex::export_csaf)) .route("/api/v1/targets/{id}/enisa", get(handlers::vex::list_enisa)) diff --git a/compliance-core/src/cve_matrix.rs b/compliance-core/src/cve_matrix.rs new file mode 100644 index 0000000..8528046 --- /dev/null +++ b/compliance-core/src/cve_matrix.rs @@ -0,0 +1,442 @@ +//! A target's CVE alerts counted by severity and VEX status (#957): the grid +//! the dashboard's "CVEs & VEX" view opens with, and the filter its cells +//! narrow the CVE list to. +//! +//! The agent counts with [`CveCell::of`] and the dashboard filters the list +//! with [`CveFilter::matches`], which buckets the same way, so a cell's +//! number and the length of the list it opens cannot drift apart. Only +//! alerts that are still reported count ([`counts`]): one a complete scan no +//! longer found (`resolved_at` set) has left the grid. + +use serde::{Deserialize, Serialize}; + +use crate::models::{CveAlert, VexStatus}; + +/// A row of the grid: the advisory's severity, or `Unknown` when it names +/// none. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum CveSeverity { + Critical, + High, + Medium, + Low, + Unknown, +} + +impl CveSeverity { + /// Every row, top to bottom. + pub const ALL: [Self; 5] = [ + Self::Critical, + Self::High, + Self::Medium, + Self::Low, + Self::Unknown, + ]; + + /// The row of an alert rated `severity` by its advisory (`CRITICAL`, + /// `MODERATE`, `low`; case does not matter), else by its CVSS base score + /// `cvss`, else `Unknown`. + /// + /// The advisory's word comes first because it is what the CVE list shows + /// as the alert's badge; the score only fills in when the word is + /// missing or not one of the four. + pub fn of(severity: Option<&str>, cvss: Option) -> Self { + let word = severity.map(|s| s.trim().to_ascii_lowercase()); + match word.as_deref() { + Some("critical") => return Self::Critical, + Some("high") => return Self::High, + Some("medium" | "moderate") => return Self::Medium, + Some("low") => return Self::Low, + _ => {} + } + // Guards rather than range patterns on the `f64`, so that a `NaN` + // score falls through to `Low` like every other score below 4. + match cvss { + Some(score) if score >= 9.0 => Self::Critical, + Some(score) if score >= 7.0 => Self::High, + Some(score) if score >= 4.0 => Self::Medium, + Some(_) => Self::Low, + None => Self::Unknown, + } + } + + /// The row's name on the wire and in the dashboard's URL (`high`). + pub const fn as_str(self) -> &'static str { + match self { + Self::Critical => "critical", + Self::High => "high", + Self::Medium => "medium", + Self::Low => "low", + Self::Unknown => "unknown", + } + } + + /// The row named `name` by [`Self::as_str`]. + pub fn parse(name: &str) -> Option { + Self::ALL.into_iter().find(|s| s.as_str() == name) + } + + /// The row's index in [`Self::ALL`]. + const fn index(self) -> usize { + self as usize + } +} + +/// A column of the grid: the alert's VEX statement, or `Open` while nobody +/// (and no scan) has stated one. +/// +/// Unlike [`crate::vex_docs::status_of`], which exports an alert without a +/// statement as `under_investigation`, the grid tells the two apart: "open" +/// is not looked at yet, "under investigation" is being looked at. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +#[serde(rename_all = "snake_case")] +pub enum VexColumn { + Open, + UnderInvestigation, + Affected, + NotAffected, + Fixed, +} + +impl VexColumn { + /// Every column, left to right. + pub const ALL: [Self; 5] = [ + Self::Open, + Self::UnderInvestigation, + Self::Affected, + Self::NotAffected, + Self::Fixed, + ]; + + /// The column of an alert whose VEX statement has `status`, `None` + /// without one. + pub const fn of(status: Option) -> Self { + match status { + None => Self::Open, + Some(VexStatus::UnderInvestigation) => Self::UnderInvestigation, + Some(VexStatus::Affected) => Self::Affected, + Some(VexStatus::NotAffected) => Self::NotAffected, + Some(VexStatus::Fixed) => Self::Fixed, + } + } + + /// The column's name on the wire and in the dashboard's URL (`open`). + pub const fn as_str(self) -> &'static str { + match self { + Self::Open => "open", + Self::UnderInvestigation => "under_investigation", + Self::Affected => "affected", + Self::NotAffected => "not_affected", + Self::Fixed => "fixed", + } + } + + /// The column named `name` by [`Self::as_str`]. + pub fn parse(name: &str) -> Option { + Self::ALL.into_iter().find(|v| v.as_str() == name) + } + + /// The column's index in [`Self::ALL`]. + const fn index(self) -> usize { + self as usize + } +} + +/// The cell of the grid an alert is counted in. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)] +pub struct CveCell { + pub severity: CveSeverity, + pub vex: VexColumn, +} + +impl CveCell { + /// The cell of an alert rated `severity` / `cvss` with the VEX status + /// `vex` (see [`CveSeverity::of`] and [`VexColumn::of`]). + pub fn of(severity: Option<&str>, cvss: Option, vex: Option) -> Self { + Self { + severity: CveSeverity::of(severity, cvss), + vex: VexColumn::of(vex), + } + } + + /// The cell `alert` is counted in. + pub fn of_alert(alert: &CveAlert) -> Self { + Self::of( + alert.severity.as_deref(), + alert.cvss_score, + alert.vex.as_ref().map(|v| v.status), + ) + } +} + +/// Whether `alert` is counted in the grid: still reported by the scans. +pub fn counts(alert: &CveAlert) -> bool { + alert.resolved_at.is_none() +} + +/// One non-empty cell of a [`CveMatrix`]. +#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] +pub struct CveMatrixCell { + pub severity: CveSeverity, + pub vex: VexColumn, + pub count: u64, +} + +/// A target's still-reported CVE alerts counted per [`CveCell`]. Only the +/// non-empty cells are listed, rows top to bottom and columns left to right; +/// every other cell counts 0. +#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)] +pub struct CveMatrix { + pub cells: Vec, +} + +impl CveMatrix { + /// Count `cells`, one per alert. + /// + /// # Examples + /// + /// ``` + /// use compliance_core::cve_matrix::{CveCell, CveMatrix, CveSeverity, VexColumn}; + /// + /// let high_open = CveCell::of(Some("HIGH"), None, None); + /// let matrix = CveMatrix::from_cells([high_open, high_open]); + /// assert_eq!(matrix.count(CveSeverity::High, VexColumn::Open), 2); + /// ``` + pub fn from_cells(cells: impl IntoIterator) -> Self { + // A fixed 5 x 5 table: one pass, no hashing, and the output order + // falls out of the index order. + let mut table = [[0u64; VexColumn::ALL.len()]; CveSeverity::ALL.len()]; + for cell in cells { + table[cell.severity.index()][cell.vex.index()] += 1; + } + let cells = CveSeverity::ALL + .into_iter() + .flat_map(|severity| { + VexColumn::ALL.into_iter().map(move |vex| CveMatrixCell { + severity, + vex, + count: table[severity.index()][vex.index()], + }) + }) + .filter(|cell| cell.count > 0) + .collect(); + Self { cells } + } + + /// How many alerts are in the cell of `severity` and `vex`. + pub fn count(&self, severity: CveSeverity, vex: VexColumn) -> u64 { + self.cells + .iter() + .find(|c| c.severity == severity && c.vex == vex) + .map_or(0, |c| c.count) + } + + /// The largest count of a cell, 0 when there are none. + pub fn max(&self) -> u64 { + self.cells.iter().map(|c| c.count).max().unwrap_or(0) + } + + /// How many alerts are counted in all. + pub fn total(&self) -> u64 { + self.cells.iter().map(|c| c.count).sum() + } + + /// How many alerts nobody has assessed yet: the "open" column. + pub fn unassessed(&self) -> u64 { + self.cells + .iter() + .filter(|c| c.vex == VexColumn::Open) + .map(|c| c.count) + .sum() + } + + /// The rows the grid shows: the four severities, and "unknown" only + /// when an alert has no severity. + pub fn rows(&self) -> Vec { + let has_unknown = self + .cells + .iter() + .any(|c| c.severity == CveSeverity::Unknown); + CveSeverity::ALL + .into_iter() + .filter(|s| *s != CveSeverity::Unknown || has_unknown) + .collect() + } +} + +/// What a click in the grid narrows the CVE list to: a severity, a VEX +/// column, or both; `None` leaves that side open. Either way only alerts the +/// grid counts ([`counts`]) pass. +#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)] +pub struct CveFilter { + pub severity: Option, + pub vex: Option, +} + +impl CveFilter { + /// Whether `alert` is in the narrowed list. + pub fn matches(&self, alert: &CveAlert) -> bool { + if !counts(alert) { + return false; + } + let cell = CveCell::of_alert(alert); + self.severity.is_none_or(|s| s == cell.severity) && self.vex.is_none_or(|v| v == cell.vex) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::models::{CveSource, VexAssessment}; + + fn alert(severity: Option<&str>, cvss: Option, vex: Option) -> CveAlert { + CveAlert { + id: None, + cve_id: "CVE-2024-0001".to_string(), + repo_id: "t1".to_string(), + affected_package: "openssl".to_string(), + affected_version: "3.0.0".to_string(), + purl: None, + source: CveSource::Osv, + severity: severity.map(String::from), + cvss_score: cvss, + summary: None, + llm_impact_summary: None, + references: Vec::new(), + aliases: Vec::new(), + fixed_versions: Vec::new(), + exploitation: None, + advisories: Vec::new(), + vex: vex.map(|status| VexAssessment { + status, + justification: None, + impact_statement: None, + action_statement: None, + by: "u1".to_string(), + by_name: None, + at: chrono::Utc::now(), + by_scan: false, + }), + resolved_at: None, + exploited_seen_at: None, + created_at: chrono::Utc::now(), + } + } + + #[test] + fn the_advisory_word_picks_the_row_in_any_case() { + assert_eq!( + CveSeverity::of(Some("CRITICAL"), None), + CveSeverity::Critical + ); + assert_eq!(CveSeverity::of(Some("high"), None), CveSeverity::High); + assert_eq!(CveSeverity::of(Some("MODERATE"), None), CveSeverity::Medium); + assert_eq!(CveSeverity::of(Some(" Medium "), None), CveSeverity::Medium); + assert_eq!(CveSeverity::of(Some("low"), Some(9.8)), CveSeverity::Low); + } + + #[test] + fn the_cvss_score_fills_in_a_missing_or_odd_word() { + assert_eq!(CveSeverity::of(None, Some(9.0)), CveSeverity::Critical); + assert_eq!( + CveSeverity::of(Some("important"), Some(8.1)), + CveSeverity::High + ); + assert_eq!(CveSeverity::of(None, Some(4.0)), CveSeverity::Medium); + assert_eq!(CveSeverity::of(None, Some(3.9)), CveSeverity::Low); + } + + #[test] + fn without_word_or_score_the_severity_is_unknown() { + assert_eq!(CveSeverity::of(None, None), CveSeverity::Unknown); + assert_eq!(CveSeverity::of(Some("unrated"), None), CveSeverity::Unknown); + } + + #[test] + fn no_statement_is_open_and_each_status_has_its_column() { + assert_eq!(VexColumn::of(None), VexColumn::Open); + assert_eq!( + VexColumn::of(Some(VexStatus::UnderInvestigation)), + VexColumn::UnderInvestigation + ); + assert_eq!( + VexColumn::of(Some(VexStatus::Affected)), + VexColumn::Affected + ); + assert_eq!( + VexColumn::of(Some(VexStatus::NotAffected)), + VexColumn::NotAffected + ); + assert_eq!(VexColumn::of(Some(VexStatus::Fixed)), VexColumn::Fixed); + } + + #[test] + fn names_round_trip_and_match_the_wire() { + for severity in CveSeverity::ALL { + assert_eq!(CveSeverity::parse(severity.as_str()), Some(severity)); + assert_eq!( + serde_json::to_value(severity).ok(), + Some(serde_json::Value::from(severity.as_str())) + ); + } + for vex in VexColumn::ALL { + assert_eq!(VexColumn::parse(vex.as_str()), Some(vex)); + assert_eq!( + serde_json::to_value(vex).ok(), + Some(serde_json::Value::from(vex.as_str())) + ); + } + assert_eq!(CveSeverity::parse("hoch"), None); + assert_eq!(VexColumn::parse(""), None); + } + + #[test] + fn the_matrix_counts_each_cell_and_lists_only_non_empty_ones() { + let high_open = CveCell::of(Some("HIGH"), None, None); + let low_fixed = CveCell::of(Some("LOW"), None, Some(VexStatus::Fixed)); + let matrix = CveMatrix::from_cells([high_open, low_fixed, high_open]); + assert_eq!(matrix.cells.len(), 2); + assert_eq!(matrix.cells[0].severity, CveSeverity::High); + assert_eq!(matrix.count(CveSeverity::High, VexColumn::Open), 2); + assert_eq!(matrix.count(CveSeverity::Low, VexColumn::Fixed), 1); + assert_eq!(matrix.count(CveSeverity::Critical, VexColumn::Open), 0); + assert_eq!( + (matrix.max(), matrix.total(), matrix.unassessed()), + (2, 3, 2) + ); + } + + #[test] + fn the_unknown_row_shows_only_when_an_alert_has_no_severity() { + let rated = CveMatrix::from_cells([CveCell::of(Some("high"), None, None)]); + assert_eq!(rated.rows().len(), 4); + let unrated = CveMatrix::from_cells([CveCell::of(None, None, None)]); + assert_eq!(unrated.rows().last(), Some(&CveSeverity::Unknown)); + assert_eq!(CveMatrix::default().rows().len(), 4); + } + + #[test] + fn the_filter_passes_its_cell_and_never_a_resolved_alert() { + let high_open = alert(Some("HIGH"), None, None); + let high_affected = alert(Some("HIGH"), None, Some(VexStatus::Affected)); + let mut resolved = high_open.clone(); + resolved.resolved_at = Some(chrono::Utc::now()); + + let cell = CveFilter { + severity: Some(CveSeverity::High), + vex: Some(VexColumn::Open), + }; + assert!(cell.matches(&high_open)); + assert!(!cell.matches(&high_affected)); + assert!(!cell.matches(&resolved)); + + let all_open = CveFilter { + severity: None, + vex: Some(VexColumn::Open), + }; + assert!(all_open.matches(&high_open)); + assert!(CveFilter::default().matches(&high_affected)); + assert!(!CveFilter::default().matches(&resolved)); + } +} diff --git a/compliance-core/src/lib.rs b/compliance-core/src/lib.rs index 4f706f6..f858120 100644 --- a/compliance-core/src/lib.rs +++ b/compliance-core/src/lib.rs @@ -4,6 +4,7 @@ pub mod control_check; pub mod csaf_docs; pub mod csaf_ingest; pub mod cve_groups; +pub mod cve_matrix; pub mod db; pub mod encoding; pub mod enisa_docs; diff --git a/compliance-dashboard/assets/main.css b/compliance-dashboard/assets/main.css index ba703e7..2957b3b 100644 --- a/compliance-dashboard/assets/main.css +++ b/compliance-dashboard/assets/main.css @@ -6251,3 +6251,215 @@ input[type="file"] { .co-back { margin-left: auto; } + +/* ── CVEs & VEX grid (#957) ── + Severity rows against VEX-status columns, each count shaded on one blue + scale, light to dark; the darkest two carry white ink. In dark mode the + scale runs from the surface up to light blue instead, ink flipped. */ +:root { + --cve-shade-0: var(--bg-primary); + --cve-shade-1: #CDE2FB; + --cve-shade-2: #9EC5F4; + --cve-shade-3: #5598E7; + --cve-shade-4: #256ABF; + --cve-shade-5: #104281; + --cve-ink-0: var(--text-faint); + --cve-ink-low: #14162B; + --cve-ink-high: #FFFFFF; +} + +:root[data-theme="dark"] { + --cve-shade-0: var(--bg-elevated); + --cve-shade-1: #13315C; + --cve-shade-2: #174A8A; + --cve-shade-3: #256ABF; + --cve-shade-4: #5598E7; + --cve-shade-5: #9EC5F4; + --cve-ink-low: #FFFFFF; + --cve-ink-high: #0F1225; +} + +@media (prefers-color-scheme: dark) { + :root:not([data-theme="light"]) { + --cve-shade-0: var(--bg-elevated); + --cve-shade-1: #13315C; + --cve-shade-2: #174A8A; + --cve-shade-3: #256ABF; + --cve-shade-4: #5598E7; + --cve-shade-5: #9EC5F4; + --cve-ink-low: #FFFFFF; + --cve-ink-high: #0F1225; + } +} + +.cve-matrix-head { + display: flex; + flex-wrap: wrap; + gap: 12px; + align-items: flex-start; + justify-content: space-between; + margin-bottom: 12px; +} + +.cve-matrix-head p { + flex: 1 1 320px; +} + +.cve-view-toggle { + display: inline-flex; + gap: 4px; +} + +.cve-view-toggle [aria-pressed="true"] { + border-color: var(--border-accent); + background: var(--accent-muted); + color: var(--accent); +} + +.cve-grid-wrap { + overflow-x: auto; +} + +.cve-grid { + display: grid; + grid-template-columns: minmax(72px, auto) repeat(5, minmax(56px, 1fr)); + gap: 2px; + min-width: 360px; +} + +.cve-grid-col, +.cve-grid-row { + font-size: 12px; + color: var(--text-secondary); +} + +.cve-grid-col { + align-self: end; + padding: 0 4px 6px; + text-align: center; +} + +.cve-grid-row { + align-self: center; + padding-right: 10px; +} + +.cve-cell { + min-height: 40px; + border: none; + border-radius: 4px; + font-family: var(--font-mono); + font-size: 14px; + font-variant-numeric: tabular-nums; + cursor: pointer; + transition: box-shadow 0.15s var(--ease-out); +} + +.cve-cell:hover:not(:disabled) { + box-shadow: inset 0 0 0 2px var(--accent); +} + +.cve-cell:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 1px; +} + +.cve-cell:disabled { + cursor: default; +} + +.cve-shade-0 { background: var(--cve-shade-0); color: var(--cve-ink-0); } +.cve-shade-1 { background: var(--cve-shade-1); color: var(--cve-ink-low); } +.cve-shade-2 { background: var(--cve-shade-2); color: var(--cve-ink-low); } +.cve-shade-3 { background: var(--cve-shade-3); color: var(--cve-ink-low); } +.cve-shade-4 { background: var(--cve-shade-4); color: var(--cve-ink-high); } +.cve-shade-5 { background: var(--cve-shade-5); color: var(--cve-ink-high); } + +.cve-scale { + display: flex; + align-items: center; + justify-content: flex-end; + gap: 2px; + margin-top: 8px; + font-size: 11.5px; + color: var(--text-tertiary); +} + +.cve-scale span:first-child { + margin-right: 6px; +} + +.cve-scale span:last-child { + margin-left: 6px; +} + +.cve-scale-step { + width: 18px; + height: 10px; + border-radius: 2px; +} + +.cve-matrix-foot { + display: flex; + flex-wrap: wrap; + gap: 10px; + align-items: center; + justify-content: space-between; + margin-top: 14px; +} + +.cve-unassessed { + display: inline-flex; + align-items: baseline; + gap: 6px; + padding: 8px 12px; + border: 1px solid var(--border-bright); + border-radius: var(--radius); + background: var(--bg-card); + color: var(--text-secondary); + font-family: var(--font-body); + font-size: 12.5px; + cursor: pointer; +} + +.cve-unassessed strong { + font-family: var(--font-mono); + font-size: 18px; + color: var(--text-primary); +} + +.cve-unassessed:hover:not(:disabled) { + border-color: var(--border-strong); + background: var(--bg-elevated); +} + +.cve-unassessed:disabled { + cursor: default; +} + +.cve-crumbs { + display: flex; + flex-wrap: wrap; + gap: 6px 12px; + align-items: center; + margin-bottom: 12px; + font-size: 12.5px; +} + +.cve-crumb-trail { + color: var(--text-secondary); +} + +.cve-crumb-trail a { + color: var(--accent); +} + +.cve-crumb-trail [aria-current="page"] { + color: var(--text-primary); + font-weight: 500; +} + +.cve-table td { + font-family: var(--font-mono); + font-variant-numeric: tabular-nums; +} diff --git a/compliance-dashboard/src/app.rs b/compliance-dashboard/src/app.rs index cbf6520..735580f 100644 --- a/compliance-dashboard/src/app.rs +++ b/compliance-dashboard/src/app.rs @@ -12,8 +12,11 @@ pub enum Route { OverviewPage {}, #[route("/targets")] TargetsPage {}, - #[route("/targets/:id")] - TargetPage { id: String }, + // `?cve_severity=high&cve_vex=open` opens the target's CVE list + // narrowed to that cell of the CVE grid (#957); `all` leaves a side + // open, neither shows the grid. + #[route("/targets/:id?:cve_severity&:cve_vex")] + TargetPage { id: String, cve_severity: Option, cve_vex: Option }, #[route("/targets/:id/compliance")] CompliancePage { id: String }, #[route("/onboard")] @@ -60,6 +63,17 @@ pub enum Route { McpTokensPage {}, } +impl Route { + /// The page of target `id`, its CVE grid shown (no CVE cell chosen). + pub fn target(id: String) -> Self { + Self::TargetPage { + id, + cve_severity: None, + cve_vex: None, + } + } +} + const MAIN_CSS: Asset = asset!("/assets/main.css"); const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css"); const VIS_NETWORK_JS: Asset = asset!("/assets/vis-network.min.js"); @@ -120,4 +134,46 @@ mod tests { if ecosystem == "cargo" && target == "665f" )); } + + #[test] + fn the_target_page_carries_the_cve_cell_in_the_query() { + let cell = Route::TargetPage { + id: "t1".to_string(), + cve_severity: Some("high".to_string()), + cve_vex: Some("open".to_string()), + }; + assert_eq!( + cell.to_string(), + "/targets/t1?cve_severity=high&cve_vex=open" + ); + assert_eq!(Route::from_str(&cell.to_string()).ok(), Some(cell)); + + let column = Route::TargetPage { + id: "t1".to_string(), + cve_severity: None, + cve_vex: Some("open".to_string()), + }; + assert_eq!(Route::from_str(&column.to_string()).ok(), Some(column)); + + // The router writes the `?` of a two-argument query even when both + // are absent; harmless, and it reads back as the grid. + assert_eq!(Route::target("t1".to_string()).to_string(), "/targets/t1?"); + assert_eq!( + Route::from_str("/targets/t1?").ok(), + Some(Route::target("t1".to_string())) + ); + + assert_eq!( + Route::from_str("/targets/t1").ok(), + Some(Route::TargetPage { + id: "t1".to_string(), + cve_severity: None, + cve_vex: None, + }) + ); + assert!(matches!( + Route::from_str("/targets/t1/compliance"), + Ok(Route::CompliancePage { id }) if id == "t1" + )); + } } diff --git a/compliance-dashboard/src/components/cve_matrix.rs b/compliance-dashboard/src/components/cve_matrix.rs new file mode 100644 index 0000000..5d67ba7 --- /dev/null +++ b/compliance-dashboard/src/components/cve_matrix.rs @@ -0,0 +1,418 @@ +//! The "CVEs & VEX" view on a target (#957): a grid of severity against VEX +//! status with a count per cell, shaded on one blue scale, and behind each +//! count the target's CVE list narrowed to that cell. The choice lives in +//! the page's URL (`?cve_severity=high&cve_vex=open`), so a narrowed list +//! can be linked and the browser's back button returns to the grid. + +use dioxus::prelude::*; +use dioxus_free_icons::icons::bs_icons::BsArrowLeft; +use dioxus_free_icons::Icon; + +use compliance_core::cve_matrix::{CveFilter, CveMatrix, CveSeverity, VexColumn}; + +use crate::app::Route; +use crate::components::vex_panel::VexPanel; +use crate::i18n::texts::{common, cve_matrix as tx, vex as vex_tx}; +use crate::i18n::{use_lang, Lang}; +use crate::infrastructure::cve_matrix::fetch_cve_matrix; + +/// The query value for "every severity and status": the whole list. +const ALL: &str = "all"; + +/// The steps of the blue scale above 0 (`.cve-shade-1` to `.cve-shade-5`). +const SHADES: u64 = 5; + +/// What the target page's CVE query asks for. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum Selection { + /// No CVE query: the grid. + Grid, + /// The list narrowed to a cell, row or column of the grid. + List(Option), +} + +/// The selection of the query values `severity` and `vex`. An absent or +/// unknown value leaves its side open; when both sides are open the list +/// is the whole one as it always was (resolved alerts included), `None`. +fn selection(severity: Option<&str>, vex: Option<&str>) -> Selection { + if severity.is_none() && vex.is_none() { + return Selection::Grid; + } + let filter = CveFilter { + severity: severity.and_then(CveSeverity::parse), + vex: vex.and_then(VexColumn::parse), + }; + Selection::List((filter != CveFilter::default()).then_some(filter)) +} + +/// The target page of `target_id` with its CVE list narrowed to `filter`, +/// or the whole list for `None`. +fn list_route(target_id: &str, filter: Option) -> Route { + let filter = filter.unwrap_or_default(); + let severity = filter.severity.map(|s| s.as_str().to_string()); + // Neither side named would mean the grid; `all` asks for the list. + let vex = filter + .vex + .map(VexColumn::as_str) + .or(severity.is_none().then_some(ALL)) + .map(String::from); + Route::TargetPage { + id: target_id.to_string(), + cve_severity: severity, + cve_vex: vex, + } +} + +/// The step of the blue scale for `count` in a grid whose largest cell is +/// `max`: 0 for an empty cell, else 1 to [`SHADES`] in proportion, rounded +/// up so that a single CVE is never shaded like none. +fn shade(count: u64, max: u64) -> u64 { + if count == 0 || max == 0 { + return 0; + } + // Integer ceiling of SHADES * count / max, no floats. + (SHADES * count).div_ceil(max).min(SHADES) +} + +/// What the breadcrumb names the selection: "hoch · offen", "offen", "alle". +fn crumb(filter: Option, lang: Lang) -> String { + let filter = filter.unwrap_or_default(); + let parts: Vec<&str> = [ + filter.severity.map(|s| tx::severity(s).get(lang)), + filter.vex.map(|v| tx::vex(v).get(lang)), + ] + .into_iter() + .flatten() + .collect(); + if parts.is_empty() { + tx::ALL.get(lang).to_string() + } else { + parts.join(" · ") + } +} + +/// What a cell says to a screen reader and on hover: "hoch, offen: 12". +fn cell_label(severity: CveSeverity, vex: VexColumn, count: u64, lang: Lang) -> String { + format!( + "{}, {}: {count}", + tx::severity(severity).get(lang), + tx::vex(vex).get(lang) + ) +} + +/// The "Schwachstellen und VEX" card body of target `target_id`: the grid, +/// or the CVE list narrowed to the cell the query `cve_severity` / +/// `cve_vex` names. +#[component] +pub fn CveView( + target_id: String, + cve_severity: Option, + cve_vex: Option, +) -> Element { + let lang = use_lang()(); + match selection(cve_severity.as_deref(), cve_vex.as_deref()) { + Selection::Grid => rsx! { CveGrid { target_id } }, + Selection::List(filter) => rsx! { + nav { class: "cve-crumbs", "aria-label": tx::CVES.get(lang), + Link { class: "btn btn-ghost btn-back", to: Route::target(target_id.clone()), + Icon { icon: BsArrowLeft, width: 16, height: 16 } + {tx::BACK.get(lang)} + } + span { class: "cve-crumb-trail", + Link { to: Route::target(target_id.clone()), {tx::CVES.get(lang)} } + span { "aria-hidden": "true", " › " } + span { "aria-current": "page", "{crumb(filter, lang)}" } + } + } + VexPanel { target_id, filter } + }, + } +} + +/// The grid (or, toggled, the table) of target `target_id`'s counts. Mounted +/// afresh on every return from the list, so statements made there show. +#[component] +fn CveGrid(target_id: String) -> Element { + let lang = use_lang()(); + let navigator = use_navigator(); + let id_for_load = target_id.clone(); + let matrix = use_resource(move || { + let id = id_for_load.clone(); + async move { fetch_cve_matrix(id).await.ok() } + }); + let mut as_table = use_signal(|| false); + + let guard = matrix.read(); + let matrix = match &*guard { + None => return rsx! { div { class: "loading", {common::LOADING.get(lang)} } }, + Some(None) => return rsx! { p { class: "target-muted", {vex_tx::LOAD_FAILED.get(lang)} } }, + Some(Some(m)) => m, + }; + let unassessed = matrix.unassessed(); + let open_route = list_route( + &target_id, + Some(CveFilter { + severity: None, + vex: Some(VexColumn::Open), + }), + ); + let all_route = list_route(&target_id, None); + + rsx! { + div { class: "cve-matrix-head", + p { class: "target-muted", {tx::HINT.get(lang)} } + if matrix.total() > 0 { + div { class: "cve-view-toggle", role: "group", "aria-label": tx::VIEW.get(lang), + button { + class: "btn btn-sm", + "aria-pressed": "{!as_table()}", + onclick: move |_| as_table.set(false), + {tx::CHART.get(lang)} + } + button { + class: "btn btn-sm", + "aria-pressed": "{as_table()}", + onclick: move |_| as_table.set(true), + {tx::TABLE.get(lang)} + } + } + } + } + if matrix.total() == 0 { + p { class: "target-muted", {vex_tx::NONE.get(lang)} } + } else if as_table() { + CveTable { target_id: target_id.clone(), matrix: matrix.clone() } + } else { + CveChart { target_id: target_id.clone(), matrix: matrix.clone() } + } + div { class: "cve-matrix-foot", + if matrix.total() > 0 { + button { + class: "cve-unassessed", + disabled: unassessed == 0, + onclick: move |_| { navigator.push(open_route.clone()); }, + span { {tx::UNASSESSED.get(lang)} ": " } + strong { "{unassessed}" } + } + } + button { + class: "btn btn-ghost btn-sm", + onclick: move |_| { navigator.push(all_route.clone()); }, + {tx::LIST_AND_EXPORTS.get(lang)} + } + } + } +} + +/// The grid itself: a row per severity, a column per VEX status, each cell +/// a button into the narrowed list. +#[component] +fn CveChart(target_id: String, matrix: CveMatrix) -> Element { + let lang = use_lang()(); + let max = matrix.max(); + rsx! { + div { class: "cve-grid-wrap", + div { class: "cve-grid", + span {} + for vex in VexColumn::ALL { + span { class: "cve-grid-col", {tx::vex(vex).get(lang)} } + } + for severity in matrix.rows() { + span { class: "cve-grid-row", {tx::severity(severity).get(lang)} } + for vex in VexColumn::ALL { + CveCellButton { + target_id: target_id.clone(), + severity, + vex, + count: matrix.count(severity, vex), + max, + } + } + } + } + div { class: "cve-scale", "aria-hidden": "true", + span { {tx::FEW.get(lang)} } + for step in 1..=SHADES { + span { class: "cve-scale-step cve-shade-{step}" } + } + span { {tx::MANY.get(lang)} } + } + } + } +} + +/// One cell of the grid. An empty cell is disabled: it would open an empty +/// list. +#[component] +fn CveCellButton( + target_id: String, + severity: CveSeverity, + vex: VexColumn, + count: u64, + max: u64, +) -> Element { + let lang = use_lang()(); + let navigator = use_navigator(); + let label = cell_label(severity, vex, count, lang); + let step = shade(count, max); + rsx! { + button { + class: "cve-cell cve-shade-{step}", + "aria-label": "{label}", + title: "{label}", + disabled: count == 0, + onclick: move |_| { + navigator.push(list_route(&target_id, Some(CveFilter { + severity: Some(severity), + vex: Some(vex), + }))); + }, + "{count}" + } + } +} + +/// The same counts as a plain table, for screen readers and for reading +/// exact numbers; a count links to the narrowed list as in the grid. +#[component] +fn CveTable(target_id: String, matrix: CveMatrix) -> Element { + let lang = use_lang()(); + rsx! { + div { class: "table-wrapper", + table { class: "cve-table", + caption { class: "sr-only", {tx::CAPTION.get(lang)} } + thead { + tr { + th { scope: "col", {tx::SEVERITY.get(lang)} } + for vex in VexColumn::ALL { + th { scope: "col", {tx::vex(vex).get(lang)} } + } + } + } + tbody { + for severity in matrix.rows() { + tr { + th { scope: "row", {tx::severity(severity).get(lang)} } + for vex in VexColumn::ALL { + { + let count = matrix.count(severity, vex); + let to = list_route(&target_id, Some(CveFilter { + severity: Some(severity), + vex: Some(vex), + })); + rsx! { + td { + if count > 0 { + Link { + to, + "aria-label": cell_label(severity, vex, count, lang), + "{count}" + } + } else { + "0" + } + } + } + } + } + } + } + } + } + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn no_query_shows_the_grid_and_any_query_the_list() { + assert_eq!(selection(None, None), Selection::Grid); + assert_eq!( + selection(Some("high"), Some("open")), + Selection::List(Some(CveFilter { + severity: Some(CveSeverity::High), + vex: Some(VexColumn::Open), + })) + ); + assert_eq!( + selection(None, Some("open")), + Selection::List(Some(CveFilter { + severity: None, + vex: Some(VexColumn::Open), + })) + ); + assert_eq!(selection(None, Some(ALL)), Selection::List(None)); + assert_eq!(selection(Some("bogus"), None), Selection::List(None)); + } + + #[test] + fn every_route_reads_back_as_its_selection() { + let filters = [ + None, + Some(CveFilter { + severity: Some(CveSeverity::Unknown), + vex: Some(VexColumn::NotAffected), + }), + Some(CveFilter { + severity: None, + vex: Some(VexColumn::Open), + }), + Some(CveFilter { + severity: Some(CveSeverity::Low), + vex: None, + }), + ]; + for filter in filters { + let Route::TargetPage { + id, + cve_severity, + cve_vex, + } = list_route("t1", filter) + else { + panic!("not the target page"); + }; + assert_eq!(id, "t1"); + assert_eq!( + selection(cve_severity.as_deref(), cve_vex.as_deref()), + Selection::List(filter) + ); + } + } + + #[test] + fn the_shade_rises_with_the_count_and_one_cve_is_never_blank() { + assert_eq!(shade(0, 10), 0); + assert_eq!(shade(0, 0), 0); + assert_eq!(shade(1, 100), 1); + assert_eq!(shade(10, 10), SHADES); + assert_eq!(shade(5, 10), 3); + assert_eq!(shade(7, 7), SHADES); + assert_eq!((shade(40, 100), shade(41, 100)), (2, 3)); + } + + #[test] + fn labels_name_row_column_and_count() { + assert_eq!( + cell_label(CveSeverity::High, VexColumn::Open, 12, Lang::De), + "hoch, offen: 12" + ); + assert_eq!( + cell_label(CveSeverity::Critical, VexColumn::NotAffected, 0, Lang::En), + "critical, not affected: 0" + ); + let cell = Some(CveFilter { + severity: Some(CveSeverity::High), + vex: Some(VexColumn::Open), + }); + assert_eq!(crumb(cell, Lang::De), "hoch · offen"); + let column = Some(CveFilter { + severity: None, + vex: Some(VexColumn::UnderInvestigation), + }); + assert_eq!(crumb(column, Lang::De), "in Prüfung"); + assert_eq!(crumb(None, Lang::De), "alle"); + } +} diff --git a/compliance-dashboard/src/components/mod.rs b/compliance-dashboard/src/components/mod.rs index d79e12c..484b216 100644 --- a/compliance-dashboard/src/components/mod.rs +++ b/compliance-dashboard/src/components/mod.rs @@ -7,6 +7,7 @@ pub mod code_snippet; pub mod component_overview; pub mod copy_button; pub mod cra_bar; +pub mod cve_matrix; pub mod demo_targets; pub mod evidence_button; pub mod file_tree; diff --git a/compliance-dashboard/src/components/vex_panel.rs b/compliance-dashboard/src/components/vex_panel.rs index 0a45376..3017c88 100644 --- a/compliance-dashboard/src/components/vex_panel.rs +++ b/compliance-dashboard/src/components/vex_panel.rs @@ -11,6 +11,7 @@ use dioxus_free_icons::icons::bs_icons::BsDownload; use dioxus_free_icons::Icon; use compliance_core::cve_groups::{CveGroup, CveSeverity, PackageKey}; +use compliance_core::cve_matrix::CveFilter; use compliance_core::models::{CveAlert, VexAssessment, VexJustification, VexStatus}; use compliance_core::vex_docs::status_of; @@ -107,9 +108,10 @@ fn stated_by(alert: &CveAlert, lang: Lang) -> String { } } -/// The "Schwachstellen und VEX" card body for target `target_id`. +/// The "Schwachstellen und VEX" card body for target `target_id`; with +/// `filter`, only the alerts of that cell of the CVE grid (#957). #[component] -pub fn VexPanel(target_id: String) -> Element { +pub fn VexPanel(target_id: String, #[props(default)] filter: Option) -> Element { let lang = use_lang()(); let id_for_load = target_id.clone(); let mut alerts = use_resource(move || { @@ -151,6 +153,19 @@ pub fn VexPanel(target_id: String) -> Element { None => rsx! { div { class: "loading", {common::LOADING.get(lang)} } }, Some(None) => rsx! { p { class: "target-muted", {tx::LOAD_FAILED.get(lang)} } }, Some(Some(list)) if list.is_empty() => rsx! { p { class: "target-muted", {tx::NONE.get(lang)} } }, + // A cell of the CVE grid (#957) opens its alerts one by one: the + // package groups (#949) cover all open alerts, not the cell's. + Some(Some(list)) if filter.is_some() => rsx! { + CveTable { + alerts: list + .iter() + .filter(|a| filter.as_ref().is_none_or(|f| f.matches(a))) + .cloned() + .collect::>(), + candidates: candidates.clone(), + on_saved, + } + }, Some(Some(list)) => rsx! { div { class: "sbom-tab-bar vex-view-toggle", for (is_grouped, label) in [(true, tx::VIEW_GROUPED), (false, tx::VIEW_SINGLE)] { diff --git a/compliance-dashboard/src/i18n/texts.rs b/compliance-dashboard/src/i18n/texts.rs index bcfa6d0..a3f5bfc 100644 --- a/compliance-dashboard/src/i18n/texts.rs +++ b/compliance-dashboard/src/i18n/texts.rs @@ -5386,3 +5386,135 @@ pub mod component_overview { } } } + +/// The "CVEs & VEX" grid on a target (#957): CVEs by severity and VEX +/// status, each count a click into the narrowed list. +pub mod cve_matrix { + use super::Text; + use compliance_core::cve_matrix::{CveSeverity, VexColumn}; + + pub const HINT: Text = Text { + de: "Die gemeldeten CVEs nach Schweregrad und VEX-Status. „Offen“ heißt: noch keine \ + VEX-Aussage (im VEX-Export „in Prüfung“). Ein Klick auf eine Zahl zeigt diese CVEs.", + en: "The reported CVEs by severity and VEX status. \"Open\" means no VEX statement yet \ + (\"under investigation\" in the VEX export). Click a number to see those CVEs.", + }; + pub const VIEW: Text = Text { + de: "Darstellung", + en: "View", + }; + pub const CHART: Text = Text { + de: "Diagramm", + en: "Chart", + }; + pub const TABLE: Text = Text { + de: "Tabelle", + en: "Table", + }; + pub const SEVERITY: Text = Text { + de: "Schweregrad", + en: "Severity", + }; + pub const CAPTION: Text = Text { + de: "CVEs nach Schweregrad und VEX-Status", + en: "CVEs by severity and VEX status", + }; + pub const FEW: Text = Text { + de: "wenige", + en: "few", + }; + pub const MANY: Text = Text { + de: "viele", + en: "many", + }; + pub const UNASSESSED: Text = Text { + de: "Offen und noch nicht bewertet", + en: "Open and not assessed yet", + }; + pub const LIST_AND_EXPORTS: Text = Text { + de: "Liste und Exporte", + en: "List and exports", + }; + pub const CVES: Text = Text { + de: "CVEs", + en: "CVEs", + }; + pub const ALL: Text = Text { + de: "alle", + en: "all", + }; + pub const BACK: Text = Text { + de: "Zurück zum Diagramm", + en: "Back to the chart", + }; + + /// A row's label, lower case as in "hoch, offen: 12". + pub const fn severity(severity: CveSeverity) -> Text { + match severity { + CveSeverity::Critical => Text { + de: "kritisch", + en: "critical", + }, + CveSeverity::High => Text { + de: "hoch", + en: "high", + }, + CveSeverity::Medium => Text { + de: "mittel", + en: "medium", + }, + CveSeverity::Low => Text { + de: "niedrig", + en: "low", + }, + CveSeverity::Unknown => Text { + de: "unbekannt", + en: "unknown", + }, + } + } + + /// A column's label, lower case as in "hoch, offen: 12". + pub const fn vex(vex: VexColumn) -> Text { + match vex { + VexColumn::Open => Text { + de: "offen", + en: "open", + }, + VexColumn::UnderInvestigation => Text { + de: "in Prüfung", + en: "under investigation", + }, + VexColumn::Affected => Text { + de: "betroffen", + en: "affected", + }, + VexColumn::NotAffected => Text { + de: "nicht betroffen", + en: "not affected", + }, + VexColumn::Fixed => Text { + de: "behoben", + en: "fixed", + }, + } + } + + #[cfg(test)] + mod tests { + use super::*; + + #[test] + fn every_row_and_column_is_named_in_both_languages() { + for s in CveSeverity::ALL { + assert!(!severity(s).de.is_empty() && !severity(s).en.is_empty()); + } + for v in VexColumn::ALL { + assert!(!vex(v).de.is_empty() && !vex(v).en.is_empty()); + } + assert_eq!(severity(CveSeverity::High).de, "hoch"); + assert_eq!(vex(VexColumn::UnderInvestigation).de, "in Prüfung"); + assert_eq!(vex(VexColumn::NotAffected).en, "not affected"); + } + } +} diff --git a/compliance-dashboard/src/infrastructure/cve_matrix.rs b/compliance-dashboard/src/infrastructure/cve_matrix.rs new file mode 100644 index 0000000..c7d7773 --- /dev/null +++ b/compliance-dashboard/src/infrastructure/cve_matrix.rs @@ -0,0 +1,30 @@ +//! A target's CVE alerts counted by severity and VEX status (#957), from +//! the agent's `GET /api/v1/targets/{id}/cve-matrix`. + +use dioxus::prelude::*; + +use compliance_core::cve_matrix::CveMatrix; + +/// The agent's reply (read on the server only). +#[cfg(feature = "server")] +#[derive(Debug, serde::Deserialize)] +struct MatrixResponse { + data: CveMatrix, +} + +/// The still-reported CVE alerts of target `target_id`, counted per +/// severity and VEX status. +/// +/// # Errors +/// +/// The agent's refusal or an unreachable agent. +#[server] +pub async fn fetch_cve_matrix(target_id: String) -> Result { + let resp = super::agent_client::agent_get(&format!("/api/v1/targets/{target_id}/cve-matrix")) + .await? + .send() + .await + .map_err(|e| ServerFnError::new(e.to_string()))?; + let body: MatrixResponse = super::agent_client::json_or_error(resp).await?; + Ok(body.data) +} diff --git a/compliance-dashboard/src/infrastructure/mod.rs b/compliance-dashboard/src/infrastructure/mod.rs index 0d5b902..21d82f5 100644 --- a/compliance-dashboard/src/infrastructure/mod.rs +++ b/compliance-dashboard/src/infrastructure/mod.rs @@ -2,6 +2,7 @@ // the #[server] macro generates client stubs for the web target) pub mod auth_check; pub mod chat; +pub mod cve_matrix; pub mod dast; pub mod download; pub mod evidence; diff --git a/compliance-dashboard/src/pages/compliance.rs b/compliance-dashboard/src/pages/compliance.rs index 83ebe7c..8ee545f 100644 --- a/compliance-dashboard/src/pages/compliance.rs +++ b/compliance-dashboard/src/pages/compliance.rs @@ -70,7 +70,7 @@ pub fn CompliancePage(id: String) -> Element { rsx! { div { class: "back-nav", - Link { to: Route::TargetPage { id: id.clone() }, class: "btn btn-ghost btn-back", + Link { to: Route::target(id.clone()), class: "btn btn-ghost btn-back", Icon { icon: BsArrowLeft, width: 16, height: 16 } "{name}" } diff --git a/compliance-dashboard/src/pages/graph_explorer.rs b/compliance-dashboard/src/pages/graph_explorer.rs index 712f027..9c7a25b 100644 --- a/compliance-dashboard/src/pages/graph_explorer.rs +++ b/compliance-dashboard/src/pages/graph_explorer.rs @@ -500,7 +500,7 @@ fn GraphBack(repo_id: String) -> Element { let lang = use_lang()(); rsx! { div { class: "back-nav", - Link { to: Route::TargetPage { id: repo_id }, class: "btn btn-ghost btn-back", + Link { to: Route::target(repo_id), class: "btn btn-ghost btn-back", Icon { icon: BsArrowLeft, width: 16, height: 16 } {tx::BACK.get(lang)} } diff --git a/compliance-dashboard/src/pages/target.rs b/compliance-dashboard/src/pages/target.rs index e3f7c92..8aba53a 100644 --- a/compliance-dashboard/src/pages/target.rs +++ b/compliance-dashboard/src/pages/target.rs @@ -10,6 +10,7 @@ use crate::app::Route; use crate::components::artifact_upload::ArtifactUpload; use crate::components::billing_swap::BillingSwap; use crate::components::cra_bar::CraBar; +use crate::components::cve_matrix::CveView; use crate::components::evidence_button::EvidencePackButton; use crate::components::layer_pins::LayerPinsCard; use crate::components::manual_findings::ManualFindingsPanel; @@ -19,7 +20,6 @@ use crate::components::scan_coverage::ScanCoverage; use crate::components::scan_runs::ScanRunList; use crate::components::severity_badge::SeverityBadge; use crate::components::toast::{ToastType, Toasts}; -use crate::components::vex_panel::VexPanel; use crate::components::webhook_deliveries::WebhookDeliveries; use crate::i18n::texts::{common, compliance::language_name, kinds, targets as tx}; use crate::i18n::use_lang; @@ -92,8 +92,10 @@ fn editable_artifacts(target: &serde_json::Value) -> Vec { .unwrap_or_default() } +/// The page of target `id`. `cve_severity` and `cve_vex` are the CVE grid's +/// cell from the URL query (see [`CveView`]). #[component] -pub fn TargetPage(id: String) -> Element { +pub fn TargetPage(id: String, cve_severity: Option, cve_vex: Option) -> Element { let lang = use_lang()(); let can_write = use_can_write(); let mut toasts = use_context::(); @@ -348,7 +350,7 @@ pub fn TargetPage(id: String) -> Element { section { class: "card target-vex", div { class: "target-card-head", h3 { {crate::i18n::texts::vex::TITLE.get(lang)} } } - div { class: "target-card-body", VexPanel { target_id: id.clone() } } + div { class: "target-card-body", CveView { target_id: id.clone(), cve_severity, cve_vex } } } div { class: "target-columns", diff --git a/compliance-dashboard/src/pages/targets.rs b/compliance-dashboard/src/pages/targets.rs index 638ff80..3096c86 100644 --- a/compliance-dashboard/src/pages/targets.rs +++ b/compliance-dashboard/src/pages/targets.rs @@ -226,10 +226,10 @@ pub fn TargetsPage() -> Element { rsx! { tr { class: "targets-row", - onclick: move |_| { navigator.push(Route::TargetPage { id: id_open.clone() }); }, + onclick: move |_| { navigator.push(Route::target(id_open.clone())); }, td { Link { - to: Route::TargetPage { id: id.clone() }, + to: Route::target(id.clone()), class: "targets-name", onclick: move |e: MouseEvent| e.stop_propagation(), "{name}" diff --git a/docs/guide/sbom.md b/docs/guide/sbom.md index ca0c3c4..a2aaa1f 100644 --- a/docs/guide/sbom.md +++ b/docs/guide/sbom.md @@ -442,6 +442,8 @@ differently: | `inline_mitigations_already_exist` | `protected_by_mitigating_control` | API: `GET /api/v1/targets/{id}/cves` lists the alerts with their statements, +`GET /api/v1/targets/{id}/cve-matrix` counts the still-reported ones per severity +and VEX status (`open` = no statement yet) for the grid on the target page, `PATCH /api/v1/cves/{id}/vex` sets one (`{"status": "not_affected", "justification": "…", "impact_statement": "…"}`), `GET /api/v1/targets/{id}/cve-groups` lists the open alerts grouped by component