Skip to content

Apache Lucene open-source search software

SOLR-11207: Add OWASP dependency checker to gradle build (#1121)

Jan Høydahl74a8d6d5acc6
diff --git a/build.gradle b/build.gradle
index 0dc2c14f0fb..1a4bdd0efb2 100644
--- a/build.gradle
+++ b/build.gradle
@@ -5,6 +5,7 @@ plugins {
id "base"
id "com.palantir.consistent-versions" version "1.14.0"
id 'de.thetaphi.forbiddenapis' version '2.7' apply false
+ id "org.owasp.dependencycheck" version "5.2.4"
}
// Project version and main properties. Applies to all projects.
@@ -58,6 +59,7 @@ apply from: file('gradle/validation/versions-props-sorted.gradle')
apply from: file('gradle/validation/validate-source-patterns.gradle')
apply from: file('gradle/validation/config-file-sanity.gradle')
apply from: file('gradle/validation/rat-sources.gradle')
+apply from: file('gradle/validation/owasp-dependency-check.gradle')
// Additional development aids.
apply from: file('gradle/maven/maven-local.gradle')
diff --git a/gradle/validation/dependency-check/exclusions.xml b/gradle/validation/dependency-check/exclusions.xml
new file mode 100644
index 00000000000..02740c17250
--- /dev/null
+++ b/gradle/validation/dependency-check/exclusions.xml
@@ -0,0 +1,49 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+ -->
+
+<!-- See https://jeremylong.github.io/DependencyCheck/general/suppression.html for usage.
+ Simply view the HTML report generated in ./build/reports/dependency-check-report.html
+ and click the "suppress" button next to the CVE you wish to suppress to copy the xml fragment
+ -->
+
+<suppressions xmlns="https://jeremylong.github.io/DependencyCheck/dependency-suppression.1.3.xsd">
+ <suppress>
+ <notes><![CDATA[
+ file name: simple-xml-safe-2.7.1.jar
+ We use a safe fork that fixes this
+ ]]></notes>
+ <packageUrl regex="true">^pkg:maven/com\.carrotsearch\.thirdparty/simple\-xml\-safe@.*$</packageUrl>
+ <cve>CVE-2017-1000190</cve>
+ </suppress>
+ <suppress>
+ <notes><![CDATA[
+ file name: netty-transport-native-epoll-4.1.29.Final.jar
+ We only use netty as a client towards Zookeeper
+ ]]></notes>
+ <packageUrl regex="true">^pkg:maven/io\.netty/netty\-.*@.*$</packageUrl>
+ <cpe>cpe:/a:netty:netty</cpe>
+ </suppress>
+ <suppress>
+ <notes><![CDATA[
+ file name: dirgra-0.3.jar
+ We will sandbox JRuby
+ ]]></notes>
+ <packageUrl regex="true">^pkg:maven/org\.jruby/dirgra@.*$</packageUrl>
+ <cpe>cpe:/a:jruby:jruby</cpe>
+ </suppress>
+</suppressions>
diff --git a/gradle/validation/owasp-dependency-check.gradle b/gradle/validation/owasp-dependency-check.gradle
new file mode 100644
index 00000000000..b47291cccd0
--- /dev/null
+++ b/gradle/validation/owasp-dependency-check.gradle
@@ -0,0 +1,17 @@
+// This adds OWASP vulnerability validation of project dependencies
+// Not part of 'check' task by default, must be called explicitly, e.g. gradlew dependencyCheckAnalyze
+// Start build with -Pvalidation.owasp.fail=true to fail build on owasp errors (CVSS >= 7)
+// Start build with -Pvalidation.owasp.skip=true to skip OWASP checks during 'check' phase
+
+configure(rootProject) {
+ dependencyCheck {
+ // TODO: Flip this to true once the ist is empty
+ skip = !propertyOrDefault("validation.owasp", false).toBoolean()
+ failBuildOnCVSS = propertyOrDefault("validation.owasp.threshold", 7) as Integer
+ formats = ['HTML', 'JSON']
+ suppressionFile = 'gradle/validation/dependency-check/exclusions.xml'
+ }
+
+ // Included in 'check' but it won't do anything since 'skip' defaults to true (inverse of validation.owasp property)
+ check.dependsOn dependencyCheckAnalyze
+}
\ No newline at end of file
diff --git a/help/workflow.txt b/help/workflow.txt
index f929a52168c..46a9eb8e99a 100644
--- a/help/workflow.txt
+++ b/help/workflow.txt
@@ -31,3 +31,6 @@ Put together Solr distribution:
gradlew -p solr/packaging assemble
ls solr/packaging/build/solr-*
+Generate a report of dependencies with known OWASP vulnerabilities:
+gradlew -Pvalidation.owasp=true dependencyCheckAnalyze
+open ./build/reports/dependency-check-report.html
\ No newline at end of file