代码依赖包漏洞检查maven插件–dependency-check-maven。通过这个插件可以扫描出项目中是否依赖已经存在的安全漏洞包

如何使用

前置条件:该插件需要使用maven 3.1或更高版本

原始地址https://jeremylong.github.io/DependencyCheck/index.html dependency-check – About (jeremylong.github.io)

1、在项目pom引入dependency-check-maven插件
<build>
<plugins>
<plugin>
<groupId>org.owasp</groupId>
<artifactId>dependency-check-maven</artifactId>
<version>7.0.0</version>
<configuration>
<autoUpdate>true</autoUpdate>
</configuration>
<executions>
<execution>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
  1. 切换到项目的target目录,执行mvn dependency-check:check

  1. idea,可以直接如下,右键运行

第一次执行的话,他的速度会挺慢的,因为他需要从NIST托管的国家漏洞数据库下载漏洞数据到本地备份库。

在执行的过程中,可能会出现

Failed to initialize the RetireJS repo

One or more exceptions occurred during analysis:

UpdateException: Failed to initialize the RetireJS repo

caused by DownloadFailedException: Download failed, unable to copy 'https://raw.githubusercontent.com/Retirejs/retire.js/master/repository/jsrepository.json' to 'd:\m2\repository\org\owasp\dependency-check-utils\7.0.0\..\..\dependency-check-data\7.0\jsrepository.json'; Error downloading file https://raw.githubusercontent.com/Retirejs/retire.js/master/repository/jsrepository.json; unable to connect.

caused by DownloadFailedException: Error downloading file https://raw.githubusercontent.com/Retirejs/retire.js/master/repository/jsrepository.json; unable to connect.

caused by SocketTimeoutException: Read timed out

NoDataException: No documents exist

解决的办法

下载jsrepository.json并将该文件放到maven私仓地址\org\owasp\dependency-check-data\7.0目录下

执行完毕后,会在target目录下产生dependency-check-report.html文件

3、通过浏览器打开dependency-check-report.html

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
GitLab-CI/CD可以很方便地集成Dependency-Check来实现依赖扫描。下面是具体的集成步骤: 1. 安装Dependency-Check 首先需要安装Dependency-Check工具。可以到官网下载对应的软件,然后解压到任意目录即可。 2. 配置GitLab-CI/CD 在项目的根目录下创建一个名为`.gitlab-ci.yml`的文件,并添加以下内容: ``` image: maven:3.6.3-jdk-11 stages: - build - test - dependency-check before_script: - mvn --version build: stage: build script: - mvn clean package test: stage: test script: - mvn test dependency-check: stage: dependency-check script: - wget https://dl.bintray.com/jeremy-long/owasp/dependency-check-5.3.2-release.zip - unzip dependency-check-5.3.2-release.zip - cd dependency-check-5.3.2-release/bin - ./dependency-check.sh --project "My Project" --scan ./../../target/*.jar --out ./../../dependency-check-report artifacts: paths: - dependency-check-report ``` 以上配置文件定义了三个阶段:build、test和dependency-check。其,build和test阶段是项目的编译和测试阶段,dependency-check阶段是依赖扫描阶段。在dependency-check阶段,我们下载并安装了Dependency-Check工具,并使用它来扫描项目依赖关系。扫描结果将以HTML报告的形式保存在`dependency-check-report`目录下。 3. 提交并运行Pipeline 将`.gitlab-ci.yml`文件提交到项目的Git仓库,并在GitLab上开启CI/CD功能。然后,就可以运行Pipeline了。Pipeline运行结束后,可以在GitLab的Pipeline页面查看扫描结果。 以上就是集成Dependency-Check的具体步骤,希望可以帮到你。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值