Skip to content

Commit f35b129

Browse files
authoredMar 7, 2023
Merge pull request DependencyTrack#2532 from lme-nca/bugfix/issue_2424_add_do_not_reactivate_flag
add DefectDojo "do not reactivate" flag, fixes issue 2424 Closes DependencyTrack#2424
2 parents 64e0f99 + 8e72253 commit f35b129

File tree

5 files changed

+36
-6
lines changed

5 files changed

+36
-6
lines changed
 

‎docs/_docs/integrations/defectdojo.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ This feature is used to map projects in Dependency-Track to engagements in Defec
4848
| ---------------| --------------------------------- |
4949
| Group Name | `integrations` |
5050
| Property Name | `defectdojo.engagementId` |
51-
| Property Value | The CI/CD engagement ID to upload findings to, noted in Step 3 |
51+
| Property Value | The CI/CD engagement ID to upload findings to, noted in Step 3 |s
5252
| Property Type | `STRING` |
5353

5454
#### Step 7: Add Per-project configuration for Reimport Enhancement (Optional)
@@ -64,7 +64,25 @@ The additional configuration property is defined as below:
6464
| Property Value | 'true' |
6565
| Property Type | `BOOLEAN` |
6666

67-
#### Step 8: Global configuration for Reimport Enhancement (Optional)
67+
#### Step 8: Add Per-project configuration for do_not_reactivate Enhancement (Optional)
68+
![Configure Project](/images/screenshots/defectdojo_do-not-reactivate.png)
69+
70+
* Dependency-Track v4.8.0 or higher
71+
* Only work in combination with reimport
72+
* Enabling this flag will mean that DefectDojo is considered the source of truth and findings closed in DefectDojo are not re-opened.
73+
* WARNING! This comes with the downside that a potentially patched vulnerability that is re-introduced by, for example a library downgrade, is reactivated
74+
75+
As mentioned in the DefectDojo documentation this feature 'Will keep existing findings closed, without reactivating them.' Usually DefectDojo considers the scanners report as the source of truth, this leads DefectDojo to re-open findings that might have been closed in DefectDojo if it shows up in a scan.
76+
77+
78+
| Attribute | Value |
79+
| ---------------| --------------------------------- |
80+
| Group Name | `integrations` |
81+
| Property Name | `defectdojo.doNotReactivate` |
82+
| Property Value | 'true' |
83+
| Property Type | `BOOLEAN` |
84+
85+
#### Step 9: Global configuration for Reimport Enhancement (Optional)
6886
* Dependency-Track v4.6.0 or higher
6987
![Configure Project](/images/screenshots/defectdojo_global_reimport.png)
7088
Alternatively, you can turn on the above reimport feature for all projects in one click, by checking on 'Enable reimport' box as shown in the screenshot above.
Loading

‎src/main/java/org/dependencytrack/integrations/defectdojo/DefectDojoClient.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public ArrayList<String> jsonToList(final JSONArray jsonArray) {
163163
* A Reimport will reuse (overwrite) the existing test, instead of create a new test.
164164
* The Successfully reimport will also increase the reimport counter by 1.
165165
*/
166-
public void reimportDependencyTrackFindings(final String token, final String engagementId, final InputStream findingsJson, final String testId) {
166+
public void reimportDependencyTrackFindings(final String token, final String engagementId, final InputStream findingsJson, final String testId, final Boolean doNotReactivate) {
167167
LOGGER.debug("Re-reimport Dependency-Track findings to DefectDojo per Engagement");
168168
HttpPost request = new HttpPost(baseURL + "/api/v2/reimport-scan/");
169169
request.addHeader("accept", "application/json");
@@ -178,6 +178,7 @@ public void reimportDependencyTrackFindings(final String token, final String eng
178178
.addPart("minimum_severity", new StringBody("Info", ContentType.MULTIPART_FORM_DATA))
179179
.addPart("close_old_findings", new StringBody("true", ContentType.MULTIPART_FORM_DATA))
180180
.addPart("push_to_jira", new StringBody("push_to_jira", ContentType.MULTIPART_FORM_DATA))
181+
.addPart("do_not_reactivate", new StringBody(doNotReactivate.toString(), ContentType.MULTIPART_FORM_DATA))
181182
.addPart("test", new StringBody(testId, ContentType.MULTIPART_FORM_DATA))
182183
.addPart("scan_date", new StringBody(DATE_FORMAT.format(new Date()), ContentType.MULTIPART_FORM_DATA))
183184
.build();

‎src/main/java/org/dependencytrack/integrations/defectdojo/DefectDojoUploader.java

+12-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public class DefectDojoUploader extends AbstractIntegrationPoint implements Proj
4444
private static final Logger LOGGER = Logger.getLogger(DefectDojoUploader.class);
4545
private static final String ENGAGEMENTID_PROPERTY = "defectdojo.engagementId";
4646
private static final String REIMPORT_PROPERTY = "defectdojo.reimport";
47+
private static final String DO_NOT_REACTIVATE_PROPERTY = "defectdojo.doNotReactivate";
48+
4749

4850
public boolean isReimportConfigured(final Project project) {
4951
final ProjectProperty reimport = qm.getProjectProperty(project, DEFECTDOJO_ENABLED.getGroupName(), REIMPORT_PROPERTY);
@@ -54,6 +56,15 @@ public boolean isReimportConfigured(final Project project) {
5456
}
5557
}
5658

59+
public boolean isDoNotReactivateConfigured(final Project project) {
60+
final ProjectProperty reactivate = qm.getProjectProperty(project, DEFECTDOJO_ENABLED.getGroupName(), DO_NOT_REACTIVATE_PROPERTY);
61+
if (reactivate != null) {
62+
return Boolean.parseBoolean(reactivate.getPropertyValue());
63+
} else {
64+
return false;
65+
}
66+
}
67+
5768
@Override
5869
public String name() {
5970
return "DefectDojo";
@@ -97,7 +108,7 @@ public void upload(final Project project, final InputStream payload) {
97108
if (testId.equals("")) {
98109
client.uploadDependencyTrackFindings(apiKey.getPropertyValue(), engagementId.getPropertyValue(), payload);
99110
} else {
100-
client.reimportDependencyTrackFindings(apiKey.getPropertyValue(), engagementId.getPropertyValue(), payload, testId);
111+
client.reimportDependencyTrackFindings(apiKey.getPropertyValue(), engagementId.getPropertyValue(), payload, testId, isDoNotReactivateConfigured(project));
101112
}
102113
} else {
103114
client.uploadDependencyTrackFindings(apiKey.getPropertyValue(), engagementId.getPropertyValue(), payload);

‎src/test/java/org/dependencytrack/integrations/defectdojo/DefectDojoClientTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public void testReimportFindingsPositiveCase() throws Exception {
8585
withBody(WireMock.equalTo(engagementId))).willReturn(WireMock.aResponse().withStatus(201).withHeader(HttpHeaders.CONTENT_TYPE, "application/json")));
8686
DefectDojoUploader uploader = new DefectDojoUploader();
8787
DefectDojoClient client = new DefectDojoClient(uploader, new URL(wireMockRule.baseUrl() + "/defectdojo"));
88-
client.reimportDependencyTrackFindings(token, engagementId, new NullInputStream(0), testId);
88+
client.reimportDependencyTrackFindings(token, engagementId, new NullInputStream(0), testId, false);
8989
WireMock.verify(WireMock.postRequestedFor(WireMock.urlPathEqualTo("/defectdojo/api/v2/reimport-scan/"))
9090
.withAnyRequestBodyPart(WireMock.aMultipart().withName("engagement").
9191
withBody(WireMock.equalTo(engagementId)
@@ -103,7 +103,7 @@ public void testReimportFindingsNegativeCase() throws Exception {
103103
withBody(WireMock.equalTo(""))).willReturn(WireMock.aResponse().withStatus(400).withHeader(HttpHeaders.CONTENT_TYPE, "application/json")));
104104
DefectDojoUploader uploader = new DefectDojoUploader();
105105
DefectDojoClient client = new DefectDojoClient(uploader, new URL(wireMockRule.baseUrl() + "/defectdojo"));
106-
client.reimportDependencyTrackFindings(token, engagementId, new NullInputStream(16), testId);
106+
client.reimportDependencyTrackFindings(token, engagementId, new NullInputStream(16), testId, false);
107107
WireMock.verify(WireMock.postRequestedFor(WireMock.urlPathEqualTo("/defectdojo/api/v2/reimport-scan/"))
108108
.withAnyRequestBodyPart(WireMock.aMultipart().withName("engagement").
109109
withBody(WireMock.equalTo(engagementId)

0 commit comments

Comments
 (0)
Please sign in to comment.