Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

4.x owasp script update #80

Merged
merged 2 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions etc/scripts/owasp-dependency-check.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash -e
#
# Copyright (c) 2020, 2023 Oracle and/or its affiliates.
# Copyright (c) 2020, 2024 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -15,28 +15,44 @@
# limitations under the License.
#

set -o pipefail || true # trace ERR through pipes
set -o errtrace || true # trace ERR through commands and functions
set -o errexit || true # exit the script if any statement returns a non-true return value

# Path to this script
[ -h "${0}" ] && readonly SCRIPT_PATH="$(readlink "${0}")" || readonly SCRIPT_PATH="${0}"
if [ -h "${0}" ] ; then
SCRIPT_PATH="$(readlink "${0}")"
else
# shellcheck disable=SC155
SCRIPT_PATH="${0}"
fi
readonly SCRIPT_PATH

# Load pipeline environment setup and define WS_DIR
. $(dirname -- "${SCRIPT_PATH}")/includes/pipeline-env.sh "${SCRIPT_PATH}" '../..'
# Path to the root of the workspace
# shellcheck disable=SC2046
WS_DIR=$(cd $(dirname -- "${SCRIPT_PATH}") ; cd ../.. ; pwd -P)

# Setup error handling using default settings (defined in includes/error_handlers.sh)
error_trap_setup
on_error(){
CODE="${?}" && \
set +x && \
printf "[ERROR] Error(code=%s) occurred at %s:%s command: %s\n" \
"${CODE}" "${BASH_SOURCE[0]}" "${LINENO}" "${BASH_COMMAND}"
}
trap on_error ERR

readonly RESULT_FILE=$(mktemp -t XXXdependency-check-result)
RESULT_FILE=$(mktemp -t XXXdependency-check-result)
readonly RESULT_FILE

die() { cat ${RESULT_FILE} ; echo "Dependency report in ${WS_DIR}/target" ; echo "${1}" ; exit 1 ;}
die() { cat "${RESULT_FILE}" ; echo "Dependency report in ${WS_DIR}/target" ; echo "${1}" ; exit 1 ;}

if [ "${PIPELINE}" = "true" ] ; then
# If in pipeline do a priming build before scan
mvn ${MAVEN_ARGS} -f ${WS_DIR}/pom.xml clean install -DskipTests
fi
# Setting NVD_API_KEY is not required but improves behavior of NVD API throttling

# shellcheck disable=SC2086
mvn ${MAVEN_ARGS} -Dorg.slf4j.simpleLogger.defaultLogLevel=WARN org.owasp:dependency-check-maven:aggregate \
-f ${WS_DIR}/pom.xml \
-f "${WS_DIR}"/pom.xml \
-Dtop.parent.basedir="${WS_DIR}" \
> ${RESULT_FILE} || die "Error running the Maven command"
-Dnvd-api-key="${NVD_API_KEY}" \
> "${RESULT_FILE}" || die "Error running the Maven command"

grep -i "One or more dependencies were identified with known vulnerabilities" ${RESULT_FILE} \
grep -i "One or more dependencies were identified with known vulnerabilities" "${RESULT_FILE}" \
&& die "CVE SCAN ERROR" || echo "CVE SCAN OK"
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<version.plugin.buildnumber>3.1.0</version.plugin.buildnumber>
<version.plugin.spotbugs>4.7.3.5</version.plugin.spotbugs>
<version.plugin.findsecbugs>1.12.0</version.plugin.findsecbugs>
<version.plugin.dependency-check>9.0.8</version.plugin.dependency-check>
<version.plugin.dependency-check>10.0.3</version.plugin.dependency-check>
</properties>

<modules>
Expand Down