SoFunction
Updated on 2025-03-09

Implementation Guide for Dependency Vulnerability Checking with Maven

This article will cover the following:

  • What is Maven and why dependency vulnerability checking is required
  • Common dependency vulnerability checking tools and installation methods
  • Vulnerability checking using the OWASP Dependency-Check plugin
  • Vulnerability checking using the Sonatype Nexus IQ plugin
  • Dependency vulnerability checking in continuous integration

What is Maven and why dependency vulnerability checking is required

Introduction to Maven

Apache Maven is a popular project management and construction tool, mainly used in Java projects. It can simplify tasks such as project dependency management, construction, document generation, and project reporting.

Threats of dependency vulnerabilities

Although convenient and powerful, open source libraries are also susceptible to vulnerabilities and attacks. If your project relies on a vulnerable library, the vulnerability is likely to be a breakthrough for attackers. Therefore, conducting dependency vulnerability checks is a key step in ensuring project security.

Common dependency vulnerability checking tools and installation methods

1. OWASP Dependency-Check

OWASP Dependency-Checkis an open source tool for identifying known vulnerabilities in project dependencies. It can generate detailed reports to help developers fix these vulnerabilities.

Installation method

First, modify the projectFile to add the Dependency-Check plugin:

<build>
    <plugins>
        <plugin>
            <groupId></groupId>
            <artifactId>dependency-check-maven</artifactId>
            <version>6.5.3</version>
            <executions>
                <execution>
                    <goals>
                        <goal>check</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

2. Sonatype Nexus IQ

Sonatype Nexus IQis a commercial solution that provides in-depth dependency vulnerability analysis and automated repair suggestions.

Installation method

existAdd Nexus IQ plug-in to the file:

<build>
    <plugins>
        <plugin>
            <groupId></groupId>
            <artifactId>clm-maven-plugin</artifactId>
            <version>2.10.0-01</version>
            <configuration>
                <applicationId>your-application-id</applicationId>
                <serverUrl>https://your-nexus-iq-server</serverUrl>
            </configuration>
        </plugin>
    </plugins>
</build>

Vulnerability checking using the OWASP Dependency-Check plugin

Plug-in configuration

First, make sure that the plug-in mentioned above is correctly configured inmiddle.

Perform a check

Run the dependency vulnerability check by executing the following command:

mvn verify

This command will download all dependencies and check for known security vulnerabilities. After the inspection is completed, a report in HTML and XML format will be generated in the target directory, with the default path beingtarget/

Analysis Report

OpenFile, view the generated report. The report mainly contains the following information:

  • Dependency list: Lists all project dependencies.
  • Vulnerability details: Each detected vulnerability is listed in detail, including its severity score (CVSS), description and recommended solutions.

The results of this check can help developers quickly locate and fix known security vulnerabilities.

Vulnerability checking using the Sonatype Nexus IQ plugin

Plug-in configuration

Make sure you have followed the previous steps inThe Nexus IQ plugin has been added to the file.

Perform a check

Run the following command for dependency vulnerability check:

mvn :clm-maven-plugin:evaluate

This command uploads build information to Nexus IQ Server and generates a detailed inspection report.

Analysis Report

In the Nexus IQ Server web interface, you can view detailed dependency analysis reports. Again, these reports contain a list of dependencies and detailed vulnerability information. In addition, Nexus IQ also provides automatic repair suggestions and fix solutions to enable developers to solve problems faster.

Dependency vulnerability checking in continuous integration

Integrating dependency vulnerability inspection into a continuous integration (CI) environment is a best practice for ensuring security and timely detection of vulnerabilities. Here are ways to integrate vulnerability checking into common CI tools:

Jenkins

In Jenkins, you can integrate OWASP Dependency-Check or Sonatype Nexus IQ by configuring Jenkinsfile.

OWASP Dependency-Check Configuration Example

pipeline {
    agent any

    stages {
        stage('Dependency-Check') {
            steps {
                sh 'mvn verify'
                // Archive generated report                archiveArtifacts 'target/'
                publishHTML(target: [
                    allowMissing: false,
                    alwaysLinkToLastBuild: true,
                    keepAll: true,
                    reportDir: 'target',
                    reportFiles: '',
                    reportName: 'Dependency-Check Report'
                ])
            }
        }
    }
}

Sonatype Nexus IQ configuration example

pipeline {
    agent any

    stages {
        stage('Nexus IQ') {
            steps {
                sh 'mvn :clm-maven-plugin:evaluate'
            }
        }
    }
}

GitLab CI

In GitLab CI, you can use.Configure the file.

OWASP Dependency-Check Configuration Example

stages:
  - security

dependency-check:
  stage: security
  image: maven:3.6.3-jdk-11
  script:
    - mvn verify
  artifacts:
    paths:
      - target/

Sonatype Nexus IQ configuration example

stages:
  - security

nexus-iq:
  stage: security
  image: maven:3.6.3-jdk-11
  script:
    - mvn :clm-maven-plugin:evaluate

GitHub Actions

GitHub Actions provides excellent flexibility for dependency vulnerability checks.

OWASP Dependency-Check Configuration Example

name: Dependency-Check

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: '11'
      - name: Build with Maven
        run: mvn verify
      - name: Upload Dependency-Check Report
        uses: actions/upload-artifact@v2
        with:
          name: dependency-check-report
          path: target/

Sonatype Nexus IQ configuration example

name: Nexus-IQ

on: [push]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: '11'
      - name: Build with Maven
        run: mvn :clm-maven-plugin:evaluate

Summarize

Performing dependency vulnerability checks is an important step in ensuring the security of software projects. By using tools like OWASP Dependency-Check and Sonatype Nexus IQ, developers can effectively identify and fix known vulnerabilities in dependencies. Integrating these checks into a continuous integration platform ensures security reviews are conducted at every stage of development, thereby improving the security and robustness of the project.

The above is the detailed content of the implementation guide for using Maven for dependency vulnerability checking. For more information about Maven's dependency vulnerability checking, please pay attention to my other related articles!