Skip to content

Commit 223d973

Browse files
committed
zip over id
1 parent a7a2bbd commit 223d973

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

src/main/java/io/mixeway/api/cicd/controller/CICDController.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@ public ResponseEntity<Status> loadVulnsZap (@RequestBody ZapReportModel loadVuln
106106
Principal principal) throws Exception {
107107
return cicdService.loadVulnZap(loadVulnModel,ciid,principal);
108108
}
109+
@PreAuthorize("hasAuthority('ROLE_API')")
110+
@PostMapping(value="/loadvulns/zap/{id}")
111+
public ResponseEntity<Status> loadVulnsZap (@RequestBody ZapReportModel loadVulnModel,
112+
@PathVariable(value = "id") Long id,
113+
Principal principal) throws Exception {
114+
return cicdService.loadVulnZapId(loadVulnModel,id,principal);
115+
}
109116

110117
/**
111118
* Validate State of security for given CodeProject and Branch

src/main/java/io/mixeway/api/cicd/service/CICDService.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,16 @@ public ResponseEntity<Status> loadVulnZap(ZapReportModel loadVulnModel, String c
169169
return webAppScanService.prepareAndLoadZapVulns(loadVulnModel,ciid,principal);
170170
}
171171

172+
/**
173+
* ZAP reports
174+
*/
175+
176+
@Transactional
177+
public ResponseEntity<Status> loadVulnZapId(ZapReportModel loadVulnModel, Long id, Principal principal) throws ParseException {
178+
log.info("ZAP DAST JSON report received for ID {}", id);
179+
return webAppScanService.prepareAndLoadZapVulnsId(loadVulnModel,id,principal);
180+
}
181+
172182
public ResponseEntity<SecurityGatewayResponse> validate(LoadSCA loadSCA, Principal principal) throws UnknownHostException {
173183
Optional<CodeProject> codeProject = findCodeProjectService.findById(loadSCA.getCodeProjectId());
174184
if (codeProject.isPresent() && permissionFactory.canUserAccessProject(principal, codeProject.get().getProject())) {

src/main/java/io/mixeway/scanmanager/service/webapp/WebAppScanService.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.mixeway.utils.Status;
2424
import lombok.RequiredArgsConstructor;
2525
import lombok.extern.log4j.Log4j2;
26+
import org.checkerframework.checker.nullness.Opt;
2627
import org.springframework.http.HttpStatus;
2728
import org.springframework.http.ResponseEntity;
2829
import org.springframework.stereotype.Service;
@@ -274,6 +275,24 @@ public ResponseEntity<Status> prepareAndLoadZapVulns(ZapReportModel loadVulnMode
274275
}
275276
}
276277

278+
public ResponseEntity<Status> prepareAndLoadZapVulnsId(ZapReportModel loadVulnModel, Long id, Principal principal) throws ParseException {
279+
Optional<WebApp> webAppOptional = findWebAppService.findById(id);
280+
if (loadVulnModel.getSite() != null && webAppOptional.isPresent()) {
281+
WebApp webApp = webAppOptional.get();
282+
List<ProjectVulnerability> oldVulns = vulnTemplate.projectVulnerabilityRepository.findByWebApp(webApp);
283+
List<ProjectVulnerability> newVulns = ZapMapper(loadVulnModel,webApp);
284+
zapVulnsRemove(oldVulns);
285+
vulnTemplate.vulnerabilityPersistList(oldVulns, newVulns);
286+
vulnTemplate.projectVulnerabilityRepository.deleteByStatus(vulnTemplate.STATUS_REMOVED);
287+
log.info("[ZAP DAST] vulnerabilities loaded/updated/removed for webapp url {}",webApp.getUrl());
288+
return new ResponseEntity<>(HttpStatus.OK);
289+
}
290+
else {
291+
log.error("Malformed ZAP DAST JSON report.");
292+
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
293+
}
294+
}
295+
277296
public void createWebAppsForProject(Project project, RoutingDomain routingDomain) {
278297
Vulnerability vulnerability = vulnTemplate.vulnerabilityRepository.findByName(Constants.VULNERABILITY_HTTP_SERVER_DETECTED).orElse(null);
279298
if (vulnerability != null) {

0 commit comments

Comments
 (0)