Skip to content

Commit 78643bc

Browse files
committed
Fix additional crash caused by new validation of severities in DefectDojo
DefectDojo apparently now validates that these are in the right format, nice 👍 Signed-off-by: Jannik Hollenbach <jannik.hollenbach@iteratec.com>
1 parent 1164ac1 commit 78643bc

3 files changed

Lines changed: 24 additions & 6 deletions

File tree

‎hooks/persistence-defectdojo/hook/src/main/java/io/securecodebox/persistence/mapping/SecureCodeBoxFindingsToDefectDojoMapper.java‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,25 @@ public static String fromSecureCodeboxFindingsJson(String scbFindingsJson) throw
5252
return ddFindingJson.toString();
5353
}
5454

55+
protected static String convertToDefectDojoSeverity(SecureCodeBoxFinding.Severities severity) {
56+
if (severity == null) {
57+
return "Info";
58+
}
59+
60+
switch (severity) {
61+
case HIGH:
62+
return "High";
63+
case MEDIUM:
64+
return "Medium";
65+
case LOW:
66+
return "Low";
67+
case INFORMATIONAL:
68+
return "Info";
69+
}
70+
71+
return "Info";
72+
}
73+
5574
/**
5675
* Converts a SecureCodeBox Finding to a DefectDojo Finding,
5776
* that can be imported by the DefectDojo Generic JSON Parser.
@@ -64,8 +83,7 @@ protected static DefectDojoImportFinding fromSecureCodeBoxFinding(SecureCodeBoxF
6483
//set basic Finding info
6584
DefectDojoImportFinding result = new DefectDojoImportFinding();
6685
result.setTitle(secureCodeBoxFinding.getName());
67-
if (secureCodeBoxFinding.getSeverity() != null)
68-
result.setSeverity(capitalize(secureCodeBoxFinding.getSeverity().toString()));
86+
result.setSeverity(convertToDefectDojoSeverity(secureCodeBoxFinding.getSeverity()));
6987
result.setUniqueIdFromTool(secureCodeBoxFinding.getId());
7088
// set DefectDojo description as combination of SecureCodeBox Finding description and Finding attributes
7189
String description = secureCodeBoxFinding.getDescription();

‎hooks/persistence-defectdojo/hook/src/test/java/io/securecodebox/persistence/mapping/SecureCodeBoxFindingsToDefectDojoMapperTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void yieldsCorrectResult() throws IOException {
4444
public void correctlyParsesFindings() throws IOException {
4545
var name = "Name";
4646
var description = "Description";
47-
var severity = "HIGH";
47+
var severity = "High";
4848
var id = "123";
4949
var parsedAt = "2020-04-15T12:27:28.153Z";
5050
var location = "ldap://[2001:db8::7]/c=GB?objectClass?one";

‎hooks/persistence-defectdojo/hook/src/test/resources/kubehunter-dd-findings.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"title": "Read access to pod's service account token",
55
"description": " Accessing the pod service account token gives an attacker the option to use the server API \n {\n \"evidence\" : \"eyJhbGciOiJSUzI1NiIsImtpZCI6IkxuOE9ZaGt1SFFabmwzN3ZEYlg1R2ZqX25VVWtnWUlnU0VOdExBbWE4VFEifQ.eyJpc3MiOiJrdWJlcm5ldGVzL3NlcnZpY2VhY2NvdW50Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9uYW1lc3BhY2UiOiJkZWZhdWx0Iiwia3ViZXJuZXRlcy5pby9zZXJ2aWNlYWNjb3VudC9zZWNyZXQubmFtZSI6Imx1cmNoZXItdG9rZW4tdjI4cWIiLCJrdWJlcm5ldGVzLmlvL3NlcnZpY2VhY2NvdW50L3NlcnZpY2UtYWNjb3VudC5uYW1lIjoibHVyY2hlciIsImt1YmVybmV0ZXMuaW8vc2VydmljZWFjY291bnQvc2VydmljZS1hY2NvdW50LnVpZCI6IjIzMTg2YTI5LTY0NDQtNGI3Ny1hZjA1LTY5YzcyYWViZWYwZCIsInN1YiI6InN5c3RlbTpzZXJ2aWNlYWNjb3VudDpkZWZhdWx0Omx1cmNoZXIifQ.IeiByhB-g3W6Zzr4_cEU2sdfyAHVwgnKn-apu8YVkS9886zSeg_BB4F-KsljFApt8gZA4gzLEMuDTEubURkD-omaWw6_eHkV_SfIiD69rvLFC-wTtLLxQijrfBa1ZJ6PxI1kVnykaWMnmBUbkqaK-xsnhw8_pk536qWjwEFUyf6PUUg1wzk_IpEQAY8paDzB1Od2eoE18NbXUFZYllsqKZly59jvsjwPRRHk8yYr3eQW6AyxBezOhpY9qI3kooKY2_mzMXAiyrcmb-apucQabMuDfVaFF7zR0OQ-1wR_hwH-ZfLZXjf9S0Im8_Hf0WLPw60iWp5d9g_kdKuysPlJGg\",\n \"kubeHunterRule\" : \"Access Secrets\"\n}",
6-
"severity": "LOW",
6+
"severity": "Low",
77
"date": "2020-04-15",
88
"unique_id_from_tool": "df9afbb5-f0c4-475b-a0e5-e3635c55917a",
99
"endpoints": [
@@ -13,7 +13,7 @@
1313
{
1414
"title": "CAP_NET_RAW Enabled",
1515
"description": "CAP_NET_RAW is enabled by default for pods.\n If an attacker manages to compromise a pod,\n they could potentially take advantage of this capability to perform network\n attacks on other pods running on the same node\n {\n \"evidence\" : \"\",\n \"kubeHunterRule\" : \"Pod Capabilities Hunter\"\n}",
16-
"severity": "LOW",
16+
"severity": "Low",
1717
"date": "2020-04-16",
1818
"unique_id_from_tool": "341ad0c8-0f3b-47ff-9b89-83d4a7e121f7",
1919
"endpoints": [
@@ -23,7 +23,7 @@
2323
{
2424
"title": "Access to pod's secrets",
2525
"description": " Accessing the pod's secrets within a compromised pod might disclose valuable data to a potential attacker\n {\n \"evidence\" : \"['/var/run/secrets/kubernetes.io/serviceaccount/token', '/var/run/secrets/kubernetes.io/serviceaccount/namespace', '/var/run/secrets/kubernetes.io/serviceaccount/ca.crt', '/var/run/secrets/kubernetes.io/serviceaccount/..2021_05_17_21_58_54.448582170/token', '/var/run/secrets/kubernetes.io/serviceaccount/..2021_05_17_21_58_54.448582170/namespace', '/var/run/secrets/kubernetes.io/serviceaccount/..2021_05_17_21_58_54.448582170/ca.crt']\",\n \"kubeHunterRule\" : \"Access Secrets\"\n}",
26-
"severity": "LOW",
26+
"severity": "Low",
2727
"date": "2020-04-17",
2828
"unique_id_from_tool": "eb0c75cf-beef-4fd8-b2ed-6e46a5afa1bc",
2929
"endpoints": [

0 commit comments

Comments
 (0)