mirror of
https://github.com/ysoftdevs/DependencyCheck.git
synced 2026-03-21 00:29:21 +01:00
Ruby bundler: More method extractions to eliminate monolithic method.
This commit is contained in:
@@ -208,58 +208,13 @@ public class RubyBundleAuditAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
dependency = map.get(gem);
|
dependency = map.get(gem);
|
||||||
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
||||||
} else if (nextLine.startsWith(VERSION)) {
|
} else if (nextLine.startsWith(VERSION)) {
|
||||||
if (null != dependency) {
|
vulnerability = createVulnerability(parentName, dependency, vulnerability, gem, nextLine);
|
||||||
final String version = nextLine.substring(VERSION.length());
|
|
||||||
dependency.getVersionEvidence().addEvidence(
|
|
||||||
"bundler-audit",
|
|
||||||
"Version",
|
|
||||||
version,
|
|
||||||
Confidence.HIGHEST);
|
|
||||||
vulnerability = new Vulnerability(); // don't add to dependency until we have name set later
|
|
||||||
vulnerability.setMatchedCPE(
|
|
||||||
String.format("cpe:/a:%1$s_project:%1$s:%2$s::~~~ruby~~", gem, version),
|
|
||||||
null);
|
|
||||||
}
|
|
||||||
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
|
||||||
} else if (nextLine.startsWith(ADVISORY)) {
|
} else if (nextLine.startsWith(ADVISORY)) {
|
||||||
final String advisory = nextLine.substring((ADVISORY.length()));
|
setVulnerabilityName(parentName, dependency, vulnerability, nextLine);
|
||||||
if (null != vulnerability) {
|
|
||||||
vulnerability.setName(advisory);
|
|
||||||
vulnerability.setCvssAccessVector("-");
|
|
||||||
vulnerability.setCvssAccessComplexity("-");
|
|
||||||
vulnerability.setCvssAuthentication("-");
|
|
||||||
vulnerability.setCvssAvailabilityImpact("-");
|
|
||||||
vulnerability.setCvssConfidentialityImpact("-");
|
|
||||||
vulnerability.setCvssIntegrityImpact("-");
|
|
||||||
}
|
|
||||||
if (null != dependency) {
|
|
||||||
dependency.getVulnerabilities().add(vulnerability);
|
|
||||||
}
|
|
||||||
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
|
||||||
} else if (nextLine.startsWith(CRITICALITY)) {
|
} else if (nextLine.startsWith(CRITICALITY)) {
|
||||||
if (null != vulnerability) {
|
addCriticalityToVulnerability(parentName, vulnerability, nextLine);
|
||||||
final String criticality = nextLine.substring(CRITICALITY.length()).trim();
|
|
||||||
if ("High".equals(criticality)) {
|
|
||||||
vulnerability.setCvssScore(8.5f);
|
|
||||||
} else if ("Medium".equals(criticality)) {
|
|
||||||
vulnerability.setCvssScore(5.5f);
|
|
||||||
} else if ("Low".equals(criticality)) {
|
|
||||||
vulnerability.setCvssScore(2.0f);
|
|
||||||
} else {
|
|
||||||
vulnerability.setCvssScore(-1.0f);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
|
||||||
} else if (nextLine.startsWith("URL: ")){
|
} else if (nextLine.startsWith("URL: ")){
|
||||||
final String url = nextLine.substring(("URL: ").length());
|
addReferenceToVulnerability(parentName, vulnerability, nextLine);
|
||||||
if (null != vulnerability) {
|
|
||||||
Reference ref = new Reference();
|
|
||||||
ref.setName(vulnerability.getName());
|
|
||||||
ref.setSource("bundle-audit");
|
|
||||||
ref.setUrl(url);
|
|
||||||
vulnerability.getReferences().add(ref);
|
|
||||||
}
|
|
||||||
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
|
||||||
} else if (nextLine.startsWith("Description:")) {
|
} else if (nextLine.startsWith("Description:")) {
|
||||||
appendToDescription = true;
|
appendToDescription = true;
|
||||||
if (null != vulnerability) {
|
if (null != vulnerability) {
|
||||||
@@ -273,6 +228,68 @@ public class RubyBundleAuditAnalyzer extends AbstractFileTypeAnalyzer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setVulnerabilityName(String parentName, Dependency dependency, Vulnerability vulnerability, String nextLine) {
|
||||||
|
final String advisory = nextLine.substring((ADVISORY.length()));
|
||||||
|
if (null != vulnerability) {
|
||||||
|
vulnerability.setName(advisory);
|
||||||
|
}
|
||||||
|
if (null != dependency) {
|
||||||
|
dependency.getVulnerabilities().add(vulnerability); // needed to wait for vulnerability name to avoid NPE
|
||||||
|
}
|
||||||
|
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addReferenceToVulnerability(String parentName, Vulnerability vulnerability, String nextLine) {
|
||||||
|
final String url = nextLine.substring(("URL: ").length());
|
||||||
|
if (null != vulnerability) {
|
||||||
|
Reference ref = new Reference();
|
||||||
|
ref.setName(vulnerability.getName());
|
||||||
|
ref.setSource("bundle-audit");
|
||||||
|
ref.setUrl(url);
|
||||||
|
vulnerability.getReferences().add(ref);
|
||||||
|
}
|
||||||
|
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addCriticalityToVulnerability(String parentName, Vulnerability vulnerability, String nextLine) {
|
||||||
|
if (null != vulnerability) {
|
||||||
|
final String criticality = nextLine.substring(CRITICALITY.length()).trim();
|
||||||
|
if ("High".equals(criticality)) {
|
||||||
|
vulnerability.setCvssScore(8.5f);
|
||||||
|
} else if ("Medium".equals(criticality)) {
|
||||||
|
vulnerability.setCvssScore(5.5f);
|
||||||
|
} else if ("Low".equals(criticality)) {
|
||||||
|
vulnerability.setCvssScore(2.0f);
|
||||||
|
} else {
|
||||||
|
vulnerability.setCvssScore(-1.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Vulnerability createVulnerability(String parentName, Dependency dependency, Vulnerability vulnerability, String gem, String nextLine) {
|
||||||
|
if (null != dependency) {
|
||||||
|
final String version = nextLine.substring(VERSION.length());
|
||||||
|
dependency.getVersionEvidence().addEvidence(
|
||||||
|
"bundler-audit",
|
||||||
|
"Version",
|
||||||
|
version,
|
||||||
|
Confidence.HIGHEST);
|
||||||
|
vulnerability = new Vulnerability(); // don't add to dependency until we have name set later
|
||||||
|
vulnerability.setMatchedCPE(
|
||||||
|
String.format("cpe:/a:%1$s_project:%1$s:%2$s::~~~ruby~~", gem, version),
|
||||||
|
null);
|
||||||
|
vulnerability.setCvssAccessVector("-");
|
||||||
|
vulnerability.setCvssAccessComplexity("-");
|
||||||
|
vulnerability.setCvssAuthentication("-");
|
||||||
|
vulnerability.setCvssAvailabilityImpact("-");
|
||||||
|
vulnerability.setCvssConfidentialityImpact("-");
|
||||||
|
vulnerability.setCvssIntegrityImpact("-");
|
||||||
|
}
|
||||||
|
LOGGER.info(String.format("bundle-audit (%s): %s", parentName, nextLine));
|
||||||
|
return vulnerability;
|
||||||
|
}
|
||||||
|
|
||||||
private Dependency createDependencyForGem(Engine engine, String parentName, String fileName, String gem) throws IOException {
|
private Dependency createDependencyForGem(Engine engine, String parentName, String fileName, String gem) throws IOException {
|
||||||
final File tempFile = File.createTempFile("Gemfile-" + gem, ".lock", Settings.getTempDirectory());
|
final File tempFile = File.createTempFile("Gemfile-" + gem, ".lock", Settings.getTempDirectory());
|
||||||
final String displayFileName = String.format("%s%c%s:%s", parentName, File.separatorChar, fileName, gem);
|
final String displayFileName = String.format("%s%c%s:%s", parentName, File.separatorChar, fileName, gem);
|
||||||
|
|||||||
Reference in New Issue
Block a user