-
Notifications
You must be signed in to change notification settings - Fork 184
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package edu.hm.hafner.analysis.parser; | ||
|
||
import edu.hm.hafner.analysis.Issue; | ||
import edu.hm.hafner.analysis.IssueBuilder; | ||
import edu.hm.hafner.analysis.Report; | ||
import edu.hm.hafner.analysis.Severity; | ||
import edu.umd.cs.findbugs.annotations.CheckForNull; | ||
Check warning on line 7 in src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
import org.json.JSONArray; | ||
import org.json.JSONObject; | ||
|
||
import static java.lang.String.*; | ||
Check warning on line 11 in src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java ci.jenkins.io / PMDUnnecessaryImport
Raw output
|
||
|
||
/** | ||
* JSON report parser for grype (https://plugins.jenkins.io/grypescanner/ / https://github.com/anchore/grype). | ||
*/ | ||
public class GrypeParser extends JsonIssueParser { | ||
private static final long serialVersionUID = -1369431674771459756L; | ||
|
||
private static final String MATCHES_TAG = "matches"; | ||
private static final String VULNERABILIY_TAG = "vulnerability"; | ||
private static final String ARTIFACT_TAG = "artifact"; | ||
private static final String LOCATIONS_TAG = "locations"; | ||
private static final String PATH_TAG = "path"; | ||
private static final String DATA_SOURCE_TAG = "dataSource"; | ||
private static final String SEVERITY_TAG = "severity"; | ||
private static final String ID_TAG = "id"; | ||
private static final String DESCRIPTION_TAG = "description"; | ||
|
||
@Override | ||
protected void parseJsonObject(final Report report, final JSONObject jsonReport, final IssueBuilder issueBuilder) { | ||
final JSONArray matches = jsonReport.getJSONArray(MATCHES_TAG); | ||
for (int i = 0; i < matches.length(); i++) { | ||
final JSONObject match = matches.getJSONObject(i); | ||
if (!match.has(VULNERABILIY_TAG)) { | ||
continue; | ||
} | ||
JSONObject vuln = match.getJSONObject(VULNERABILIY_TAG); | ||
String fileName = match.getJSONObject(ARTIFACT_TAG).getJSONArray(LOCATIONS_TAG).getJSONObject(0) | ||
.getString(PATH_TAG); | ||
Issue issue = issueBuilder.setFileName(fileName) | ||
.setCategory(vuln.getString(SEVERITY_TAG)) | ||
.setSeverity(mapSeverity(vuln.getString(SEVERITY_TAG))) | ||
.setType(vuln.getString(ID_TAG)) | ||
.setMessage(vuln.getString(DESCRIPTION_TAG)) | ||
.setOriginName("Grype") | ||
.setPathName(fileName) | ||
.setDescription(vuln.getString(DATA_SOURCE_TAG)).build(); | ||
report.add(issue); | ||
} | ||
} | ||
|
||
private Severity mapSeverity(final String severity) { | ||
switch (severity.toUpperCase()) { | ||
Check warning on line 53 in src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java ci.jenkins.io / SpotBugsDM_CONVERT_CASE
Raw output
Check warning on line 53 in src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java ci.jenkins.io / SpotBugsIMPROPER_UNICODE
Raw output
Check warning on line 53 in src/main/java/edu/hm/hafner/analysis/parser/GrypeParser.java ci.jenkins.io / PMDUseLocaleWithCaseConversions
Raw output
|
||
case "LOW": | ||
return Severity.WARNING_LOW; | ||
case "MEDIUM": | ||
return Severity.WARNING_NORMAL; | ||
case "CRITICAL": | ||
return Severity.ERROR; | ||
case "HIGH": | ||
return Severity.WARNING_HIGH; | ||
default: | ||
return new Severity(severity); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package edu.hm.hafner.analysis.registry; | ||
|
||
import edu.hm.hafner.analysis.IssueParser; | ||
import edu.hm.hafner.analysis.parser.GrypeParser; | ||
|
||
/** | ||
* Descriptor for Grype report parser. | ||
*/ | ||
public class GrypeDescriptor extends ParserDescriptor { | ||
private static final String ID = "grypescanner"; | ||
private static final String NAME = "Grype scanner"; | ||
|
||
GrypeDescriptor() { | ||
super(ID, NAME); | ||
} | ||
|
||
@Override | ||
public IssueParser createParser(final Option... options) { | ||
return new GrypeParser(); | ||
} | ||
|
||
@Override | ||
public String getPattern() { | ||
return "**/grype-report.json"; | ||
Check warning on line 24 in src/main/java/edu/hm/hafner/analysis/registry/GrypeDescriptor.java ci.jenkins.io / CheckStyleFileTabCharacterCheck
Raw output
|
||
} | ||
|
||
@Override | ||
public String getUrl() { | ||
return "https://github.com/anchore/grype"; | ||
} | ||
|
||
@Override | ||
public String getIconUrl() { | ||
return "https://user-images.githubusercontent.com/5199289/136855393-d0a9eef9-ccf1-4e2b-9d7c-7aad16a567e5.png"; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package edu.hm.hafner.analysis.parser; | ||
|
||
import edu.hm.hafner.analysis.AbstractParserTest; | ||
import edu.hm.hafner.analysis.IssueParser; | ||
import edu.hm.hafner.analysis.Report; | ||
import edu.hm.hafner.analysis.Severity; | ||
import edu.hm.hafner.analysis.assertions.SoftAssertions; | ||
|
||
class GrypeParserTest extends AbstractParserTest { | ||
protected GrypeParserTest() { | ||
super("grype-report.json"); | ||
} | ||
|
||
@Override | ||
protected void assertThatIssuesArePresent(final Report report, final SoftAssertions softly) { | ||
softly.assertThat(report).hasSize(29).hasDuplicatesSize(0); | ||
softly.assertThat(report.get(0)) | ||
.hasFileName("tomcat-jdbc/8.0.28/tomcat-jdbc-8.0.28.jar") | ||
.hasSeverity(Severity.WARNING_NORMAL) | ||
.hasCategory("Medium") | ||
.hasType("CVE-2015-5345") | ||
.hasMessage( | ||
"The Mapper component in Apache Tomcat 6.x before 6.0.45, 7.x before 7.0.68, 8.x before 8.0.30, and 9.x before 9.0.0.M2 processes redirects before considering security constraints and Filters, which allows remote attackers to determine the existence of a directory via a URL that lacks a trailing / (slash) character.") | ||
.hasDescription("https://nvd.nist.gov/vuln/detail/CVE-2015-5345"); | ||
|
||
softly.assertThat(report.get(17)) | ||
.hasFileName("tomcat-jdbc/8.0.28/tomcat-jdbc-8.0.28.jar") | ||
.hasSeverity(Severity.WARNING_HIGH) | ||
.hasCategory("High") | ||
.hasType("CVE-2016-8745") | ||
.hasMessage( | ||
"A bug in the error handling of the send file code for the NIO HTTP connector in Apache Tomcat 9.0.0.M1 to 9.0.0.M13, 8.5.0 to 8.5.8, 8.0.0.RC1 to 8.0.39, 7.0.0 to 7.0.73 and 6.0.16 to 6.0.48 resulted in the current Processor object being added to the Processor cache multiple times. This in turn meant that the same Processor could be used for concurrent requests. Sharing a Processor can result in information leakage between requests including, not not limited to, session ID and the response body. The bug was first noticed in 8.5.x onwards where it appears the refactoring of the Connector code for 8.5.x onwards made it more likely that the bug was observed. Initially it was thought that the 8.5.x refactoring introduced the bug but further investigation has shown that the bug is present in all currently supported Tomcat versions.") | ||
.hasDescription("https://nvd.nist.gov/vuln/detail/CVE-2016-8745"); | ||
} | ||
|
||
@Override | ||
protected IssueParser createParser() { | ||
return new GrypeParser(); | ||
} | ||
} |