Skip to content

Commit

Permalink
Get severity from cvssv3
Browse files Browse the repository at this point in the history
  • Loading branch information
the-wright-jamie committed Jan 26, 2024
1 parent fc85717 commit 544d734
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ dependency-check-report.json
.scannerwork
sonar-project.properties
clip.json
src/dependency-check-report-npm.json
25 changes: 9 additions & 16 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ struct VulnerabilityId {
struct Vulnerability {
source: String,
name: String,
severity: SeverityKind,
cvssv2: Option<CVSSV2>,
severity: String,
cvssv3: CVSSV3,
cwes: Vec<Value>,
description: String,
notes: String,
Expand All @@ -125,15 +125,8 @@ enum SeverityKind {

#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
struct CVSSV2 {
score: f32,
access_vector: String,
access_complexity: String,
authenticationr: String,
confidential_impact: Option<String>,
integrity_impact: String,
availability_impact: String,
severity: String,
struct CVSSV3 {
base_severity: SeverityKind,
}

fn parse_json(file_path: &str) -> Result<ReportJson, Box<dyn Error>> {
Expand Down Expand Up @@ -179,14 +172,14 @@ fn print_severities(json: &ReportJson) {

for dependency in &json.dependencies {
for vulnerabilities in &dependency.vulnerabilities {
vulnerabilities
.iter()
.for_each(|vulnerability| match vulnerability.severity {
vulnerabilities.iter().for_each(|vulnerability| {
match vulnerability.cvssv3.base_severity {
SeverityKind::CRITICAL => critical_count += 1,
SeverityKind::HIGH => high_count += 1,
SeverityKind::MEDIUM => medium_count += 1,
SeverityKind::LOW => low_count += 1,
})
}
})
}
}

Expand Down Expand Up @@ -302,7 +295,7 @@ fn print_cves(json_to_process: &ReportJson) {
for vulnerability in vulnerabilities {
println!(
"{1} ({0})\n{2}\n",
coloured_severity(&vulnerability.severity),
coloured_severity(&vulnerability.cvssv3.base_severity),
vulnerability.name.red().bold(),
vulnerability.description
);
Expand Down

0 comments on commit 544d734

Please sign in to comment.