From 931f7d47eabaedd1d83cbe68877ba60c16f784c7 Mon Sep 17 00:00:00 2001
From: Jeremy Long
Date: Wed, 2 Apr 2014 06:52:26 -0400
Subject: [PATCH] simplified velocity report generation
Former-commit-id: 7c0f5bd492bce8a37c1633715d989970ee5b0d61
---
.../reporting/ReportGenerator.java | 32 ++-
.../main/resources/templates/HtmlReport.vsl | 206 +++++++++++++++---
.../templates/VulnerabilityReport.vsl | 10 +-
.../main/resources/templates/XmlReport.vsl | 56 ++---
4 files changed, 230 insertions(+), 74 deletions(-)
diff --git a/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java b/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java
index 5b702543b..5c5a8bee1 100644
--- a/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java
+++ b/dependency-check-core/src/main/java/org/owasp/dependencycheck/reporting/ReportGenerator.java
@@ -26,15 +26,17 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
+import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import org.apache.velocity.runtime.RuntimeConstants;
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
-import org.apache.velocity.tools.ToolManager;
-import org.apache.velocity.tools.config.EasyFactoryConfiguration;
import org.owasp.dependencycheck.analyzer.Analyzer;
import org.owasp.dependencycheck.data.nvdcve.DatabaseProperties;
import org.owasp.dependencycheck.dependency.Dependency;
@@ -93,10 +95,20 @@ public class ReportGenerator {
engine.init();
+ DateFormat dateFormat = new SimpleDateFormat("MMM d, yyyy 'at' HH:mm:ss z");
+ DateFormat dateFormatXML = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
+ Date d = new Date();
+ String scanDate = dateFormat.format(d);
+ String scanDateXML = dateFormatXML.format(d);
+ EscapeTool enc = new EscapeTool();
+
context.put("applicationName", applicationName);
context.put("dependencies", dependencies);
context.put("analyzers", analyzers);
context.put("properties", properties);
+ context.put("scanDate", scanDate);
+ context.put("scanDateXML", scanDateXML);
+ context.put("enc", enc);
context.put("version", Settings.getString("application.version", "Unknown"));
}
@@ -118,15 +130,15 @@ public class ReportGenerator {
*
* @return a Velocity Context.
*/
- @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RV_RETURN_VALUE_IGNORED_INFERRED",
- justification = "No plan to fix this style issue")
private Context createContext() {
- final ToolManager manager = new ToolManager();
- final Context c = manager.createContext();
- final EasyFactoryConfiguration config = new EasyFactoryConfiguration();
- config.addDefaultTools();
- config.toolbox("application").tool("esc", "org.apache.velocity.tools.generic.EscapeTool").tool("org.apache.velocity.tools.generic.DateTool");
- manager.configure(config);
+ //REMOVED all of the velocity tools to simplify the engine trying to resolve issues running this in Jenkins
+// final ToolManager manager = new ToolManager();
+// final Context c = manager.createContext();
+// final EasyFactoryConfiguration config = new EasyFactoryConfiguration();
+// config.addDefaultTools();
+// config.toolbox("application").tool("esc", "org.apache.velocity.tools.generic.EscapeTool").tool("org.apache.velocity.tools.generic.DateTool");
+// manager.configure(config);
+ VelocityContext c = new VelocityContext();
return c;
}
diff --git a/dependency-check-core/src/main/resources/templates/HtmlReport.vsl b/dependency-check-core/src/main/resources/templates/HtmlReport.vsl
index 2ff16d539..0ae1ba690 100644
--- a/dependency-check-core/src/main/resources/templates/HtmlReport.vsl
+++ b/dependency-check-core/src/main/resources/templates/HtmlReport.vsl
@@ -471,26 +471,38 @@ implied or otherwise, with regard to the analysis or its use. Any use of the too
is at the user’s risk. In no event shall the copyright holder or OWASP be held liable for any damages whatsoever
arising out of or in connection with the use of this tool, the analysis performed, or the resulting report.
@@ -499,11 +511,11 @@ arising out of or in connection with the use of this tool, the analysis performe
#foreach($dependency in $dependencies)
#set($lnkcnt=$lnkcnt+1)
#foreach($related in $dependency.getRelatedDependencies())
-
$esc.html($related.FileName)
+
$enc.html($related.FileName)
#end
#end
@@ -516,22 +528,22 @@ arising out of or in connection with the use of this tool, the analysis performe
#set($vsctr=0) ##counter to create unique groups for vulnerable software
#foreach($dependency in $dependencies)
#set($lnkcnt=$lnkcnt+1)
-
@@ -539,7 +551,7 @@ arising out of or in connection with the use of this tool, the analysis performe
Source
Name
Value
#foreach($evidence in $dependency.getEvidenceUsed())
-
$esc.html($evidence.getSource())
$esc.html($evidence.getName())
$esc.html($evidence.getValue())
+
$enc.html($evidence.getSource())
$enc.html($evidence.getName())
$enc.html($evidence.getValue())
#end
@@ -549,18 +561,18 @@ arising out of or in connection with the use of this tool, the analysis performe
#foreach($related in $dependency.getRelatedDependencies())
-
$esc.html($related.FileName)
+
$enc.html($related.FileName)
-
File Path: $esc.html($related.FilePath)
-
SHA1: $esc.html($related.Sha1sum)
-
MD5: $esc.html($related.Md5sum)
+
File Path: $enc.html($related.FilePath)
+
SHA1: $enc.html($related.Sha1sum)
+
MD5: $enc.html($related.Md5sum)
#foreach($id in $related.getIdentifiers())
#if ($id.type=="maven")
#if( $id.url )
##yes, we are HTML Encoding the href. this is okay. We can't URL encode as we have to trust the analyzer here...
-
@@ -588,19 +600,19 @@ arising out of or in connection with the use of this tool, the analysis performe
#foreach($id in $dependency.getIdentifiers())
#if( $id.url )
##yes, we are HTML Encoding the href. this is okay. We can't URL encode as we have to trust the analyzer here...
-
$enc.html($id.type): $enc.html($id.value)
#end
#if ($id.confidence)
Confidence:$id.confidence
#end
#if ($id.type=="cpe")
##yes, we are HTML Encoding into JavaScript... the escape utils don't have a JS Encode and I haven't written one yet
-
+
#end
#if ($id.description)
- $esc.html($id.description)
+ $enc.html($id.description)
#end
#end
@@ -613,7 +625,7 @@ arising out of or in connection with the use of this tool, the analysis performe
#foreach($vuln in $dependency.getVulnerabilities())
#set($vsctr=$vsctr+1)
-
Severity:
#if ($vuln.cvssScore<4.0)
Low
@@ -626,20 +638,20 @@ arising out of or in connection with the use of this tool, the analysis performe
#if ($vuln.cwe)
CWE: $vuln.cwe
#end
+ #foreach($id in $dependency.getSuppressedIdentifiers())
+ #if( $id.url )
+ ##yes, we are HTML Encoding the href. this is okay. We can't URL encode as we have to trust the analyzer here...
+
diff --git a/dependency-check-core/src/main/resources/templates/VulnerabilityReport.vsl b/dependency-check-core/src/main/resources/templates/VulnerabilityReport.vsl
index c4d642986..c381d5d19 100644
--- a/dependency-check-core/src/main/resources/templates/VulnerabilityReport.vsl
+++ b/dependency-check-core/src/main/resources/templates/VulnerabilityReport.vsl
@@ -178,8 +178,8 @@ implied or otherwise, with regard to the analysis or its use. Any use of the too
is at the user’s risk. In no event shall the copyright holder or OWASP be held liable for any damages whatsoever
arising out of or in connection with the use of this tool, the analysis performed, or the resulting report.
]]#
-
Project: $esc.html($applicationName)
-
Report Generated On: $date
+
Project: $enc.html($applicationName)
+
Report Generated On: $scanDate
#set($depCount=$dependencies.size())
#set($vulnCount=0)
@@ -205,7 +205,7 @@ arising out of or in connection with the use of this tool, the analysis performe
#if($dependency.getVulnerabilities().size()>0)
#foreach($vuln in $dependency.getVulnerabilities())