Skip to content

Commit e778c5b

Browse files
authored
CxOne: support Critical severity (#5418)
1 parent 6a715b8 commit e778c5b

File tree

6 files changed

+117
-12
lines changed

6 files changed

+117
-12
lines changed

cmd/checkmarxOneExecuteScan.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,7 @@ func (c *checkmarxOneExecuteScanHelper) getDetailedResults(scan *checkmarxOne.Sc
808808
resultMap["Preset"] = scanmeta.PresetName
809809
resultMap["DeepLink"] = fmt.Sprintf("%v/projects/%v/overview?branch=%v", c.config.ServerURL, c.Project.ProjectID, url.QueryEscape(scan.Branch))
810810
resultMap["ReportCreationTime"] = time.Now().String()
811+
resultMap["Critical"] = map[string]int{}
811812
resultMap["High"] = map[string]int{}
812813
resultMap["Medium"] = map[string]int{}
813814
resultMap["Low"] = map[string]int{}
@@ -817,6 +818,8 @@ func (c *checkmarxOneExecuteScanHelper) getDetailedResults(scan *checkmarxOne.Sc
817818
for _, result := range *results {
818819
key := "Information"
819820
switch result.Severity {
821+
case "CRITICAL":
822+
key = "Critical"
820823
case "HIGH":
821824
key = "High"
822825
case "MEDIUM":
@@ -1075,20 +1078,29 @@ func (c *checkmarxOneExecuteScanHelper) enforceThresholds(results *map[string]in
10751078
insecureResults := []string{}
10761079
insecure := false
10771080

1081+
cxCriticalThreshold := c.config.VulnerabilityThresholdCritical
10781082
cxHighThreshold := c.config.VulnerabilityThresholdHigh
10791083
cxMediumThreshold := c.config.VulnerabilityThresholdMedium
10801084
cxLowThreshold := c.config.VulnerabilityThresholdLow
10811085
cxLowThresholdPerQuery := c.config.VulnerabilityThresholdLowPerQuery
10821086
cxLowThresholdPerQueryMax := c.config.VulnerabilityThresholdLowPerQueryMax
1087+
criticalValue := (*results)["Critical"].(map[string]int)["NotFalsePositive"]
10831088
highValue := (*results)["High"].(map[string]int)["NotFalsePositive"]
10841089
mediumValue := (*results)["Medium"].(map[string]int)["NotFalsePositive"]
10851090
lowValue := (*results)["Low"].(map[string]int)["NotFalsePositive"]
10861091
var unit string
1092+
criticalViolation := ""
10871093
highViolation := ""
10881094
mediumViolation := ""
10891095
lowViolation := ""
10901096
if c.config.VulnerabilityThresholdUnit == "percentage" {
10911097
unit = "%"
1098+
criticalAudited := (*results)["Critical"].(map[string]int)["Issues"] - (*results)["Critical"].(map[string]int)["NotFalsePositive"]
1099+
criticalOverall := (*results)["Critical"].(map[string]int)["Issues"]
1100+
if criticalOverall == 0 {
1101+
criticalAudited = 1
1102+
criticalOverall = 1
1103+
}
10921104
highAudited := (*results)["High"].(map[string]int)["Issues"] - (*results)["High"].(map[string]int)["NotFalsePositive"]
10931105
highOverall := (*results)["High"].(map[string]int)["Issues"]
10941106
if highOverall == 0 {
@@ -1107,10 +1119,15 @@ func (c *checkmarxOneExecuteScanHelper) enforceThresholds(results *map[string]in
11071119
lowAudited = 1
11081120
lowOverall = 1
11091121
}
1122+
criticalValue = int(float32(criticalAudited) / float32(criticalOverall) * 100.0)
11101123
highValue = int(float32(highAudited) / float32(highOverall) * 100.0)
11111124
mediumValue = int(float32(mediumAudited) / float32(mediumOverall) * 100.0)
11121125
lowValue = int(float32(lowAudited) / float32(lowOverall) * 100.0)
11131126

1127+
if criticalValue < cxCriticalThreshold {
1128+
insecure = true
1129+
criticalViolation = fmt.Sprintf("<-- %v %v deviation", cxCriticalThreshold-criticalValue, unit)
1130+
}
11141131
if highValue < cxHighThreshold {
11151132
insecure = true
11161133
highViolation = fmt.Sprintf("<-- %v %v deviation", cxHighThreshold-highValue, unit)
@@ -1148,6 +1165,10 @@ func (c *checkmarxOneExecuteScanHelper) enforceThresholds(results *map[string]in
11481165
}
11491166
if c.config.VulnerabilityThresholdUnit == "absolute" {
11501167
unit = " findings"
1168+
if criticalValue > cxCriticalThreshold {
1169+
insecure = true
1170+
criticalViolation = fmt.Sprintf("<-- %v%v deviation", criticalValue-cxCriticalThreshold, unit)
1171+
}
11511172
if highValue > cxHighThreshold {
11521173
insecure = true
11531174
highViolation = fmt.Sprintf("<-- %v%v deviation", highValue-cxHighThreshold, unit)
@@ -1162,9 +1183,17 @@ func (c *checkmarxOneExecuteScanHelper) enforceThresholds(results *map[string]in
11621183
}
11631184
}
11641185

1186+
criticalText := fmt.Sprintf("Critical %v%v %v", criticalValue, unit, criticalViolation)
11651187
highText := fmt.Sprintf("High %v%v %v", highValue, unit, highViolation)
11661188
mediumText := fmt.Sprintf("Medium %v%v %v", mediumValue, unit, mediumViolation)
11671189
lowText := fmt.Sprintf("Low %v%v %v", lowValue, unit, lowViolation)
1190+
if len(criticalViolation) > 0 {
1191+
insecureResults = append(insecureResults, criticalText)
1192+
log.Entry().Error(criticalText)
1193+
} else {
1194+
neutralResults = append(neutralResults, criticalText)
1195+
log.Entry().Info(criticalText)
1196+
}
11681197
if len(highViolation) > 0 {
11691198
insecureResults = append(insecureResults, highText)
11701199
log.Entry().Error(highText)
@@ -1191,6 +1220,13 @@ func (c *checkmarxOneExecuteScanHelper) enforceThresholds(results *map[string]in
11911220
}
11921221

11931222
func (c *checkmarxOneExecuteScanHelper) reportToInflux(results *map[string]interface{}) {
1223+
c.influx.checkmarxOne_data.fields.critical_issues = (*results)["Critical"].(map[string]int)["Issues"]
1224+
c.influx.checkmarxOne_data.fields.critical_not_false_postive = (*results)["Critical"].(map[string]int)["NotFalsePositive"]
1225+
c.influx.checkmarxOne_data.fields.critical_not_exploitable = (*results)["Critical"].(map[string]int)["NotExploitable"]
1226+
c.influx.checkmarxOne_data.fields.critical_confirmed = (*results)["Critical"].(map[string]int)["Confirmed"]
1227+
c.influx.checkmarxOne_data.fields.critical_urgent = (*results)["Critical"].(map[string]int)["Urgent"]
1228+
c.influx.checkmarxOne_data.fields.critical_proposed_not_exploitable = (*results)["Critical"].(map[string]int)["ProposedNotExploitable"]
1229+
c.influx.checkmarxOne_data.fields.critical_to_verify = (*results)["Critical"].(map[string]int)["ToVerify"]
11941230

11951231
c.influx.checkmarxOne_data.fields.high_issues = (*results)["High"].(map[string]int)["Issues"]
11961232
c.influx.checkmarxOne_data.fields.high_not_false_postive = (*results)["High"].(map[string]int)["NotFalsePositive"]

cmd/checkmarxOneExecuteScan_generated.go

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/checkmarxone/checkmarxone.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1356,6 +1356,7 @@ func (sys *SystemInstance) RequestNewReportV2(scanID, reportType string) (string
13561356
"filters": map[string][]string{
13571357
"scanners": {"sast"},
13581358
"severities": {
1359+
"critical",
13591360
"high",
13601361
"medium",
13611362
"low",

pkg/checkmarxone/reporting.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,13 @@ func CreateCustomReport(data *map[string]interface{}, insecure, neutral []string
9494
WithCounter: false,
9595
}
9696
detailRows := []reporting.OverviewRow{
97+
{Description: "Critical issues", Details: fmt.Sprint((*data)["Critical"].(map[string]int)["Issues"])},
98+
{Description: "Critical not false positive issues", Details: fmt.Sprint((*data)["Critical"].(map[string]int)["NotFalsePositive"])},
99+
{Description: "Critical not exploitable issues", Details: fmt.Sprint((*data)["Critical"].(map[string]int)["NotExploitable"])},
100+
{Description: "Critical confirmed issues", Details: fmt.Sprint((*data)["Critical"].(map[string]int)["Confirmed"])},
101+
{Description: "Critical urgent issues", Details: fmt.Sprint((*data)["Critical"].(map[string]int)["Urgent"])},
102+
{Description: "Critical proposed not exploitable issues", Details: fmt.Sprint((*data)["Critical"].(map[string]int)["ProposedNotExploitable"])},
103+
{Description: "Critical to verify issues", Details: fmt.Sprint((*data)["Critical"].(map[string]int)["ToVerify"])},
97104
{Description: "High issues", Details: fmt.Sprint((*data)["High"].(map[string]int)["Issues"])},
98105
{Description: "High not false positive issues", Details: fmt.Sprint((*data)["High"].(map[string]int)["NotFalsePositive"])},
99106
{Description: "High not exploitable issues", Details: fmt.Sprint((*data)["High"].(map[string]int)["NotExploitable"])},
@@ -152,6 +159,13 @@ func CreateJSONHeaderReport(data *map[string]interface{}) CheckmarxOneReportData
152159
}
153160

154161
findings := []Finding{}
162+
// Critical
163+
criticalFindings := Finding{}
164+
criticalFindings.ClassificationName = "Critical"
165+
criticalFindings.Total = (*data)["Critical"].(map[string]int)["Issues"]
166+
criticalAudited := (*data)["Critical"].(map[string]int)["Issues"] - (*data)["Critical"].(map[string]int)["NotFalsePositive"]
167+
criticalFindings.Audited = &criticalAudited
168+
findings = append(findings, criticalFindings)
155169
// High
156170
highFindings := Finding{}
157171
highFindings.ClassificationName = "High"

pkg/checkmarxone/reporting_test.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,20 @@ func TestCreateJSONReport(t *testing.T) {
2121
resultMap["ProjectId"] = `f5702f86-b396-417f-82e2-4949a55d5382`
2222
resultMap["ScanId"] = `21e40b36-0dd7-48e5-9768-da1a8f36c907`
2323

24+
resultMap["Critical"] = map[string]int{}
2425
resultMap["High"] = map[string]int{}
2526
resultMap["Medium"] = map[string]int{}
2627
resultMap["Low"] = map[string]int{}
2728
resultMap["Information"] = map[string]int{}
29+
2830
submap := map[string]int{}
2931
submap["Issues"] = 10
3032
submap["NotFalsePositive"] = 10
33+
resultMap["Critical"] = submap
34+
35+
submap = map[string]int{}
36+
submap["Issues"] = 10
37+
submap["NotFalsePositive"] = 10
3138
resultMap["High"] = submap
3239

3340
submap = map[string]int{}
@@ -74,7 +81,7 @@ func TestCreateJSONReport(t *testing.T) {
7481
assert.Equal(t, "v1", reportingData.ToolVersion)
7582
assert.Equal(t, "Incremental", reportingData.ScanType)
7683

77-
lowList := (*reportingData.Findings)[2].LowPerQuery
84+
lowList := (*reportingData.Findings)[3].LowPerQuery
7885
lowListLen := len(*lowList)
7986
assert.Equal(t, 2, lowListLen)
8087

0 commit comments

Comments
 (0)