Skip to content

Commit

Permalink
Critical for pull request fix (#1359)
Browse files Browse the repository at this point in the history
  • Loading branch information
itsKedar authored Jun 3, 2024
1 parent a8dbb2d commit 7a80486
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/checkmarx/flow/dto/ScanRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ public class ScanRequest {
@Getter @Setter
private String latestCommitterEmail;

@Getter @Setter
private Double sastVersion;

// @Getter @Setter @Builder.Default
// private Boolean overrideProjectSetting = false;

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/checkmarx/flow/service/ResultsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ public void processResults(ScanRequest request, ScanResults results, ScanDetails
if (Boolean.FALSE.equals(cxScannerService.getProperties().getOffline())) {
getCxFields(request, results);
}
if(cxScannerService.getProperties().getVersion()!=null){
request.setSastVersion(cxScannerService.getProperties().getVersion());
}

if(results.getScaResults() != null || results.getXIssues() != null || results.getAstResults() != null) {
switch (request.getBugTracker().getType()) {
Expand Down
37 changes: 28 additions & 9 deletions src/main/java/com/checkmarx/flow/utils/HTMLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static void scaSummaryBuilder(StringBuilder body, SCAResults r, ScanRequ
appendAll(body, MarkDownHelper.getBoldText("Total Packages Identified"), ": ", MarkDownHelper.getBoldText(String.valueOf(r.getSummary().getTotalPackages())), CRLF);
appendAll(body, MarkDownHelper.getBoldText("Scan Risk Score"), ": ", MarkDownHelper.getBoldText(String.format("%.2f", r.getSummary().getRiskScore())), CRLF, CRLF);

Arrays.asList("High", "Medium", "Low").forEach(v ->
Arrays.asList("Critical","High", "Medium", "Low").forEach(v ->
appendAll(body, MarkDownHelper.getSeverityIconFromLinkByText(v, request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(String.valueOf(r.getSummary().getFindingCounts().get(Severity.valueOf(v.toUpperCase())))),
" ", MarkDownHelper.getBoldText(v), " " ,MarkDownHelper.getBoldText("severity vulnerabilities"), CRLF));

Expand Down Expand Up @@ -721,25 +721,44 @@ private static void addScanSummarySection(ScanRequest request, ScanResults resul
appendAll(body, MarkDownHelper.getMdHeaderType(4, properties.getCxSummaryHeader()), CRLF);
}
MarkDownHelper.appendMDtableHeaders(body, SEVERITY, "Count");
MarkDownHelper.appendMDtableRow(body, "High", summary.getHighSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Medium", summary.getMediumSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Low", summary.getLowSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Informational", summary.getInfoSeverity().toString());
if(request.getSastVersion()>=9.7){
MarkDownHelper.appendMDtableRow(body, "Critical", summary.getCriticalSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "High", summary.getHighSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Medium", summary.getMediumSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Low", summary.getLowSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Informational", summary.getInfoSeverity().toString());
}else{
MarkDownHelper.appendMDtableRow(body, "High", summary.getHighSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Medium", summary.getMediumSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Low", summary.getLowSeverity().toString());
MarkDownHelper.appendMDtableRow(body, "Informational", summary.getInfoSeverity().toString());
}

body.append(CRLF);
}
}

private static void setScannerTotalVulnerabilities(StringBuilder body, CxScanSummary summary, ScanRequest request) {
appendAll(body, "Total of " + countSastTotalVulnerabilities(summary) + " vulnerabilities", MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getHighIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getHighSeverity() + " High"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getMediumIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getMediumSeverity() + " Medium"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getLowIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getLowSeverity() + " Low"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getInfoIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getInfoSeverity() + " Info"), MarkDownHelper.getLineBreak(request), CRLF);
if(request.getSastVersion()>=9.7){
appendAll(body, MarkDownHelper.getCriticalIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getCriticalSeverity() + " Critical"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getHighIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getHighSeverity() + " High"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getMediumIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getMediumSeverity() + " Medium"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getLowIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getLowSeverity() + " Low"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getInfoIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getInfoSeverity() + " Info"), MarkDownHelper.getLineBreak(request), CRLF);
}else {
appendAll(body, MarkDownHelper.getHighIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getHighSeverity() + " High"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getMediumIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getMediumSeverity() + " Medium"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getLowIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getLowSeverity() + " Low"), MarkDownHelper.getLineBreak(request));
appendAll(body, MarkDownHelper.getInfoIconFromLink(request), MarkDownHelper.getNonBreakingSpace(request), MarkDownHelper.getBoldText(summary.getInfoSeverity() + " Info"), MarkDownHelper.getLineBreak(request), CRLF);
}

}

private static String countSastTotalVulnerabilities(CxScanSummary summary) {
int totalVulnerabilities = 0;

totalVulnerabilities += Optional.ofNullable(summary.getCriticalSeverity()).orElse(0);
totalVulnerabilities += Optional.ofNullable(summary.getHighSeverity()).orElse(0);
totalVulnerabilities += Optional.ofNullable(summary.getMediumSeverity()).orElse(0);
totalVulnerabilities += Optional.ofNullable(summary.getLowSeverity()).orElse(0);
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/checkmarx/flow/utils/MarkDownHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class MarkDownHelper {

private static final String GITHUB_USER_PREFIX = "https://user-images.githubusercontent.com/23239410/";
private static final String CHECKMARX_LOGO_URL = GITHUB_USER_PREFIX + "92153465-ff743900-ee2c-11ea-9c8d-8141e38feb41.png";
private static final String CRITICAL_ICON = "https://i.imgur.com/DGKOtBX.png";
private static final String HIGH_ICON = GITHUB_USER_PREFIX + "92157087-97285600-ee32-11ea-988f-0aca12c4c126.png";
private static final String MEDIUM_ICON = GITHUB_USER_PREFIX + "92157093-98598300-ee32-11ea-83d7-af52251a011b.png";
private static final String LOW_ICON = GITHUB_USER_PREFIX + "92157091-98598300-ee32-11ea-8498-19bd7d62019b.png";
Expand All @@ -42,6 +43,7 @@ public class MarkDownHelper {
public static final String SAST_HEADER = CHECKMARX_PREFIX + SAST_SCANNER + " - " + SCAN_SUMMARY_DETAILS;
public static final String SCA_HEADER = CHECKMARX_PREFIX + SCA_SCANNER + " - " + SCAN_SUMMARY_DETAILS;
private static final String AST_SAST_HEADER = CHECKMARX_PREFIX + AST_SAST_SCANNER + " - " + SCAN_SUMMARY_DETAILS;
private static final String CRITICAL = "CRITICAL";
private static final String HIGH = "HIGH";
private static final String MEDIUM = "MEDIUM";
private static final String LOW = "LOW";
Expand Down Expand Up @@ -113,6 +115,10 @@ static String getHighIconFromLink(ScanRequest request) {
return getImageFromLink("High", HIGH_ICON, request);
}

static String getCriticalIconFromLink(ScanRequest request) {
return getImageFromLink("Critical", CRITICAL_ICON, request);
}

static String getMediumIconFromLink(ScanRequest request) {
return getImageFromLink("Medium", MEDIUM_ICON, request);
}
Expand Down Expand Up @@ -154,6 +160,8 @@ static String getSeverityIconFromLinkByText(String severity, ScanRequest request
severity = severity.toUpperCase();

switch (severity) {
case CRITICAL:
return getCriticalIconFromLink(request);
case HIGH:
return getHighIconFromLink(request);
case MEDIUM:
Expand Down

0 comments on commit 7a80486

Please sign in to comment.