Core Java

Java Maven OWASP Dependency-Check Example

With the increasing use of open-source libraries, ensuring software security has become a critical aspect of development. Many applications rely on third-party components, making them vulnerable to potential security threats. OWASP Dependency-Check is a powerful tool that helps developers identify known vulnerabilities in project dependencies. It scans dependencies against a vulnerability database and provides a report highlighting any issues. Software vulnerabilities can lead to serious security threats such as data breaches, unauthorized access, or malware injection. Attackers often exploit known vulnerabilities in libraries to gain unauthorized control over applications. Therefore, regularly checking for dependency vulnerabilities is an essential step in maintaining secure software. Let us delve into understanding how to use OWASP Dependency-Check in Java and Maven and its significance in securing project dependencies.

1. What is Dependency-Check?

OWASP Dependency-Check is an open-source tool developed by OWASP that helps identify vulnerabilities in project dependencies. It works by:

  • Scanning project dependencies.
  • Matching dependencies with known vulnerabilities from the National Vulnerability Database (NVD).
  • Generating reports that indicate vulnerable components and their severity levels.

Dependency-Check supports multiple build systems, including Maven, Gradle, Ant, and CLI. By integrating Dependency-Check into the development workflow, developers can proactively detect and mitigate security risks, ensuring a more secure software supply chain.

2. Maven Setup

To integrate OWASP Dependency-Check into a Maven-based project for automated scanning during the build process, follow these steps:

2.1 Add Plugin to pom.xml

Include the following dependency-check plugin in your pom.xml file to enable automatic vulnerability scanning:

01
02
03
04
05
06
07
08
09
10
11
12
<plugin>
    <groupId>org.owasp</groupId>
    <artifactId>dependency-check-maven</artifactId>
    <version>8.4.0</version>
    <executions>
        <execution>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
</plugin>

2.1.1 Configure Dependency-Check Execution

By default, the plugin runs the check goal, but you can customize its execution by adding configuration parameters such as:

  • Fail Build on Vulnerability: Set thresholds to fail the build if high-severity vulnerabilities are found.
  • Report Format: Generate reports in HTML, XML, JSON, or CSV formats.
  • Suppression Files: Exclude false positives using custom suppression files.

Below is the XML snippet showcasing the configuration options:

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
<plugin>
    <groupId>org.owasp</groupId>
    <artifactId>dependency-check-maven</artifactId>
    <version>8.4.0</version>
    <executions>
        <execution>
            <goals>
                <goal>check</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <failBuildOnCVSS>7.0</failBuildOnCVSS>
        <formats>HTML, JSON</formats>
        <outputDirectory>${project.build.directory}/dependency-check-report</outputDirectory>
        <suppressionFile>${project.basedir}/dependency-check-suppression.xml</suppressionFile>
    </configuration>
</plugin>

2.2 Running the Dependency-Check

Once the dependency-check plugin is added, run the following Maven command to perform a security scan:

1
mvn dependency-check:check

The command will analyze the project dependencies and compare them against the National Vulnerability Database (NVD). After successfully executing the command, the following output will be generated.

01
02
03
04
05
06
07
08
09
10
11
[INFO] Checking for updates...
[INFO] Updating NVD database...
[INFO] Scanning dependencies...
[INFO] Found vulnerabilities in the following dependencies:
 
+----------------+----------------+------------+--------------------------------+
| Dependency    | CVE ID        | CVSS Score | Severity                      |
+----------------+----------------+------------+--------------------------------+
| log4j-core-2.14.1.jar | CVE-2021-44228 | 10.0 | Critical - Remote Code Exec  |
| jackson-databind-2.9.9.jar | CVE-2019-12384 | 7.5 | High - Deserialization Issue |
+----------------+----------------+------------+--------------------------------+

2.2.1 CVSS Score

The Common Vulnerability Scoring System (CVSS) is a standardized method for assessing the severity of security vulnerabilities. Dependency-Check provides CVSS scores for identified vulnerabilities, helping developers prioritize security fixes. The CVSS score ranges from 0 to 10:

  • 0.0 – 3.9: Low severity
  • 4.0 – 6.9: Medium severity
  • 7.0 – 8.9: High severity
  • 9.0 – 10.0: Critical severity

For example, CVE-2021-44228 (Log4Shell) has a CVSS score of 10.0, indicating a critical severity that needs immediate remediation.

3. Integrating into CI/CD Pipeline

To ensure continuous security, integrate OWASP Dependency-Check into CI/CD pipelines. Here’s an example of how to run the check in a Jenkins pipeline:

01
02
03
04
05
06
07
08
09
10
pipeline {
    agent any
    stages {
        stage('Dependency Check') {
            steps {
                sh 'mvn dependency-check:check'
            }
        }
    }
}

This ensures that every build is checked for vulnerabilities before deployment.

4. Conclusion

Security is a crucial aspect of software development. OWASP Dependency-Check helps developers identify and mitigate risks associated with vulnerable dependencies. By regularly scanning projects, using CVSS scores to assess risks, and integrating checks into CI/CD pipelines, developers can enhance application security. Adopting security practices early in the development lifecycle reduces the risk of cyberattacks and ensures software reliability. Keep your dependencies up to date and monitor vulnerabilities regularly to maintain a secure codebase.

Yatin Batra

An experience full-stack engineer well versed with Core Java, Spring/Springboot, MVC, Security, AOP, Frontend (Angular & React), and cloud technologies (such as AWS, GCP, Jenkins, Docker, K8).
Subscribe
Notify of
guest


This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button