feat(dashboard): CRA requirements by name, no off-site advisory links

The 40 CRA Annex I requirements are shown by a name customers read
("Keine Standardpasswörter") instead of cra-ai-N, grouped by area on a
map; a requirement opens beside it with what red, orange and green mean
for that requirement, or the document that proves it.

- compliance-core: cra_requirements table (names, state meanings, proof
  documents, DE/EN) and AdvisoryRef::required_backlink (Siemens only)
- dashboard: CRA map with area cards and side panel; names in the
  compliance list, findings list and finding detail; "not checked yet" is
  grey, orange means partly checked only
- no links to OSV, GHSA, NVD or other advisory sites: CVE and advisory
  ids get a copy button; only a provider whose terms require a backlink
  keeps a "Quelle" link; off-site links in rendered markdown become text
- agent: ticket texts name requirements; CVE tickets and notifications
  no longer carry an osv.dev link; findings.csv adds requirement names
- machine-readable exports (CSAF, VEX, OSCAL, JSON) keep the ids

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Q9inRcu428A2iNjDHPEAT9
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-11-27 23:23:14 +01:00
1 parent 87b1e281ed
commit 9119dcdd9d
20 files changed
+1635 -390

No files matched your search

+12 -1
View File
@@ -349,7 +349,7 @@ fn json<T: Serialize>(value: &T) -> Result<Vec<u8>, AgentError> {
/// The findings as CSV, one row each, for a spreadsheet.
fn findings_csv(findings: &[Finding]) -> String {
let mut out =
String::from("id,severity,status,type,scanner,rule_id,cwe,location,title,cra_controls\n");
String::from("id,severity,status,type,scanner,rule_id,cwe,location,title,cra_controls,cra_requirements\n");
for f in findings {
let location = match (&f.file_path, f.line_number) {
(Some(file), Some(line)) => format!("{file}:{line}"),
@@ -367,6 +367,13 @@ fn findings_csv(findings: &[Finding]) -> String {
location,
f.title.clone(),
f.control_refs.join(" "),
// The same requirements by name, for a person reading the sheet.
f.control_refs
.iter()
.filter_map(|id| compliance_core::cra_requirements::name(id))
.map(|name| name.de)
.collect::<Vec<_>>()
.join("; "),
];
let cells: Vec<String> = row.iter().map(|c| csv_cell(c)).collect();
out.push_str(&cells.join(","));
@@ -636,6 +643,10 @@ mod tests {
"{csv}"
);
assert!(csv.contains("Core/Src/comms.c:9"));
assert!(
csv.contains(",cra-ai-8,Keine Standardpasswörter\n"),
"{csv}"
);
assert_eq!(csv_cell("=HYPERLINK(1)"), "'=HYPERLINK(1)");
assert_eq!(csv_cell("plain"), "plain");
}
@@ -466,10 +466,6 @@ fn issue_body(alert: &CveAlert, severity: &str, target_id: &str, dashboard: &str
.push_str("- Behoben in / Fixed in: keine Version bekannt / no fixed version known\n"),
fixed => body.push_str(&format!("- Behoben in / Fixed in: {}\n", fixed.join(", "))),
}
body.push_str(&format!(
"- Advisory: https://osv.dev/vulnerability/{}\n",
alert.cve_id
));
if alert
.exploitation
.as_ref()
@@ -47,7 +47,6 @@ pub async fn notify_new_cves(
);
notification.cvss_score = alert.cvss_score;
notification.summary = alert.summary.clone();
notification.url = Some(format!("https://osv.dev/vulnerability/{}", alert.cve_id));
let notification = match mongodb::bson::to_bson(&notification) {
Ok(n) => n,
Err(e) => {
+13 -17
View File
@@ -687,23 +687,17 @@ pub(super) fn format_issue_body(finding: &Finding) -> String {
body
}
/// The CRA requirements a finding is evidence for, as `cra-ai-8 — <title>`,
/// from its stamped `control_refs`. Titles come from the CRA control map.
/// The CRA requirements a finding is evidence for, from its stamped
/// `control_refs`, by the name a customer reads in both languages
/// (`Keine Standardpasswörter / No default passwords (Annex I)`). An id
/// outside the 40 requirements stays as it is.
fn cra_requirements(control_refs: &[String]) -> Vec<String> {
let map = control_map::ControlMap::cra().ok();
control_refs
.iter()
.filter(|id| id.starts_with("cra-"))
.map(|id| {
match map
.as_ref()
.and_then(|m| m.coverage(id))
.map(|c| c.title.as_str())
.filter(|t| !t.is_empty())
{
Some(title) => format!("{id} — {title} (Annex I)"),
None => format!("{id} (Annex I)"),
}
.map(|id| match compliance_core::cra_requirements::name(id) {
Some(name) => format!("{} / {} (Annex I)", name.de, name.en),
None => format!("{id} (Annex I)"),
})
.collect()
}
@@ -737,9 +731,10 @@ mod tests {
fn cra_requirements_name_the_control() {
let refs = vec!["cra-ai-1".to_string(), "iec-x".to_string()];
let lines = cra_requirements(&refs);
assert_eq!(lines.len(), 1);
assert!(lines[0].starts_with("cra-ai-1 — "), "{lines:?}");
assert!(lines[0].ends_with("(Annex I)"));
assert_eq!(
lines,
["Sichere Werkseinstellungen / Secure factory settings (Annex I)"]
);
assert_eq!(
cra_requirements(&["cra-unknown".to_string()]),
["cra-unknown (Annex I)"]
@@ -761,7 +756,8 @@ mod tests {
f.control_refs = vec!["cra-ai-1".into()];
let body = format_issue_body(&f);
assert!(body.contains("**CWE:** CWE-89"));
assert!(body.contains("**CRA:** cra-ai-1"));
assert!(body.contains("**CRA:** Sichere Werkseinstellungen / Secure factory settings"));
assert!(!body.contains("cra-ai-1"));
assert!(body.contains("`fp1`"));
}
+683
View File
@@ -0,0 +1,683 @@
//! The 40 CRA Annex I requirements in the words a customer reads: a name
//! that says what the requirement is about, and for each state what it means
//! for that requirement (#sps2026 item 10).
//!
//! The catalog (`cra-ai-1` … `cra-ai-40`) stays the source of the ids and of
//! the legal wording; people never see those ids. Machine-readable exports
//! (CSAF, VEX, OSCAL, JSON) keep them.
/// One text in both languages of the product.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Words {
/// German.
pub de: &'static str,
/// English.
pub en: &'static str,
}
/// The area a requirement belongs to, in the catalog's group order.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum CraArea {
/// Secure by design (`cra-ai-1` … `6`).
SecureDesign,
/// Sign-in and access (`7` … `12`).
Access,
/// Encryption (`13` … `17`).
Encryption,
/// Development (`18` … `20`).
Development,
/// Supply chain (`21` … `23`).
SupplyChain,
/// Logs (`24` … `27`).
Logging,
/// Updates (`28` … `31`).
Updates,
/// Vulnerabilities and incidents (`32` … `40`).
Vulnerabilities,
}
impl CraArea {
/// Every area, in the order the views show them.
pub const ALL: [Self; 8] = [
Self::SecureDesign,
Self::Access,
Self::Encryption,
Self::Development,
Self::SupplyChain,
Self::Logging,
Self::Updates,
Self::Vulnerabilities,
];
/// The area's name.
pub const fn name(self) -> Words {
match self {
Self::SecureDesign => w("Sicher entworfen", "Secure by design"),
Self::Access => w("Anmeldung und Zugriff", "Sign-in and access"),
Self::Encryption => w("Verschlüsselung", "Encryption"),
Self::Development => w("Entwicklung", "Development"),
Self::SupplyChain => w("Lieferkette", "Supply chain"),
Self::Logging => w("Protokolle", "Logs"),
Self::Updates => w("Updates", "Updates"),
Self::Vulnerabilities => w(
"Schwachstellen und Vorfälle",
"Vulnerabilities and incidents",
),
}
}
}
/// One requirement as a customer reads it.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct CraRequirement {
/// The catalog id (`cra-ai-8`).
pub id: &'static str,
/// Its area.
pub area: CraArea,
/// Its name (`Keine Standardpasswörter`).
pub name: Words,
/// What red means here: what an open finding against it shows. `None`
/// for a requirement a code scan cannot decide.
pub against: Option<Words>,
/// What green means here: what the scan did not find.
pub clear: Option<Words>,
/// The document that proves a requirement no code scan decides, as the
/// end of "Sie weisen sie nach mit …" (`ein Rechtekonzept`).
pub proof: Option<Words>,
}
/// What orange means for every requirement: only part of what it covers was
/// checked.
pub const PARTLY_CHECKED: Words = w(
"Nur ein Teil wurde geprüft, zum Beispiel bei einem Yocto-Image die Rezeptliste statt des \
fertigen Images.",
"Only part was checked, for example a Yocto image's recipe list instead of the built image.",
);
/// The requirement with catalog id `id`, if it is one of the 40.
///
/// # Examples
///
/// ```
/// use compliance_core::cra_requirements::requirement;
/// assert_eq!(requirement("cra-ai-8").unwrap().name.de, "Keine Standardpasswörter");
/// assert!(requirement("cra-ai-20-csharp-xxe").is_none());
/// ```
pub fn requirement(id: &str) -> Option<&'static CraRequirement> {
let number: usize = id.strip_prefix("cra-ai-")?.parse().ok()?;
CRA_REQUIREMENTS
.get(number.checked_sub(1)?)
.filter(|r| r.id == id)
}
/// The name of requirement `id` in German and English, or `None` for an id
/// that is not one of the 40.
pub fn name(id: &str) -> Option<Words> {
requirement(id).map(|r| r.name)
}
const fn w(de: &'static str, en: &'static str) -> Words {
Words { de, en }
}
/// A requirement a code scan checks.
const fn checked(
id: &'static str,
area: CraArea,
name: Words,
against: Words,
clear: Words,
) -> CraRequirement {
CraRequirement {
id,
area,
name,
against: Some(against),
clear: Some(clear),
proof: None,
}
}
/// A requirement proven by a document.
const fn proven(id: &'static str, area: CraArea, name: Words, proof: Words) -> CraRequirement {
CraRequirement {
id,
area,
name,
against: None,
clear: None,
proof: Some(proof),
}
}
use CraArea::{
Access, Development, Encryption, Logging, SecureDesign, SupplyChain, Updates, Vulnerabilities,
};
/// The 40 requirements, `cra-ai-1` first.
pub const CRA_REQUIREMENTS: [CraRequirement; 40] = [
checked(
"cra-ai-1",
SecureDesign,
w("Sichere Werkseinstellungen", "Secure factory settings"),
w(
"Im Auslieferungszustand ist etwas offen, das es nicht sein muss, etwa eine \
Debug-Schnittstelle oder ein unnötiger Dienst.",
"Something is open as shipped that need not be, such as a debug interface or an \
unneeded service.",
),
w(
"Der Scan fand keine unsicheren Voreinstellungen.",
"The scan found no insecure defaults.",
),
),
// Decided in code only on a Yocto layer tree, so it has both.
CraRequirement {
id: "cra-ai-2",
area: SecureDesign,
name: w("Nur nötige Dienste aktiv", "Only needed services running"),
against: Some(w(
"Das Image startet Dienste oder öffnet Schnittstellen, die das Gerät nicht braucht.",
"The image starts services or opens interfaces the device does not need.",
)),
clear: Some(w(
"Im Image fand der Scan keine unnötig aktiven Dienste.",
"The scan found no needlessly running services in the image.",
)),
proof: Some(w(
"eine Liste der Dienste und Schnittstellen mit ihrem Zweck",
"a list of services and interfaces with their purpose",
)),
},
proven(
"cra-ai-3",
SecureDesign,
w("Getrennte Sicherheitsbereiche", "Separated security zones"),
w(
"eine Architekturbeschreibung",
"an architecture description",
),
),
proven(
"cra-ai-4",
SecureDesign,
w("Nur die nötigen Rechte", "Only the rights needed"),
w("ein Rechtekonzept", "a permissions concept"),
),
proven(
"cra-ai-5",
SecureDesign,
w("Schutz vor Manipulation", "Protection against tampering"),
w(
"eine Beschreibung von Secure Boot und Code-Signatur",
"a description of secure boot and code signing",
),
),
checked(
"cra-ai-6",
SecureDesign,
w("Prüfung auf Veränderung", "Checks for modification"),
w(
"Software oder Firmware wird geladen, ohne vorher zu prüfen, ob sie verändert wurde.",
"Software or firmware is loaded without first checking whether it was modified.",
),
w(
"An den Stellen, an denen Software geladen wird, fand der Scan eine Prüfung auf \
Veränderung.",
"Where software is loaded, the scan found a check for modification.",
),
),
checked(
"cra-ai-7",
Access,
w("Sichere Anmeldung", "Secure sign-in"),
w(
"Eine Anmeldung ist schwach umgesetzt, etwa ohne Passwortprüfung oder mit einem \
veralteten Verfahren.",
"A sign-in is weakly built, for example without a password check or with an \
outdated method.",
),
w(
"Der Scan fand keine schwach umgesetzte Anmeldung.",
"The scan found no weakly built sign-in.",
),
),
checked(
"cra-ai-8",
Access,
w("Keine Standardpasswörter", "No default passwords"),
w(
"Im Code oder im Image steckt ein fest eingebautes Passwort, das auf jedem Gerät \
gleich ist.",
"The code or image holds a built-in password that is the same on every device.",
),
w(
"Der Scan fand kein fest eingebautes Passwort.",
"The scan found no built-in password.",
),
),
checked(
"cra-ai-9",
Access,
w("Zugangsdaten sicher verwahrt", "Credentials kept safe"),
w(
"Zugangsdaten, Tokens oder Schlüssel liegen im Klartext im Code oder in Dateien.",
"Credentials, tokens or keys are in plain text in the code or in files.",
),
w(
"Der Scan fand keine Zugangsdaten im Klartext.",
"The scan found no credentials in plain text.",
),
),
checked(
"cra-ai-10",
Access,
w("Sitzungen enden sicher", "Sessions end safely"),
w(
"Sitzungen laufen nicht ab oder sind nicht gegen untergeschobene Anfragen geschützt.",
"Sessions do not expire or are not protected against forged requests.",
),
w(
"Der Scan fand keine unsicher verwalteten Sitzungen.",
"The scan found no unsafely managed sessions.",
),
),
checked(
"cra-ai-11",
Access,
w(
"Schutz vor Passwort-Raten",
"Protection against password guessing",
),
w(
"Eine Anmeldung erlaubt beliebig viele Versuche.",
"A sign-in allows any number of attempts.",
),
w(
"Wo man sich anmeldet, ist die Zahl der Versuche begrenzt.",
"Where people sign in, the number of attempts is limited.",
),
),
checked(
"cra-ai-12",
Access,
w("Rollen und Rechte", "Roles and permissions"),
w(
"Funktionen für Administratoren sind ohne Rechteprüfung erreichbar.",
"Administrator functions can be reached without a permission check.",
),
w(
"Vor den geschützten Funktionen fand der Scan eine Rechteprüfung.",
"The scan found a permission check before the protected functions.",
),
),
checked(
"cra-ai-13",
Encryption,
w(
"Vertrauliche Daten verschlüsselt",
"Sensitive data encrypted",
),
w(
"Vertrauliche Daten werden unverschlüsselt oder mit einem veralteten Verfahren \
verarbeitet.",
"Sensitive data is handled unencrypted or with an outdated method.",
),
w(
"Der Scan fand keine unverschlüsselten vertraulichen Daten.",
"The scan found no unencrypted sensitive data.",
),
),
checked(
"cra-ai-14",
Encryption,
w("Gespeicherte Daten verschlüsselt", "Stored data encrypted"),
w(
"Daten werden unverschlüsselt oder mit einem schwachen Verfahren gespeichert.",
"Data is stored unencrypted or with a weak method.",
),
w(
"Der Scan fand keine unverschlüsselt gespeicherten Daten.",
"The scan found no data stored unencrypted.",
),
),
checked(
"cra-ai-15",
Encryption,
w("Verbindungen verschlüsselt", "Connections encrypted"),
w(
"Eine Verbindung läuft unverschlüsselt oder mit altem SSL/TLS.",
"A connection runs unencrypted or over old SSL/TLS.",
),
w(
"Alle gefundenen Verbindungen nutzen aktuelle Verschlüsselung.",
"Every connection found uses current encryption.",
),
),
checked(
"cra-ai-16",
Encryption,
w("Schlüssel sicher verwahrt", "Keys kept safe"),
w(
"Ein kryptografischer Schlüssel steht im Code oder liegt ungeschützt bei den Dateien.",
"A cryptographic key is written in the code or lies unprotected among the files.",
),
w(
"Der Scan fand keinen ungeschützten Schlüssel.",
"The scan found no unprotected key.",
),
),
proven(
"cra-ai-17",
Encryption,
w("Nur nötige Daten erfassen", "Collect only the data needed"),
w("ein Datenschutzkonzept", "a data protection concept"),
),
proven(
"cra-ai-18",
Development,
w(
"Sicherheit im Entwicklungsablauf",
"Security in the development process",
),
w(
"eine Beschreibung Ihres Entwicklungsablaufs",
"a description of your development process",
),
),
proven(
"cra-ai-19",
Development,
w("Code-Prüfung durch Kollegen", "Code review by colleagues"),
w("Ihre Regeln für Code-Reviews", "your code review rules"),
),
checked(
"cra-ai-20",
Development,
w("Sicherer Programmcode", "Safe program code"),
w(
"Im Code stecken unsichere Muster, etwa ungeprüfte Eingaben oder unsichere \
C-Funktionen.",
"The code holds unsafe patterns, such as unchecked input or unsafe C functions.",
),
w(
"Die Sicherheitstests fanden keine unsicheren Muster.",
"The security tests found no unsafe patterns.",
),
),
proven(
"cra-ai-21",
SupplyChain,
w("Fremdkomponenten geprüft", "Third-party components vetted"),
w(
"Ihren Prüfablauf für zugekaufte Komponenten",
"your vetting process for bought-in components",
),
),
checked(
"cra-ai-22",
SupplyChain,
w(
"Bekannte Schwachstellen in Komponenten",
"Known vulnerabilities in components",
),
w(
"Eine eingesetzte Komponente hat eine bekannte Schwachstelle, die noch offen ist.",
"A component in use has a known vulnerability that is still open.",
),
w(
"Für keine eingesetzte Komponente ist eine offene Schwachstelle bekannt.",
"No component in use has a known open vulnerability.",
),
),
checked(
"cra-ai-23",
SupplyChain,
w(
"Vollständige Stückliste (SBOM)",
"Complete bill of materials (SBOM)",
),
w(
"Die Stückliste fehlt, oder ihr fehlen Angaben wie Version oder Lizenz.",
"The bill of materials is missing, or lacks details such as version or licence.",
),
w(
"Die Stückliste ist vollständig und maschinenlesbar.",
"The bill of materials is complete and machine-readable.",
),
),
checked(
"cra-ai-24",
Logging,
w(
"Sicherheitsereignisse protokolliert",
"Security events logged",
),
w(
"Anmeldungen, Rechteänderungen oder Aktionen von Administratoren werden nicht \
protokolliert.",
"Sign-ins, permission changes or administrator actions are not logged.",
),
w(
"Der Scan fand eine Protokollierung der sicherheitsrelevanten Ereignisse.",
"The scan found the security-relevant events being logged.",
),
),
proven(
"cra-ai-25",
Logging,
w("Zentrale Überwachung", "Central monitoring"),
w("Ihr Überwachungskonzept", "your monitoring concept"),
),
proven(
"cra-ai-26",
Logging,
w(
"Angriffe automatisch erkannt",
"Attacks detected automatically",
),
w(
"eine Beschreibung Ihrer Angriffserkennung",
"a description of your attack detection",
),
),
checked(
"cra-ai-27",
Logging,
w("Fälschungssichere Protokolle", "Tamper-proof logs"),
w(
"Protokolle lassen sich nachträglich ändern oder werden zu kurz aufbewahrt.",
"Logs can be changed afterwards or are kept too briefly.",
),
w(
"Der Scan fand keine änderbaren oder zu kurz aufbewahrten Protokolle.",
"The scan found no logs that can be changed or are kept too briefly.",
),
),
checked(
"cra-ai-28",
Updates,
w("Sicherer Update-Weg", "Secure update channel"),
w(
"Updates kommen über einen ungesicherten Weg, etwa per HTTP.",
"Updates arrive over an unsecured channel, such as plain HTTP.",
),
w(
"Updates kommen über einen gesicherten Weg.",
"Updates arrive over a secured channel.",
),
),
checked(
"cra-ai-29",
Updates,
w("Signierte Updates", "Signed updates"),
w(
"Ein Update wird installiert, ohne vorher seine Signatur zu prüfen.",
"An update is installed without first checking its signature.",
),
w(
"Vor der Installation wird die Signatur eines Updates geprüft.",
"An update's signature is checked before it is installed.",
),
),
checked(
"cra-ai-30",
Updates,
w("Unversehrte Update-Pakete", "Intact update packages"),
w(
"Update-Pakete werden ohne Prüfsumme oder Signatur übernommen.",
"Update packages are taken without a checksum or signature.",
),
w(
"Update-Pakete werden vor der Übernahme geprüft.",
"Update packages are checked before they are taken.",
),
),
proven(
"cra-ai-31",
Updates,
w(
"Updates über die Lebensdauer",
"Updates over the product's lifetime",
),
w(
"eine Support-Zusage mit Enddatum",
"a support commitment with an end date",
),
),
proven(
"cra-ai-32",
Vulnerabilities,
w(
"Schwachstellen werden gesucht",
"Vulnerabilities are looked for",
),
w(
"Ihren Meldeweg und Ihre Überwachung",
"your reporting channel and monitoring",
),
),
checked(
"cra-ai-33",
Vulnerabilities,
w(
"Stückliste laufend geprüft",
"Bill of materials checked continuously",
),
w(
"Die Stückliste nennt Komponenten mit neu bekannt gewordenen Schwachstellen.",
"The bill of materials lists components with newly known vulnerabilities.",
),
w(
"Bei jedem Scan wird die Stückliste gegen bekannte Schwachstellen geprüft; nichts \
ist offen.",
"Every scan checks the bill of materials against known vulnerabilities; nothing is \
open.",
),
),
proven(
"cra-ai-34",
Vulnerabilities,
w("Wichtiges zuerst beheben", "Fix what matters first"),
w("Ihre Fristen für die Behebung", "your deadlines for fixes"),
),
proven(
"cra-ai-35",
Vulnerabilities,
w(
"Meldestelle für Schwachstellen",
"Vulnerability reporting contact",
),
w(
"eine veröffentlichte Kontaktadresse für Meldungen",
"a published contact address for reports",
),
),
proven(
"cra-ai-36",
Vulnerabilities,
w("Plan für Sicherheitsvorfälle", "Incident response plan"),
w("Ihren Notfallplan", "your emergency plan"),
),
proven(
"cra-ai-37",
Vulnerabilities,
w(
"Frühwarnung binnen 24 Stunden",
"Early warning within 24 hours",
),
w(
"Ihren Meldeablauf an ENISA und CSIRT",
"your reporting procedure to ENISA and the CSIRT",
),
),
proven(
"cra-ai-38",
Vulnerabilities,
w(
"Vorfallsbericht binnen 72 Stunden",
"Incident report within 72 hours",
),
w("Ihre Berichtsvorlage", "your report template"),
),
proven(
"cra-ai-39",
Vulnerabilities,
w("Sicherheits-Updates bereitstellen", "Ship security updates"),
w(
"Ihren Ablauf für Sicherheits-Updates",
"your procedure for security updates",
),
),
proven(
"cra-ai-40",
Vulnerabilities,
w("Lückenlos dokumentiert", "Fully documented"),
w(
"Ihre Dokumentation, zehn Jahre aufbewahrt",
"your documentation, kept for ten years",
),
),
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_table_is_in_id_order_and_every_id_resolves() {
for (i, r) in CRA_REQUIREMENTS.iter().enumerate() {
assert_eq!(r.id, format!("cra-ai-{}", i + 1));
assert_eq!(requirement(r.id), Some(r));
}
assert!(requirement("cra-ai-0").is_none());
assert!(requirement("cra-ai-41").is_none());
assert!(requirement("cra-ai-8-csharp-hardcoded-credential").is_none());
assert!(requirement("mc-1").is_none());
}
#[test]
fn every_requirement_says_what_its_states_mean() {
for r in &CRA_REQUIREMENTS {
assert_eq!(r.against.is_some(), r.clear.is_some(), "{}", r.id);
assert!(r.against.is_some() || r.proof.is_some(), "{}", r.id);
for words in [Some(r.name), r.against, r.clear, r.proof]
.into_iter()
.flatten()
{
assert!(!words.de.is_empty() && !words.en.is_empty(), "{}", r.id);
}
}
}
#[test]
fn names_are_unique_and_every_area_has_requirements() {
let mut names: Vec<&str> = CRA_REQUIREMENTS.iter().map(|r| r.name.de).collect();
names.sort_unstable();
names.dedup();
assert_eq!(names.len(), CRA_REQUIREMENTS.len());
for area in CraArea::ALL {
assert!(CRA_REQUIREMENTS.iter().any(|r| r.area == area), "{area:?}");
}
}
}
+1
View File
@@ -2,6 +2,7 @@ pub mod build_info;
pub mod component_changes;
pub mod config;
pub mod control_check;
pub mod cra_requirements;
pub mod csaf_docs;
pub mod csaf_ingest;
pub mod cve_groups;
+39
View File
@@ -28,6 +28,20 @@ pub struct AdvisoryRef {
pub remediation: Option<String>,
}
/// The providers whose terms ask every use of an advisory to link it.
const BACKLINK_PROVIDERS: &[&str] = &["siemens"];
impl AdvisoryRef {
/// The advisory's page when its provider's terms require a link back to
/// it (Siemens ProductCERT); `None` otherwise. The views link nothing
/// else off-site: a customer copies the id instead.
pub fn required_backlink(&self) -> Option<&str> {
self.url
.as_deref()
.filter(|_| BACKLINK_PROVIDERS.contains(&self.provider.as_str()))
}
}
/// 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.
@@ -284,6 +298,31 @@ mod tests {
a
}
#[test]
fn only_a_provider_that_asks_for_it_keeps_its_link() {
let advisory = |provider: &str| AdvisoryRef {
provider: provider.into(),
id: "X-1".into(),
title: "t".into(),
url: Some("https://vendor.example/x-1".into()),
remediation: None,
};
assert_eq!(
advisory("siemens").required_backlink(),
Some("https://vendor.example/x-1")
);
assert_eq!(advisory("codesys").required_backlink(), None);
assert_eq!(
advisory("supplier:https://s.example/pm.json").required_backlink(),
None
);
let unlinked = AdvisoryRef {
url: None,
..advisory("siemens")
};
assert_eq!(unlinked.required_backlink(), None);
}
#[test]
fn only_not_affected_and_fixed_resolve_an_alert() {
use crate::models::vex::{VexAssessment, VexStatus};
+256 -109
View File
@@ -884,6 +884,12 @@ tbody tr:last-child td {
}
/* Neutral: skipped because a feature is disabled in this environment — not an error. */
.badge-open {
background: var(--bg-elevated);
color: var(--text-secondary);
border: 1px dashed var(--text-faint);
}
.badge-neutral {
background: transparent;
color: var(--text-tertiary);
@@ -2955,18 +2961,6 @@ tbody tr:last-child td {
text-transform: uppercase;
}
.sbom-vuln-link {
font-size: 12px;
color: var(--accent);
text-decoration: none;
transition: color 0.15s;
}
.sbom-vuln-link:hover {
color: var(--accent-hover);
text-decoration: underline;
}
/* License compliance */
.sbom-license-badge {
font-size: 12px;
@@ -4243,9 +4237,7 @@ tbody tr:last-child td {
.notification-sev.sev-high { background: rgba(255,140,0,0.12); color: #ff8c00; }
.notification-sev.sev-medium { background: var(--warning-bg); color: var(--warning); }
.notification-sev.sev-low { background: rgba(0,200,255,0.08); color: var(--accent); }
.notification-cve-id { font-size: 12px; font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }
.notification-cve-id a { color: var(--accent); text-decoration: none; }
.notification-cve-id a:hover { text-decoration: underline; }
.notification-cve-id { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-primary); font-family: var(--font-mono); }
.notification-cvss { font-size: 10px; color: var(--text-secondary); margin-left: auto; font-family: var(--font-mono); }
.notification-dismiss-btn { background: none; border: none; color: var(--text-tertiary); cursor: pointer; padding: 2px; margin-left: 4px; }
.notification-dismiss-btn:hover { color: var(--danger); }
@@ -4482,6 +4474,17 @@ tbody tr:last-child td {
align-items: center;
}
.finding-control {
display: inline-flex;
align-items: center;
padding: 2px 8px;
border-radius: 999px;
background: var(--accent-muted);
color: var(--text-primary);
font-size: 12px;
line-height: 1.35;
}
.finding-controls-more,
.finding-controls-none {
font-size: 11px;
@@ -4582,8 +4585,8 @@ tbody tr:last-child td {
}
.cra-violated { background: var(--danger); }
.cra-open { background: var(--warning); }
.cra-partial { background: var(--info); }
.cra-open { background: var(--text-faint); }
.cra-partial { background: var(--warning); }
.cra-clear { background: var(--success); }
.cra-process { background: color-mix(in srgb, var(--accent) 28%, var(--bg-elevated)); }
@@ -5585,7 +5588,20 @@ tbody tr:last-child td {
}
.vex-advisory {
display: block;
font-family: var(--font-mono);
font-size: 11.5px;
color: var(--text-secondary);
}
.vex-cve-id,
.vex-advisory-line {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px 6px;
}
.vex-advisory-source {
font-size: 11.5px;
color: var(--accent);
}
@@ -5742,13 +5758,6 @@ tbody tr:last-child td {
gap: 6px 10px;
}
.cra-control-id {
font-family: var(--font-mono);
font-size: 11.5px;
color: var(--text-tertiary);
min-width: 72px;
}
.cra-control-title {
font-weight: 500;
}
@@ -8062,14 +8071,18 @@ span.repo-crumb-name {
overflow-wrap: anywhere;
}
/* ── CRA Annex I tiles (#957) ── */
/* ── CRA Annex I map (#957): requirements by name, grouped by area ── */
.ct-card,
.sh-card {
display: grid;
gap: 12px;
}
.ct-head,
.ct-head {
display: grid;
gap: 10px;
}
.sh-head {
display: flex;
flex-wrap: wrap;
@@ -8084,7 +8097,6 @@ span.repo-crumb-name {
font-weight: 600;
}
.ct-legend,
.sh-legend {
display: flex;
flex-wrap: wrap;
@@ -8093,97 +8105,236 @@ span.repo-crumb-name {
font-size: 12px;
}
.ct-legend-item {
display: inline-flex;
align-items: center;
gap: 6px;
}
.ct-swatch {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 20px;
height: 16px;
padding: 0 3px;
border-radius: 3px;
font-size: 10px;
font-weight: 700;
}
/* Ten to a row, as the 40 requirements make four rows; five on a phone. */
.ct-grid {
display: grid;
grid-template-columns: repeat(10, minmax(0, 1fr));
gap: 6px;
}
@media (max-width: 720px) {
.ct-grid {
grid-template-columns: repeat(5, minmax(0, 1fr));
}
}
.ct-tile {
display: flex;
flex-direction: column;
justify-content: space-between;
min-height: 56px;
padding: 6px 8px;
border: 1px solid transparent;
border-radius: var(--radius);
font-family: var(--font-mono);
font-size: 12px;
text-decoration: none;
}
.ct-tile:hover,
.ct-tile:focus-visible {
outline: 2px solid var(--text-primary);
outline-offset: 1px;
}
.ct-tile-mark {
align-self: flex-end;
font-family: var(--font-body);
font-size: 13px;
font-weight: 700;
}
/* A state's colour, always with its sign beside it. */
.ct-ok { background: var(--success); color: #fff; }
.ct-bad { background: var(--danger); color: #fff; }
.ct-open { background: var(--warning-bg); border-color: var(--border-bright); color: var(--text-primary); }
.ct-partial { background: var(--info-bg); border-color: var(--border-bright); color: var(--text-primary); }
.ct-process { background: var(--bg-elevated); border-color: var(--border-bright); color: var(--text-secondary); }
.ct-hint,
.sh-hint {
color: var(--text-tertiary);
font-size: 12.5px;
}
.ct-crumbs {
/* The areas beside the open requirement; the panel goes below on a phone. */
.ct-layout {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 4px;
font-size: 13px;
align-items: flex-start;
gap: 16px;
}
.ct-crumbs a {
color: var(--accent);
}
.ct-back {
margin-left: auto;
}
.ct-detail {
.ct-areas {
flex: 999 1 560px;
min-width: 0;
display: grid;
grid-template-columns: repeat(auto-fill, minmax(min(100%, 260px), 1fr));
gap: 12px;
}
.ct-area {
display: grid;
align-content: start;
gap: 8px;
padding: 12px;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--bg-card);
}
.ct-area-name {
font-size: 14px;
font-weight: 600;
}
.ct-area-bar {
height: 6px;
}
.ct-chips {
list-style: none;
display: grid;
gap: 6px;
}
/* A requirement: its state's sign, its name, and its open findings. */
.ct-chip {
display: flex;
align-items: center;
gap: 10px;
min-height: 44px;
padding: 8px 10px;
border: 1px solid transparent;
border-radius: var(--radius);
color: var(--text-primary);
font-size: 13.5px;
font-weight: 500;
line-height: 1.3;
text-decoration: none;
}
.ct-chip:hover {
border-color: var(--accent);
}
.ct-chip:focus-visible,
.ct-chip.is-selected {
outline: 2px solid var(--accent);
outline-offset: 2px;
}
.ct-chip-name {
flex: 1 1 auto;
min-width: 0;
}
.ct-chip-n {
flex-shrink: 0;
min-width: 22px;
height: 22px;
padding: 0 6px;
border-radius: 11px;
display: inline-flex;
align-items: center;
justify-content: center;
background: var(--bg-card);
color: var(--danger);
font-size: 12px;
font-weight: 700;
font-variant-numeric: tabular-nums;
}
.ct-chip.ct-ok { background: var(--success-bg); }
.ct-chip.ct-unknown { border-color: var(--border-bright); }
.ct-chip.ct-bad { background: var(--danger); border-color: var(--danger); color: #fff; font-weight: 600; }
.ct-chip.ct-partial { background: var(--warning-bg); border-color: var(--warning); }
.ct-chip.ct-open { background: var(--bg-elevated); border: 1px dashed var(--text-faint); color: var(--text-secondary); }
.ct-chip.ct-process { background: transparent; border: 1px dotted var(--text-faint); color: var(--text-secondary); }
/* A state's sign in a round mark: never colour alone. */
.ct-mark {
flex-shrink: 0;
width: 20px;
height: 20px;
border-radius: 50%;
display: inline-flex;
align-items: center;
justify-content: center;
box-sizing: border-box;
}
.ct-mark.ct-ok { background: var(--success); color: #fff; }
.ct-mark.ct-bad { background: var(--danger); color: #fff; }
.ct-mark.ct-partial { background: var(--warning); color: #fff; }
.ct-mark.ct-open { background: var(--bg-elevated); border: 1px dashed var(--text-faint); color: var(--text-secondary); }
.ct-mark.ct-process { background: var(--bg-card); border: 1px dotted var(--text-faint); color: var(--text-secondary); }
.ct-chip.ct-bad .ct-mark { background: #fff; color: var(--danger); }
/* The open requirement. */
.ct-panel {
flex: 1 1 320px;
min-width: 0;
max-width: 440px;
display: grid;
align-content: start;
gap: 14px;
padding: 16px;
border: 1px solid var(--border);
border-radius: var(--radius);
background: var(--bg-card);
}
.ct-panel-empty {
color: var(--text-tertiary);
font-size: 13.5px;
}
.ct-panel-head {
display: grid;
gap: 8px;
}
.ct-panel-area {
color: var(--text-tertiary);
font-size: 12.5px;
}
.ct-panel-name {
font-size: 20px;
font-weight: 600;
line-height: 1.25;
}
.ct-panel-state {
display: flex;
align-items: center;
gap: 8px;
font-size: 14px;
}
.ct-panel-what {
color: var(--text-secondary);
font-size: 14px;
line-height: 1.5;
}
.ct-meanings,
.ct-proof {
display: grid;
gap: 8px;
}
.ct-meanings h4,
.ct-proof h4 {
font-size: 13px;
font-weight: 600;
}
.ct-meanings ul {
list-style: none;
display: grid;
gap: 6px;
}
.ct-meaning {
display: flex;
align-items: flex-start;
gap: 10px;
padding: 8px 10px;
border: 1px solid var(--border);
border-radius: var(--radius);
font-size: 13.5px;
line-height: 1.45;
}
.ct-meaning div {
display: grid;
gap: 2px;
}
.ct-meaning span {
color: var(--text-secondary);
}
.ct-meaning.is-now {
border-color: var(--accent);
background: var(--bg-card-hover);
}
.ct-proof {
padding: 12px;
border: 1px dotted var(--text-faint);
border-radius: var(--radius);
font-size: 13.5px;
line-height: 1.45;
color: var(--text-secondary);
}
.ct-panel-detail:empty {
display: none;
}
.ct-panel-links {
display: flex;
flex-wrap: wrap;
gap: 8px 16px;
}
/* ── Verlauf: per scan, new CVEs above the line, gone below (#957) ── */
.sh-swatch {
display: inline-block;
@@ -8402,10 +8553,6 @@ span.repo-crumb-name {
margin-top: 0;
}
.vex-advisory-line .vex-advisory {
display: inline;
}
.vex-advisory-note {
font-size: 11px;
color: var(--text-tertiary);
@@ -2,12 +2,22 @@ use dioxus::prelude::*;
use dioxus_free_icons::icons::bs_icons::*;
use dioxus_free_icons::Icon;
use crate::i18n::texts::common;
use crate::i18n::use_lang;
/// A small copy-to-clipboard button that shows a checkmark after copying.
///
/// Usage: `CopyButton { value: "text to copy" }`
#[component]
pub fn CopyButton(value: String, #[props(default = false)] small: bool) -> Element {
let lang = use_lang()();
let mut copied = use_signal(|| false);
let label = if copied() {
common::COPIED
} else {
common::COPY
};
let tip = format!("{}: {value}", label.get(lang));
let size = if small { 12 } else { 14 };
let class = if small {
@@ -19,7 +29,9 @@ pub fn CopyButton(value: String, #[props(default = false)] small: bool) -> Eleme
rsx! {
button {
class: class,
title: if copied() { "Copied!" } else { "Copy to clipboard" },
r#type: "button",
title: "{tip}",
"aria-label": "{tip}",
onclick: move |_| {
let val = value.clone();
// Escape for JS single-quoted string
+313 -110
View File
@@ -1,37 +1,90 @@
//! The CRA Annex I view of a target (#957): its 40 requirements as tiles,
//! coloured by state and marked with a sign, so the state is never told by
//! colour alone. A tile opens the requirement with what its state rests on.
//! The CRA Annex I view of a target (#957): its 40 requirements by name,
//! grouped by area, each marked with its state's colour and sign so the
//! state is never told by colour alone. A requirement opens beside the map
//! with what its colour means for it and what the state rests on.
use compliance_core::cra_requirements::{self as cra, CraArea, CraRequirement};
use dioxus::prelude::*;
use crate::app::Route;
use crate::components::cra_bar::CraBar;
use crate::i18n::texts::{common, compliance, cra_tiles as tx};
use crate::i18n::use_lang;
use crate::infrastructure::evidence::fetch_compliance;
use crate::pages::compliance::{ControlRow, STATES};
use crate::i18n::{use_lang, Lang, Text};
use crate::infrastructure::evidence::{fetch_compliance, CraCounts};
use crate::pages::compliance::{requirement_name, ControlRow, STATES};
use crate::pages::target_views::RepoView;
/// A tile's sign and CSS tone for a control `state` (as the API names it).
/// A state's sign (an SVG path) and CSS tone, for a control `state` as the
/// API names it.
fn mark(state: &str) -> (&'static str, &'static str) {
match state {
"not_satisfied" => ("!", "ct-bad"),
"not_assessed" => ("?", "ct-open"),
"partial" => ("~", "ct-partial"),
"no_violation_found" => ("OK", "ct-ok"),
_ => ("–", "ct-process"),
"not_satisfied" => ("M12 5v9M12 19v.5", "ct-bad"),
"partial" => ("M5 12h14", "ct-partial"),
"no_violation_found" => ("M5 12.5l4.5 4.5L19 7.5", "ct-ok"),
"not_assessed" => ("M9 9a3 3 0 1 1 4 2.8c-.7.3-1 .9-1 1.7M12 18v.5", "ct-open"),
_ => ("M7 4h7l4 4v12H7zM14 4v4h4M10 13h5M10 16h5", "ct-process"),
}
}
/// The short name a tile shows for control `id`: `cra-ai-7` is `AI-07`;
/// another id stays as it is.
fn short_id(id: &str) -> String {
id.strip_prefix("cra-ai-")
.and_then(|n| n.parse::<u32>().ok())
.map_or_else(|| id.to_string(), |n| format!("AI-{n:02}"))
/// The CSS tone of a requirement in `state`, or of one whose state is not
/// known (`None`).
pub(crate) fn cra_tone(state: Option<&str>) -> &'static str {
state.map_or("ct-unknown", |s| mark(s).1)
}
/// `controls` in tile order: by the number of their id, others last.
fn in_tile_order(mut controls: Vec<serde_json::Value>) -> Vec<serde_json::Value> {
/// The CraBar segment class of a control `state`, so an area's small bar
/// uses the target bar's colours.
fn bar_modifier(state: &str) -> &'static str {
match state {
"not_satisfied" => "violated",
"not_assessed" => "open",
"partial" => "partial",
"no_violation_found" => "clear",
_ => "process",
}
}
/// A state's label (`Offene Befunde`).
fn state_label(state: &str, lang: Lang) -> &'static str {
STATES
.iter()
.find(|(s, _, _)| *s == state)
.map_or("", |(_, label, _)| label.get(lang))
}
/// The sign of `state` in a round mark of its tone.
#[component]
pub(crate) fn StateMark(state: String) -> Element {
let (path, tone) = mark(&state);
rsx! {
span { class: "ct-mark {tone}", "aria-hidden": "true",
svg {
width: "12",
height: "12",
view_box: "0 0 24 24",
fill: "none",
stroke: "currentColor",
stroke_width: "3",
stroke_linecap: "round",
stroke_linejoin: "round",
path { d: path }
}
}
}
}
/// One area of the map: the API's controls of that area, in id order.
struct AreaControls {
name: Text,
controls: Vec<serde_json::Value>,
}
/// `controls` (the compliance API's) grouped by area in the catalog's order;
/// a control outside the 40 goes to a last group of its own.
fn by_area(controls: &[serde_json::Value]) -> Vec<AreaControls> {
let requirement = |c: &serde_json::Value| -> Option<&'static CraRequirement> {
c["control"].as_str().and_then(cra::requirement)
};
let number = |c: &serde_json::Value| {
c["control"]
.as_str()
@@ -39,12 +92,69 @@ fn in_tile_order(mut controls: Vec<serde_json::Value>) -> Vec<serde_json::Value>
.and_then(|n| n.parse::<u32>().ok())
.unwrap_or(u32::MAX)
};
controls.sort_by_key(number);
controls
let mut areas: Vec<AreaControls> = CraArea::ALL
.iter()
.map(|area| {
let mut list: Vec<serde_json::Value> = controls
.iter()
.filter(|c| requirement(c).is_some_and(|r| r.area == *area))
.cloned()
.collect();
list.sort_by_key(number);
AreaControls {
name: area.name().into(),
controls: list,
}
})
.filter(|a| !a.controls.is_empty())
.collect();
let others: Vec<serde_json::Value> = controls
.iter()
.filter(|c| requirement(c).is_none())
.cloned()
.collect();
if !others.is_empty() {
areas.push(AreaControls {
name: tx::OTHER_AREA,
controls: others,
});
}
areas
}
/// The tiles of target `target_id`, or, with `control` (from the URL) set,
/// that requirement with its state, findings and reasons.
/// The number of open findings `control` lists.
fn finding_count(control: &serde_json::Value) -> usize {
control["findings"].as_array().map_or(0, Vec::len)
}
/// What the state of `control` means right now, in one sentence.
fn state_sentence(control: &serde_json::Value, lang: Lang) -> String {
let req = control["control"].as_str().and_then(cra::requirement);
match control["state"].as_str().unwrap_or_default() {
"not_satisfied" => {
let against = req
.and_then(|r| r.against)
.map_or(tx::AGAINST_GENERIC, Text::from);
format!(
"{} {}",
tx::against_count(finding_count(control), lang),
against.get(lang)
)
}
"no_violation_found" => req
.and_then(|r| r.clear)
.map_or(tx::CLEAR_GENERIC, Text::from)
.get(lang)
.to_string(),
"partial" => Text::from(cra::PARTLY_CHECKED).get(lang).to_string(),
"not_assessed" => compliance::not_assessed_reason(&control["reason"], lang)
.unwrap_or_else(|| tx::OPEN_GENERIC.get(lang).to_string()),
_ => tx::PROCESS_GENERIC.get(lang).to_string(),
}
}
/// The map of target `target_id`'s requirements, with `control` (from the
/// URL) open beside it.
#[component]
pub fn CraTiles(target_id: String, control: Option<String>) -> Element {
let lang = use_lang()();
@@ -59,7 +169,9 @@ pub fn CraTiles(target_id: String, control: Option<String>) -> Element {
let Some(data) = loaded else {
return rsx! { div { class: "card", p { {tx::LOAD_FAILED.get(lang)} } } };
};
let controls = in_tile_order(data["controls"].as_array().cloned().unwrap_or_default());
let controls = data["controls"].as_array().cloned().unwrap_or_default();
let counts: CraCounts = serde_json::from_value(data["counts"].clone()).unwrap_or_default();
let areas = by_area(&controls);
let to_tile = |control: Option<String>| Route::TargetViewsPage {
id: target_id.clone(),
view: RepoView::Cra.slug().to_string(),
@@ -68,96 +180,152 @@ pub fn CraTiles(target_id: String, control: Option<String>) -> Element {
control,
scan: None,
};
if let Some(wanted) = control {
let back = to_tile(None);
let Some(chosen) = controls
let chosen = control.as_ref().map(|wanted| {
controls
.iter()
.find(|c| c["control"].as_str() == Some(wanted.as_str()))
.cloned()
else {
return rsx! {
div { class: "card",
p { {tx::UNKNOWN.get(lang)} }
Link { class: "repo-view-list", to: back, {tx::BACK.get(lang)} }
}
};
};
let state = chosen["state"].as_str().unwrap_or_default().to_string();
let (label, badge) = STATES
.iter()
.find(|(s, _, _)| *s == state)
.map_or(("", "badge"), |(_, label, badge)| (label.get(lang), *badge));
return rsx! {
nav { class: "ct-crumbs", "aria-label": tx::BREADCRUMB.get(lang),
Link { to: back.clone(), "CRA" }
span { "aria-hidden": "true", " › " }
strong { "{short_id(&wanted)} {chosen[\"title\"].as_str().unwrap_or_default()}" }
Link { class: "btn btn-sm btn-ghost ct-back", to: back, {tx::BACK.get(lang)} }
}
section { class: "card ct-detail",
p { span { class: "{badge}", "{label}" } }
ul { class: "cra-controls",
ControlRow { control: chosen, lang, show_reason: true }
}
Link {
class: "repo-view-list",
to: Route::CompliancePage { id: target_id.clone() },
{tx::ALL_REQUIREMENTS.get(lang)}
}
}
};
}
});
rsx! {
section { class: "card ct-card", "aria-label": tx::TITLE.get(lang),
div { class: "ct-head",
h3 { class: "ct-title", {tx::title(controls.len(), lang)} }
div { class: "ct-legend",
for (state, label, _) in STATES {
{
let (sign, tone) = mark(state);
let n = controls.iter().filter(|c| c["state"].as_str() == Some(state)).count();
rsx! {
span { key: "{state}", class: "ct-legend-item",
span { class: "ct-swatch {tone}", "aria-hidden": "true", "{sign}" }
"{label.get(lang)} ({n})"
CraBar { counts }
p { class: "ct-hint", {compliance::NOT_LEGAL_ADVICE.get(lang)} }
}
div { class: "ct-layout",
div { class: "ct-areas",
for area in areas {
section { class: "ct-area", "aria-label": area.name.get(lang),
h4 { class: "ct-area-name", {area.name.get(lang)} }
div { class: "cra-bar-track ct-area-bar", "aria-hidden": "true",
for (state, _, _) in STATES {
{
let n = area.controls.iter().filter(|c| c["state"].as_str() == Some(state)).count();
rsx! {
if n > 0 {
span { class: "cra-bar-seg cra-{bar_modifier(state)}", style: "flex: {n} 0 0;" }
}
}
}
}
}
ul { class: "ct-chips",
for c in area.controls.iter() {
{
let cid = c["control"].as_str().unwrap_or_default().to_string();
let state = c["state"].as_str().unwrap_or_default().to_string();
let (_, tone) = mark(&state);
let selected = control.as_deref() == Some(cid.as_str());
let n = finding_count(c);
let name = requirement_name(c, lang);
let label = state_label(&state, lang);
rsx! {
li { key: "{cid}",
Link {
class: if selected { "ct-chip {tone} is-selected" } else { "ct-chip {tone}" },
"aria-current": if selected { "true" } else { "false" },
to: to_tile(Some(cid.clone())),
StateMark { state: state.clone() }
span { class: "ct-chip-name", "{name}" }
if n > 0 {
span { class: "ct-chip-n", "{n}" }
}
span { class: "sr-only", ", {label}" }
}
}
}
}
}
}
}
}
}
aside { class: "ct-panel", "aria-label": tx::SELECTED.get(lang),
match chosen {
None => rsx! { p { class: "ct-panel-empty", {tx::PICK.get(lang)} } },
Some(None) => rsx! {
p { {tx::UNKNOWN.get(lang)} }
Link { class: "repo-view-list", to: to_tile(None), {tx::CLOSE.get(lang)} }
},
Some(Some(c)) => rsx! {
RequirementPanel { control: c, lang, close: to_tile(None), all: Route::CompliancePage { id: target_id.clone() } }
},
}
}
}
div { class: "ct-grid",
for c in controls.iter() {
{
let id = c["control"].as_str().unwrap_or_default().to_string();
let state = c["state"].as_str().unwrap_or_default();
let (sign, tone) = mark(state);
let state_label = STATES
.iter()
.find(|(s, _, _)| *s == state)
.map_or("", |(_, label, _)| label.get(lang));
let tip = format!(
"{}: {} ({state_label})",
short_id(&id),
c["title"].as_str().unwrap_or_default()
);
rsx! {
Link {
key: "{id}",
class: "ct-tile {tone}",
title: "{tip}",
"aria-label": "{tip}",
to: to_tile(Some(id.clone())),
span { class: "ct-tile-id", "{short_id(&id)}" }
span { class: "ct-tile-mark", "{sign}" }
}
}
}
/// The open requirement: its name and state, what each colour means for it
/// (or the document that proves it), and what its state rests on.
#[component]
fn RequirementPanel(control: serde_json::Value, lang: Lang, close: Route, all: Route) -> Element {
let req = control["control"].as_str().and_then(cra::requirement);
let state = control["state"].as_str().unwrap_or_default().to_string();
let area = req.map(|r| Text::from(r.area.name()).get(lang));
let name = requirement_name(&control, lang);
let sentence = state_sentence(&control, lang);
// Red, orange, green: what each would mean for this requirement.
let meanings: Vec<(&str, Text, Text)> = req
.and_then(|r| r.against.zip(r.clear))
.map(|(against, clear)| {
vec![
("not_satisfied", tx::RED, against.into()),
("partial", tx::ORANGE, cra::PARTLY_CHECKED.into()),
("no_violation_found", tx::GREEN, clear.into()),
]
})
.unwrap_or_default();
let proof = req.and_then(|r| r.proof).map(Text::from);
rsx! {
div { class: "ct-panel-head",
if let Some(area) = area {
span { class: "ct-panel-area", "{area}" }
}
h3 { class: "ct-panel-name", "{name}" }
p { class: "ct-panel-state",
StateMark { state: state.clone() }
strong { {state_label(&state, lang)} }
}
p { class: "ct-panel-what", "{sentence}" }
}
if !meanings.is_empty() {
div { class: "ct-meanings",
h4 { {tx::MEANINGS.get(lang)} }
ul {
for (meaning_state, colour, text) in meanings {
li { class: if meaning_state == state { "ct-meaning is-now" } else { "ct-meaning" },
StateMark { state: meaning_state.to_string() }
div {
strong {
{colour.get(lang)}
if meaning_state == state {
{tx::NOW.get(lang)}
}
}
span { {text.get(lang)} }
}
}
}
}
}
p { class: "ct-hint", {tx::HINT.get(lang)} " " {compliance::NOT_LEGAL_ADVICE.get(lang)} }
}
if let Some(proof) = proof {
div { class: "ct-proof",
h4 { {tx::PROOF_TITLE.get(lang)} }
p { {tx::proof(proof.get(lang), lang)} }
}
}
ul { class: "cra-controls ct-panel-detail",
ControlRow { control, lang, show_reason: false, headless: true }
}
div { class: "ct-panel-links",
Link { class: "repo-view-list", to: close, {tx::CLOSE.get(lang)} }
Link { class: "repo-view-list", to: all, {tx::ALL_REQUIREMENTS.get(lang)} }
}
}
}
@@ -167,25 +335,60 @@ mod tests {
use super::*;
#[test]
fn a_tile_names_its_requirement_short_and_in_number_order() {
assert_eq!(short_id("cra-ai-7"), "AI-07");
assert_eq!(short_id("cra-ai-40"), "AI-40");
assert_eq!(short_id("custom"), "custom");
let ordered = in_tile_order(vec![
serde_json::json!({ "control": "cra-ai-10" }),
serde_json::json!({ "control": "other" }),
serde_json::json!({ "control": "cra-ai-2" }),
]);
let ids: Vec<&str> = ordered
fn controls_are_grouped_by_area_in_id_order() {
let controls = vec![
serde_json::json!({ "control": "cra-ai-9" }),
serde_json::json!({ "control": "custom" }),
serde_json::json!({ "control": "cra-ai-7" }),
serde_json::json!({ "control": "cra-ai-1" }),
];
let areas = by_area(&controls);
let ids: Vec<Vec<&str>> = areas
.iter()
.filter_map(|c| c["control"].as_str())
.map(|a| {
a.controls
.iter()
.filter_map(|c| c["control"].as_str())
.collect()
})
.collect();
assert_eq!(ids, ["cra-ai-2", "cra-ai-10", "other"]);
assert_eq!(
ids,
[
vec!["cra-ai-1"],
vec!["cra-ai-7", "cra-ai-9"],
vec!["custom"]
]
);
assert_eq!(areas[0].name.de, "Sicher entworfen");
assert_eq!(areas[2].name, tx::OTHER_AREA);
}
#[test]
fn every_state_has_its_own_sign() {
let signs: Vec<&str> = STATES.iter().map(|(s, _, _)| mark(s).0).collect();
assert_eq!(signs, ["!", "?", "~", "OK", "–"]);
let mut signs: Vec<&str> = STATES.iter().map(|(s, _, _)| mark(s).0).collect();
signs.sort_unstable();
signs.dedup();
assert_eq!(signs.len(), STATES.len());
}
#[test]
fn the_sentence_says_what_the_state_means_for_the_requirement() {
let red = serde_json::json!({
"control": "cra-ai-8", "state": "not_satisfied",
"findings": [{ "id": "a" }, { "id": "b" }],
});
let text = state_sentence(&red, Lang::De);
assert!(text.starts_with("2 offene Befunde"), "{text}");
assert!(text.contains("fest eingebautes Passwort"), "{text}");
let green = serde_json::json!({ "control": "cra-ai-8", "state": "no_violation_found" });
assert_eq!(
state_sentence(&green, Lang::En),
"The scan found no built-in password."
);
let process = serde_json::json!({ "control": "cra-ai-36", "state": "not_code_checkable" });
assert_eq!(state_sentence(&process, Lang::De), tx::PROCESS_GENERIC.de);
}
}
+76 -43
View File
@@ -3,13 +3,15 @@
//! The help assistant answers in markdown, and semgrep rule messages are
//! markdown (the finding description). Neither is ours, so nothing in it may
//! reach the page as markup of its own: raw HTML is shown as text, and links
//! keep only web and mail targets.
//! keep only Breakpilot's own pages, relative paths and mail targets.
//! Prüfwerk sends nobody to another site: a link anywhere else (an advisory
//! database, a vendor page) is shown as its text, and an image from another
//! site as its description.
use pulldown_cmark::{CowStr, Event, Options, Parser, Tag};
use pulldown_cmark::{CowStr, Event, Options, Parser, Tag, TagEnd};
/// Link targets kept as they are; anything else (`javascript:`, `data:`, …)
/// becomes an inert `#`.
const SAFE_SCHEMES: &[&str] = &["https://", "http://", "mailto:"];
/// The domain whose pages (and subdomains) a link may open.
const OWN_DOMAIN: &str = "breakpilot.com";
/// Render `markdown` to HTML that is safe to insert into the page.
///
@@ -19,8 +21,9 @@ const SAFE_SCHEMES: &[&str] = &["https://", "http://", "mailto:"];
///
/// # Returns
///
/// HTML with every raw HTML tag escaped and every link pointing at a web
/// address, a mail address, a relative path, or `#`.
/// HTML with every raw HTML tag escaped and every link pointing at a
/// Breakpilot page, a mail address or a relative path; other links are left
/// as their text.
///
/// # Examples
///
@@ -29,47 +32,50 @@ const SAFE_SCHEMES: &[&str] = &["https://", "http://", "mailto:"];
/// ```
pub fn render_markdown(markdown: &str) -> String {
let options = Options::ENABLE_TABLES | Options::ENABLE_STRIKETHROUGH;
let events = Parser::new_ext(markdown, options).map(|event| match event {
// Links and images do not nest, so one flag per kind says whether the
// open one was dropped and its end tag must go too.
let (mut link_dropped, mut image_dropped) = (false, false);
let events = Parser::new_ext(markdown, options).filter_map(move |event| match event {
// Shown as the text it is; `push_html` escapes text.
Event::Html(html) | Event::InlineHtml(html) => Event::Text(html),
Event::Start(Tag::Link {
link_type,
dest_url,
title,
id,
}) => Event::Start(Tag::Link {
link_type,
dest_url: safe_url(dest_url),
title,
id,
}),
Event::Start(Tag::Image {
link_type,
dest_url,
title,
id,
}) => Event::Start(Tag::Image {
link_type,
dest_url: safe_url(dest_url),
title,
id,
}),
other => other,
Event::Html(html) | Event::InlineHtml(html) => Some(Event::Text(html)),
Event::Start(Tag::Link { ref dest_url, .. }) => {
link_dropped = !allowed(dest_url);
(!link_dropped).then_some(event)
}
Event::End(TagEnd::Link) => (!std::mem::take(&mut link_dropped)).then_some(event),
// An image's inner text is its description: a dropped image leaves it.
Event::Start(Tag::Image { ref dest_url, .. }) => {
image_dropped = !allowed(dest_url);
(!image_dropped).then_some(event)
}
Event::End(TagEnd::Image) => (!std::mem::take(&mut image_dropped)).then_some(event),
other => Some(other),
});
let mut html = String::with_capacity(markdown.len() * 3 / 2);
pulldown_cmark::html::push_html(&mut html, events);
html
}
/// `url` when it is a web or mail address or a relative path, else `#`.
fn safe_url(url: CowStr<'_>) -> CowStr<'_> {
/// Whether a link to `url` may stay a link: a relative path, a mail
/// address, or a web page on Breakpilot's own domain.
fn allowed(url: &CowStr<'_>) -> bool {
let lower = url.trim().to_ascii_lowercase();
let relative = !lower.contains(':');
if relative || SAFE_SCHEMES.iter().any(|scheme| lower.starts_with(scheme)) {
url
} else {
CowStr::Borrowed("#")
if lower.starts_with("mailto:") {
return true;
}
let Some(rest) = lower
.strip_prefix("https://")
.or_else(|| lower.strip_prefix("http://"))
else {
// `//host/…` is another site, `javascript:` and the like are not pages.
return !lower.contains(':') && !lower.starts_with("//");
};
// The host ends at the path, query or fragment; a `user@` before it and
// a port after it are not part of it.
let authority = rest.split(['/', '?', '#']).next().unwrap_or_default();
let host = authority.rsplit('@').next().unwrap_or_default();
let host = host.split(':').next().unwrap_or_default();
host == OWN_DOMAIN || host.ends_with(&format!(".{OWN_DOMAIN}"))
}
#[cfg(test)]
@@ -99,11 +105,38 @@ mod tests {
}
#[test]
fn script_links_are_made_inert() {
let html = render_markdown("[x](javascript:alert(1)) [y](https://example.com) [z](/guide)");
fn only_breakpilot_pages_and_relative_paths_stay_links() {
let html = render_markdown(
"[x](javascript:alert(1)) [osv](https://osv.dev/vulnerability/CVE-1) \
[docs](https://docs.breakpilot.com/pruefwerk/) [z](/guide) [m](mailto:a@b.example)",
);
assert!(!html.contains("javascript:"));
assert!(html.contains("href=\"#\""));
assert!(html.contains("href=\"https://example.com\""));
assert!(!html.contains("osv.dev"));
assert!(html.contains("osv"), "the text stays: {html}");
assert!(html.contains("href=\"https://docs.breakpilot.com/pruefwerk/\""));
assert!(html.contains("href=\"/guide\""));
assert!(html.contains("href=\"mailto:a@b.example\""));
}
#[test]
fn a_look_alike_host_is_another_site() {
for url in [
"https://breakpilot.com.evil.example/x",
"https://evilbreakpilot.com/x",
"https://breakpilot.com@evil.example/x",
"//evil.example/x",
] {
let html = render_markdown(&format!("[a]({url})"));
assert!(!html.contains("href"), "{url}: {html}");
}
let html = render_markdown("[a](https://user@cloud.breakpilot.com:443/x)");
assert!(html.contains("href"), "{html}");
}
#[test]
fn an_image_from_another_site_leaves_its_description() {
let html = render_markdown("![diagram](https://evil.example/p.png)");
assert!(!html.contains("<img"));
assert!(html.contains("diagram"));
}
}
@@ -2,6 +2,8 @@ use dioxus::prelude::*;
use dioxus_free_icons::icons::bs_icons::*;
use dioxus_free_icons::Icon;
use crate::components::copy_button::CopyButton;
use crate::infrastructure::notifications::{
dismiss_notification, fetch_notification_count, fetch_notifications,
mark_all_notifications_read,
@@ -118,12 +120,10 @@ pub fn NotificationBell() -> Element {
span { class: "notification-sev {sev_class}",
"{notif.severity.to_uppercase()}"
}
// The id to copy, never a link off-site.
span { class: "notification-cve-id",
if let Some(ref url) = notif.url {
a { href: "{url}", target: "_blank", "{notif.cve_id}" }
} else {
"{notif.cve_id}"
}
"{notif.cve_id}"
CopyButton { value: notif.cve_id.clone(), small: true }
}
if let Some(score) = notif.cvss_score {
span { class: "notification-cvss", "CVSS {score:.1}" }
@@ -15,6 +15,7 @@ use compliance_core::cve_matrix::CveFilter;
use compliance_core::models::{CveAlert, SupplierVex, VexAssessment, VexJustification, VexStatus};
use compliance_core::vex_docs::status_of;
use crate::components::copy_button::CopyButton;
use crate::components::no_access::use_can_write;
use crate::components::severity_badge::SeverityBadge;
use crate::components::toast::{ToastType, Toasts};
@@ -182,6 +183,36 @@ pub(crate) fn is_supplier_product(alert: &CveAlert) -> bool {
/// agent stores it (`csaf_feed::SUPPLIER_PREFIX`).
pub(crate) const SUPPLIER_PROVIDER_PREFIX: &str = "supplier:";
/// A vendor advisory that names a CVE alert: its id to copy, the vendor's
/// remediation on hover, and a link to its page only where the provider's
/// terms require one (Siemens ProductCERT). Nothing else leads off-site.
#[component]
pub(crate) fn AdvisoryLine(advisory: compliance_core::models::AdvisoryRef) -> Element {
let lang = use_lang()();
let hint = advisory
.remediation
.clone()
.unwrap_or_else(|| advisory.title.clone());
rsx! {
div { class: "vex-advisory-line",
span { class: "vex-advisory", title: "{hint}", "{advisory.id}" }
CopyButton { value: advisory.id.clone(), small: true }
if let Some(url) = advisory.required_backlink() {
a {
class: "vex-advisory-source",
href: "{url}",
target: "_blank",
rel: "noopener noreferrer",
{tx::SOURCE.get(lang)}
}
}
if advisory.provider.starts_with(SUPPLIER_PROVIDER_PREFIX) {
span { class: "vex-advisory-note", {tx::SUPPLIER_ADVISORY.get(lang)} }
}
}
}
}
/// Who made an alert's statement: the person's name, "Prüfung" for a scan.
fn stated_by(alert: &CveAlert, lang: Lang) -> String {
match &alert.vex {
@@ -442,24 +473,13 @@ fn CveTable(
rsx! {
tr { key: "{alert_id}", class: if open { "is-open" } else { "" },
td {
code { "{alert.cve_id}" }
// The vendor advisories that name it (#515), linked as
// their terms ask; the remediation on hover.
span { class: "vex-cve-id",
code { "{alert.cve_id}" }
CopyButton { value: alert.cve_id.clone(), small: true }
}
// The vendor advisories that name it (#515).
for adv in alert.advisories.iter() {
div { class: "vex-advisory-line",
a {
class: "vex-advisory",
href: adv.url.clone().unwrap_or_default(),
target: "_blank",
rel: "noopener noreferrer",
title: adv.remediation.clone().unwrap_or_else(|| adv.title.clone()),
"{adv.id}"
}
if adv.provider.starts_with(SUPPLIER_PROVIDER_PREFIX) {
" "
span { class: "vex-advisory-note", {tx::SUPPLIER_ADVISORY.get(lang)} }
}
}
AdvisoryLine { advisory: adv.clone() }
}
}
td {
+15
View File
@@ -70,6 +70,21 @@ impl Text {
}
}
impl From<compliance_core::cra_requirements::Words> for Text {
fn from(words: compliance_core::cra_requirements::Words) -> Self {
Self {
de: words.de,
en: words.en,
}
}
}
/// The name a customer reads for CRA requirement `id` (`cra-ai-8` is
/// `Keine Standardpasswörter`); an id outside the 40 stays as it is.
pub fn requirement_label(id: &str, lang: Lang) -> &str {
compliance_core::cra_requirements::name(id).map_or(id, |words| Text::from(words).get(lang))
}
/// The agent's refusal code in a server function's error message: the
/// first word of `error` that is one of `codes`, as in
/// `error running server function: label_taken (409) (details: None)`.
+100 -25
View File
@@ -17,6 +17,14 @@ pub mod common {
de: "Wird geladen …",
en: "Loading...",
};
pub const COPY: Text = Text {
de: "Kopieren",
en: "Copy",
};
pub const COPIED: Text = Text {
de: "Kopiert",
en: "Copied",
};
pub const PREVIOUS: Text = Text {
de: "Zurück",
en: "Previous",
@@ -3294,10 +3302,6 @@ pub mod sbom {
de: "Keine",
en: "None",
};
pub const VIEW_ADVISORY: Text = Text {
de: "Hinweis ansehen →",
en: "View advisory →",
};
pub const KEV_BADGE: Text = Text {
de: "Aktiv ausgenutzt (KEV)",
en: "Actively exploited (KEV)",
@@ -3650,6 +3654,10 @@ pub mod vex {
de: "Laut Lieferant",
en: "Per the supplier",
};
pub const SOURCE: Text = Text {
de: "Quelle",
en: "Source",
};
pub const SUPPLIER_ADVISORY: Text = Text {
de: "Hinweis des Zulieferers",
en: "Supplier advisory",
@@ -4145,26 +4153,26 @@ pub mod compliance {
en: "Show CRA status",
};
pub const NOT_SATISFIED: Text = Text {
de: "Befunde zugeordnet",
en: "Findings mapped",
de: "Offene Befunde",
en: "Open findings",
};
pub const NO_VIOLATION: Text = Text {
de: "Geprüft, keine Befunde",
en: "Checked, no findings",
de: "Nichts gefunden",
en: "Nothing found",
};
pub const VIOLATED_COUNT: Text = Text {
de: "mit Befunden",
en: "with findings",
};
pub const NOT_ASSESSED: Text = Text {
de: "Nicht geprüft",
en: "Not checked",
de: "Noch nicht geprüft",
en: "Not checked yet",
};
/// A control checked on part of what it covers (a Yocto recipe
/// inventory instead of the image's SBOM).
pub const PARTIAL: Text = Text {
de: "Teilweise geprüft",
en: "Partly checked",
de: "Nur teilweise geprüft",
en: "Only partly checked",
};
pub const RECIPE_INVENTORY_ONLY: Text = Text {
de: "Nur das Yocto-Rezeptinventar, nicht die SBOM des Images: geprüft sind die Rezepte im Layer-Baum, nicht was das Image enthält. Vollständig erst mit der SBOM aus dem Build.",
@@ -4212,8 +4220,8 @@ pub mod compliance {
en: "CVE lookup",
};
pub const NOT_CODE_CHECKABLE: Text = Text {
de: "Nicht im Code prüfbar",
en: "Not checkable in code",
de: "Nachweis per Dokument",
en: "Proven by a document",
};
pub const SHOW_REQUIREMENTS: Text = Text {
de: "Anforderungen anzeigen",
@@ -7188,22 +7196,22 @@ pub mod cra_tiles {
de: "CRA Annex I",
en: "CRA Annex I",
};
pub const BREADCRUMB: Text = Text {
de: "Anforderung",
en: "Requirement",
pub const SELECTED: Text = Text {
de: "Ausgewählte Anforderung",
en: "Selected requirement",
};
pub const HINT: Text = Text {
de: "Klick auf eine Kachel: die Anforderung mit den Befunden und Gründen dahinter.",
en: "Click a tile: the requirement with the findings and reasons behind it.",
};
pub const BACK: Text = Text {
de: "← Zurück zum Raster",
en: "← Back to the grid",
pub const PICK: Text = Text {
de: "Klicken Sie auf eine Anforderung: Hier steht dann, was ihre Farbe bedeutet und worauf sie beruht.",
en: "Click a requirement: this shows what its colour means and what it rests on.",
};
pub const UNKNOWN: Text = Text {
de: "Diese Anforderung gibt es für dieses Prüfobjekt nicht.",
en: "This target has no such requirement.",
};
pub const CLOSE: Text = Text {
de: "Schließen",
en: "Close",
};
pub const ALL_REQUIREMENTS: Text = Text {
de: "Alle Anforderungen als Liste",
en: "All requirements as a list",
@@ -7212,14 +7220,81 @@ pub mod cra_tiles {
de: "Der CRA-Stand konnte nicht geladen werden.",
en: "The CRA status could not be loaded.",
};
pub const OTHER_AREA: Text = Text {
de: "Weitere Anforderungen",
en: "Other requirements",
};
pub const MEANINGS: Text = Text {
de: "Was die Farben hier bedeuten",
en: "What the colours mean here",
};
pub const NOW: Text = Text {
de: ": so ist es jetzt",
en: ": this is how it is now",
};
pub const RED: Text = Text {
de: "Rot",
en: "Red",
};
pub const ORANGE: Text = Text {
de: "Orange",
en: "Orange",
};
pub const GREEN: Text = Text {
de: "Grün",
en: "Green",
};
pub const PROOF_TITLE: Text = Text {
de: "Nachweis per Dokument",
en: "Proven by a document",
};
pub const AGAINST_GENERIC: Text = Text {
de: "Sie sprechen gegen diese Anforderung.",
en: "They count against this requirement.",
};
pub const CLEAR_GENERIC: Text = Text {
de: "Der Scan fand nichts, was dagegen spricht.",
en: "The scan found nothing against it.",
};
pub const OPEN_GENERIC: Text = Text {
de: "Noch nicht geprüft: Es ist noch kein Scan gelaufen, oder keine Regel deckt dieses Prüfobjekt ab.",
en: "Not checked yet: no scan has run, or no rule covers this target.",
};
pub const PROCESS_GENERIC: Text = Text {
de: "Diese Anforderung betrifft Ihre Abläufe und Ihren Entwurf, nicht einzelne Codezeilen.",
en: "This requirement is about your processes and design, not single lines of code.",
};
/// The grid's heading: `CRA Annex I: 40 Anforderungen`.
/// The map's heading: `CRA Annex I: 40 Anforderungen`.
pub fn title(count: usize, lang: Lang) -> String {
match lang {
Lang::De => format!("CRA Annex I: {count} Anforderungen"),
Lang::En => format!("CRA Annex I: {count} requirements"),
}
}
/// How many open findings count against a requirement, as a sentence.
pub fn against_count(count: usize, lang: Lang) -> String {
match (lang, count) {
(Lang::De, 1) => "Ein offener Befund spricht dagegen.".to_string(),
(Lang::De, n) => format!("{n} offene Befunde sprechen dagegen."),
(Lang::En, 1) => "One open finding counts against it.".to_string(),
(Lang::En, n) => format!("{n} open findings count against it."),
}
}
/// The proof a requirement no scan decides asks for: `doc` is the
/// document (`ein Rechtekonzept`).
pub fn proof(doc: &str, lang: Lang) -> String {
match lang {
Lang::De => format!(
"Ein Code-Scan kann diese Anforderung nicht entscheiden. Sie weisen sie mit einem Dokument nach: {doc}."
),
Lang::En => format!(
"A code scan cannot decide this requirement. You prove it with a document: {doc}."
),
}
}
}
/// The "Verlauf" of a target's views (#957): what each scan changed.
+27 -8
View File
@@ -18,8 +18,8 @@ use crate::infrastructure::evidence::{fetch_compliance, CraCounts};
/// them: violated first, requirements evidenced outside the code last.
pub(crate) const STATES: [(&str, Text, &str); 5] = [
("not_satisfied", tx::NOT_SATISFIED, "badge badge-critical"),
("not_assessed", tx::NOT_ASSESSED, "badge badge-medium"),
("partial", tx::PARTIAL, "badge badge-info"),
("not_assessed", tx::NOT_ASSESSED, "badge badge-open"),
("partial", tx::PARTIAL, "badge badge-medium"),
(
"no_violation_found",
tx::NO_VIOLATION,
@@ -163,11 +163,29 @@ pub fn CompliancePage(id: String) -> Element {
}
}
/// One requirement: its id and title, the catalog's rating, and what the
/// state rests on (the findings against it, or why it was not assessed,
/// unless `show_reason` is off because the group states it once).
/// The name a customer reads for `control` (an entry of the compliance
/// API's `controls`): the requirement's name, else the catalog's title for
/// an id outside the 40, else the id.
pub(crate) fn requirement_name(control: &serde_json::Value, lang: Lang) -> String {
let id = control["control"].as_str().unwrap_or_default();
match compliance_core::cra_requirements::name(id) {
Some(words) => Text::from(words).get(lang).to_string(),
None => control["title"].as_str().unwrap_or(id).to_string(),
}
}
/// One requirement: its name, the catalog's rating, and what the state rests
/// on (the findings against it, or why it was not assessed, unless
/// `show_reason` is off because the group states it once). `headless` leaves
/// the name line out where the requirement is already named above.
#[component]
pub(crate) fn ControlRow(control: serde_json::Value, lang: Lang, show_reason: bool) -> Element {
pub(crate) fn ControlRow(
control: serde_json::Value,
lang: Lang,
show_reason: bool,
#[props(default)] headless: bool,
) -> Element {
let name = requirement_name(&control, lang);
let findings = control["findings"].as_array().cloned().unwrap_or_default();
// The control map's notes are engineering prose in English; in German
// the group's hint says the same.
@@ -186,8 +204,9 @@ pub(crate) fn ControlRow(control: serde_json::Value, lang: Lang, show_reason: bo
rsx! {
li { class: "cra-control",
div { class: "cra-control-head",
code { class: "cra-control-id", "{control[\"control\"].as_str().unwrap_or_default()}" }
span { class: "cra-control-title", "{control[\"title\"].as_str().unwrap_or_default()}" }
if !headless {
span { class: "cra-control-title", "{name}" }
}
if let Some(label) = severity_label {
span { class: "badge badge-{severity}", "{label}" }
}
@@ -4,11 +4,12 @@ use dioxus_free_icons::Icon;
use crate::app::Route;
use crate::components::code_snippet::CodeSnippet;
use crate::components::cra_tiles::{cra_tone, StateMark};
use crate::components::markdown::render_markdown;
use crate::components::page_header::PageHeader;
use crate::components::severity_badge::SeverityBadge;
use crate::i18n::texts::{common, finding_breakdown, findings as tx, graph as graph_tx};
use crate::i18n::{format_count, format_time, use_lang, Lang};
use crate::i18n::{format_count, format_time, requirement_label, use_lang, Lang};
use crate::infrastructure::evidence::{fetch_catalog_controls, CatalogControl};
use crate::infrastructure::findings::{location, mask_secrets, wire_name};
use crate::infrastructure::graph::fetch_impact;
@@ -127,11 +128,12 @@ pub fn FindingDetailPage(id: String) -> Element {
.as_ref()
.and_then(|d| d["target_name"].as_str())
.map(String::from);
let control_title = |id: &str| -> Option<String> {
// A requirement's state on the target, as the CRA map shows it.
let control_state = |id: &str| -> Option<String> {
status_data.as_ref()?["controls"]
.as_array()?
.iter()
.find(|c| c["control"].as_str() == Some(id))?["title"]
.find(|c| c["control"].as_str() == Some(id))?["state"]
.as_str()
.map(String::from)
};
@@ -143,8 +145,8 @@ pub fn FindingDetailPage(id: String) -> Element {
let cra_topics: Vec<(String, Option<String>)> = cra_refs
.into_iter()
.map(|c| {
let title = control_title(&c);
(c, title)
let state = control_state(&c);
(c, state)
})
.collect();
// Offer Breakpilot Git only once the agent said the target opens
@@ -309,11 +311,22 @@ pub fn FindingDetailPage(id: String) -> Element {
if !f.control_refs.is_empty() {
span { style: "opacity: 0.7;", {tx::CRA_REFS.get(lang)} }
ul { class: "finding-refs",
for (c, title) in cra_topics {
for (c, state) in cra_topics {
li {
span { class: "badge badge-info", "{c}" }
if let Some(title) = title {
span { " {title}" }
Link {
class: "ct-chip {cra_tone(state.as_deref())}",
to: Route::TargetViewsPage {
id: f.repo_id.clone(),
view: crate::pages::target_views::RepoView::Cra.slug().to_string(),
cve_severity: None,
cve_vex: None,
control: Some(c.clone()),
scan: None,
},
if let Some(state) = state.clone() {
StateMark { state }
}
span { class: "ct-chip-name", {requirement_label(&c, lang)} }
}
}
}
@@ -675,7 +688,7 @@ fn tracker_note(
/// # Arguments
///
/// * `finding` - the finding shown on the page
/// * `cra_topics` - its CRA control ids, each with its title when known
/// * `cra_topics` - its CRA requirement ids, each with its state when known
/// * `link` - the finding's page in Prüfwerk
/// * `lang` - the UI language, for the labels
///
@@ -720,11 +733,8 @@ fn ticket_markdown(
}
if !cra_topics.is_empty() {
md.push_str(&format!("\n### {}\n\n", tx::CRA_TOPICS.get(lang)));
for (id, title) in cra_topics {
match title {
Some(title) => md.push_str(&format!("- `{id}` {title}\n")),
None => md.push_str(&format!("- `{id}`\n")),
}
for (id, _) in cra_topics {
md.push_str(&format!("- {}\n", requirement_label(id, lang)));
}
}
md.push_str(&format!(
@@ -855,10 +865,7 @@ mod tests {
#[test]
fn the_ticket_text_holds_the_finding_and_a_link_back() {
let topics = vec![
(
"cra-ai-2c".to_string(),
Some("Schutz vor unbefugtem Zugriff".to_string()),
),
("cra-ai-8".to_string(), Some("not_satisfied".to_string())),
("cra-ai-2f".to_string(), None),
];
let md = ticket_markdown(
@@ -876,8 +883,8 @@ mod tests {
\n### Beschreibung\n\nDie Abfrage setzt Benutzereingaben direkt ein.\n\
\n### Einschätzung\n\nErreichbar über das Login-Formular.\n\
\n### CRA-Themen\n\n\
- `cra-ai-2c` Schutz vor unbefugtem Zugriff\n\
- `cra-ai-2f`\n\
- Keine Standardpasswörter\n\
- cra-ai-2f\n\
\n[Im Prüfwerk öffnen](https://pruefwerk.example/findings/abc)\n"
);
}
+7 -5
View File
@@ -16,7 +16,7 @@ use crate::components::toast::{ToastType, Toasts};
use crate::i18n::texts::{
common, finding_breakdown as breakdown_tx, finding_groups as gtx, findings as tx,
};
use crate::i18n::use_lang;
use crate::i18n::{requirement_label, use_lang};
use crate::infrastructure::findings::{has_control_refs, location, wire_name};
use compliance_core::finding_breakdown::OPEN_STATUS_FILTER;
@@ -436,9 +436,9 @@ pub fn FindingsPage(
if show_controls {
td {
{
// CRA Annex I refs by name; master controls
// (`mc-…`) only as a count, their detail is on
// the finding's page.
// CRA Annex I requirements by name; master
// controls (`mc-…`) only as a count, their
// detail is on the finding's page.
let (cra, other): (Vec<&String>, Vec<&String>) = finding
.control_refs
.iter()
@@ -446,7 +446,9 @@ pub fn FindingsPage(
rsx! {
div { class: "finding-controls",
for c in cra {
span { class: "badge badge-info", title: tx::CONTROLS_HINT.get(lang), "{c}" }
span { class: "finding-control", title: tx::CONTROLS_HINT.get(lang),
{requirement_label(c, lang)}
}
}
if !other.is_empty() {
span { class: "finding-controls-more",
+7 -15
View File
@@ -12,10 +12,11 @@ use compliance_core::scan_changes::ComponentRowKind;
use compliance_core::vex_docs::status_of;
use crate::app::Route;
use crate::components::copy_button::CopyButton;
use crate::components::severity_badge::SeverityBadge;
use crate::components::toast::{ToastType, Toasts};
use crate::components::vex_panel::{
is_supplier_product, status_class, status_text, supplier_gist, SUPPLIER_PROVIDER_PREFIX,
is_supplier_product, status_class, status_text, supplier_gist, AdvisoryLine,
};
use crate::i18n::texts::{common, cve_matrix, kinds, machine as tx, repo_views as rv};
use crate::i18n::{format_ago, format_count, format_time, use_lang, Lang};
@@ -477,21 +478,12 @@ fn MachineCveGroup(
rsx! {
tr { key: "{alert.repo_id}-{alert.cve_id}",
td {
code { "{alert.cve_id}" }
span { class: "vex-cve-id",
code { "{alert.cve_id}" }
CopyButton { value: alert.cve_id.clone(), small: true }
}
for adv in alert.advisories.iter() {
div { class: "vex-advisory-line",
a {
class: "vex-advisory",
href: adv.url.clone().unwrap_or_default(),
target: "_blank",
rel: "noopener noreferrer",
"{adv.id}"
}
if adv.provider.starts_with(SUPPLIER_PROVIDER_PREFIX) {
" "
span { class: "vex-advisory-note", {crate::i18n::texts::vex::SUPPLIER_ADVISORY.get(lang)} }
}
}
AdvisoryLine { advisory: adv.clone() }
}
}
td {
+3 -8
View File
@@ -4,6 +4,7 @@ use dioxus::prelude::*;
use crate::app::Route;
use crate::components::component_overview::ComponentOverview;
use crate::components::copy_button::CopyButton;
use crate::components::license_editor::{category_class, confirmed_title, LicenseEditor};
use crate::components::license_review::{
action_class, reasons_text, review_title, LicenseCheckPanel,
@@ -545,7 +546,9 @@ pub fn SbomPage(target: String, #[props(default)] ecosystem: String) -> Element
for vuln in &entry.known_vulnerabilities {
div { class: "sbom-vuln-card",
div { class: "sbom-vuln-card-header",
// The id to copy, never a link off-site.
span { class: "sbom-vuln-id", "{vuln.id}" }
CopyButton { value: vuln.id.clone(), small: true }
span { class: "sbom-vuln-source", "{vuln.source}" }
if let Some(sev) = &vuln.severity {
span {
@@ -573,14 +576,6 @@ pub fn SbomPage(target: String, #[props(default)] ecosystem: String) -> Element
"{tx::SSVC_EXPLOITATION.get(lang)}: {ssvc}"
}
}
if let Some(url) = &vuln.url {
a {
href: "{url}",
target: "_blank",
class: "sbom-vuln-link",
{tx::VIEW_ADVISORY.get(lang)}
}
}
}
}
if entry.known_vulnerabilities.iter().any(|v| v.exploitation.as_ref().is_some_and(|e| e.epss.is_some())) {