LoginSignup
7
2

More than 5 years have passed since last update.

OWASP Dependency-check-mavenを使ってmavenで管理している依存ライブラリの脆弱性をスキャン

Posted at

OWASP Dependency-Checkを使って依存ライブラリの脆弱性をスキャン
http://qiita.com/0x003f/items/c594c912cb7dc15b7284
にて書いたdependency-checkのmaven plugin版の使い方になります。

そもそもOWASP Dependency-Checkって何よ?という方はまず前述の記事をご覧になっていただければと思います。

maven版は「高い脆弱性が報告されている場合はビルド時にエラーを起こす」などのオプションを有効活用できます。

Dependency-Check Mavenの利用方法

以下のように、mavenでビルドの設定を書き込む pom.xml のpluginのところに dependency-check-maven を書き込みます。


<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
              <groupId>org.owasp</groupId>
              <artifactId>dependency-check-maven</artifactId>
              <version>1.4.5</version>
              <executions>
                  <execution>
                      <goals>
                          <goal>check</goal>
                      </goals>
                  </execution>
              </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>

<goal> </goal> 部分は、

  • check: dependency-checkを実行して指定された形式のレポートを出力する(デフォルトHTML)
  • aggregate: pom.xml が子ディレクトリで存在しているようなプロジェクトのとき、結果をまとめてくれます
  • update-only: NVDのアップデートのみを行います
  • purge: localに保存しているNVDのデータを削除します

の4つが記述可能です。

まずは示したとおりに記述したら

% mvn dependency-check:check

と、mvnコマンドを実行すると、checkが走り、CLI版と同様の動作をしてくれます。

オプション等について

基本的には先程のwikiに例が載っているのでそちらを参照するのが正確ですが、いくつかオプションを紹介しておきます。

[configurations] https://jeremylong.github.io/DependencyCheck/dependency-check-maven/configuration.html

XMLフォーマットで出力したい

<configuration> </configuration> の間に <format> XML </format> を記述します。
同様に HTML , VULN も指定できます。


<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
              <groupId>org.owasp</groupId>
              <artifactId>dependency-check-maven</artifactId>
              <version>1.4.5</version>
              <configuration>
                  <format> XML </format>
              </configuration>
              <executions>
                  <execution>
                      <goals>
                          <goal>check</goal>
                      </goals>
                  </execution>
              </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>

CVSS 8.0以上の脆弱性がある場合ビルドを失敗させたい


<project>
    ...
    <build>
        ...
        <plugins>
            ...
            <plugin>
              <groupId>org.owasp</groupId>
              <artifactId>dependency-check-maven</artifactId>
              <version>1.4.5</version>
              <configuration>
                  <failBuildOnCVSS>8</failBuildOnCVSS>
              </configuration>
              <executions>
                  <execution>
                      <goals>
                          <goal>check</goal>
                      </goals>
                  </execution>
              </executions>
            </plugin>
            ...
        </plugins>
        ...
    </build>
    ...
</project>
7
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
2