HackToTech

Hack To Technology

SBOM周りを見てたのでメモ

Spring Boot 3.3でSBOMがサポートされたと聞いたので、どんなもんなのかを試していたのでメモ
(SBOMについて詳しく書いてある記事ではないので、そういった記事が見たい場合はブラウザバック推奨) spring.io

SBOMについては経産省の資料を見るのが良さそうだった www.meti.go.jp

で、この辺り全く詳しくなくて今回から何がどうサポートされたのかが全くわからなかったので、手を動かしながら試していた感じ
対象の gradle plugin を入れれば bootJar のタスク実行時に
JARMETA-INF/sbom/bom.json ( json かは指定によるはず)にSBOMを埋め込んでくれるという話だった github.com

あとは spring-boot-starter-actuator 入れて application.properties 設定しておけばactuator経由で公開できるようになっていたが、
内部的に見たいだけなら特にAPIで取得できなくても良さそうな気もした

普段は trivyJAR の入ったコンテナイメージの脆弱性スキャンをして併せてチェックしているが、
SBOM作ってそっちを trivyosv-scanner に食わせたほうが良かったりするのか気になる

適当にCVEがあるバージョンのライブラリを使ったアプリケーションで、SBOMを作って試して見る

作ったSBOM(直接埋め込むとかなり長いのでgistへのリンク) https://gist.github.com/atr0phy/0d853f5c251e7e20116d50ae78aabf58#file-sbom-json

trivy

$ trivy sbom bom.32.json
2024-05-25T20:44:07+09:00   INFO    Vulnerability scanning is enabled
2024-05-25T20:44:07+09:00   INFO    Detected SBOM format    format="cyclonedx-json"
2024-05-25T20:44:07+09:00   WARN    Third-party SBOM may lead to inaccurate vulnerability detection
2024-05-25T20:44:07+09:00   WARN    Recommend using Trivy to generate SBOMs
....

Java (jar)

Total: 8 (UNKNOWN: 0, LOW: 0, MEDIUM: 2, HIGH: 5, CRITICAL: 1)

┌────────────────────────────────────────────────┬────────────────┬──────────┬────────┬───────────────────┬─────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────┐
│                    Library                     │ Vulnerability  │ Severity │ Status │ Installed Version │                  Fixed Version                  │                            Title                             │
├────────────────────────────────────────────────┼────────────────┼──────────┼────────┼───────────────────┼─────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│ ch.qos.logback:logback-classic                 │ CVE-2023-6378  │ HIGH     │ fixed  │ 1.4.11            │ 1.3.12, 1.4.12, 1.2.13                          │ logback: serialization vulnerability in logback receiver     │
│                                                │                │          │        │                   │                                                 │ https://avd.aquasec.com/nvd/cve-2023-6378                    │
├────────────────────────────────────────────────┤                │          │        │                   │                                                 │                                                              │
│ ch.qos.logback:logback-core                    │                │          │        │                   │                                                 │                                                              │
│                                                │                │          │        │                   │                                                 │                                                              │
├────────────────────────────────────────────────┼────────────────┼──────────┤        ├───────────────────┼─────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│ org.apache.tomcat.embed:tomcat-embed-core      │ CVE-2024-24549 │ MEDIUM   │        │ 10.1.16           │ 8.5.99, 9.0.86, 10.1.19, 11.0.0-M17             │ : Apache Tomcat: HTTP/2 header handling DoS                  │
│                                                │                │          │        │                   │                                                 │ https://avd.aquasec.com/nvd/cve-2024-24549                   │
├────────────────────────────────────────────────┼────────────────┤          │        │                   ├─────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│ org.apache.tomcat.embed:tomcat-embed-websocket │ CVE-2024-23672 │          │        │                   │ 11.0.0-M17, 10.1.19, 9.0.86, 8.5.99             │ Apache Tomcat: WebSocket DoS with incomplete closing         │
│                                                │                │          │        │                   │                                                 │ handshake                                                    │
│                                                │                │          │        │                   │                                                 │ https://avd.aquasec.com/nvd/cve-2024-23672                   │
├────────────────────────────────────────────────┼────────────────┼──────────┤        ├───────────────────┼─────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│ org.postgresql:postgresql                      │ CVE-2024-1597  │ CRITICAL │        │ 42.7.1            │ 42.2.28, 42.3.9, 42.4.4, 42.5.5, 42.6.1, 42.7.2 │ pgjdbc: PostgreSQL JDBC Driver allows attacker to inject SQL │
│                                                │                │          │        │                   │                                                 │ if using PreferQueryMode=SIMPLE...                           │
│                                                │                │          │        │                   │                                                 │ https://avd.aquasec.com/nvd/cve-2024-1597                    │
├────────────────────────────────────────────────┼────────────────┼──────────┤        ├───────────────────┼─────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│ org.springframework:spring-web                 │ CVE-2024-22243 │ HIGH     │        │ 6.1.1             │ 6.1.4, 6.0.17, 5.3.32                           │ springframework: URL Parsing with Host Validation            │
│                                                │                │          │        │                   │                                                 │ https://avd.aquasec.com/nvd/cve-2024-22243                   │
│                                                ├────────────────┤          │        │                   ├─────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│                                                │ CVE-2024-22259 │          │        │                   │ 6.1.5, 6.0.18, 5.3.33                           │ springframework: URL Parsing with Host Validation            │
│                                                │                │          │        │                   │                                                 │ https://avd.aquasec.com/nvd/cve-2024-22259                   │
│                                                ├────────────────┤          │        │                   ├─────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────┤
│                                                │ CVE-2024-22262 │          │        │                   │ 5.3.34, 6.0.19, 6.1.6                           │ springframework: URL Parsing with Host Validation            │
│                                                │                │          │        │                   │                                                 │ https://avd.aquasec.com/nvd/cve-2024-22262                   │
└────────────────────────────────────────────────┴────────────────┴──────────┴────────┴───────────────────┴─────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────┘

trivyの方が修正バージョンも出ていて親切だが、省略した箇所に↓みたいなHASHのWARNが出てくるのだけ見づらいのでどうにかしたほうが良さそうだった

2024-05-25T20:43:52+09:00   WARN    Unsupported hash algorithm  algorithm="SHA3-384"
2024-05-25T20:43:52+09:00   WARN    Unsupported hash algorithm  algorithm="SHA3-256"
2024-05-25T20:43:52+09:00   WARN    Unsupported hash algorithm  algorithm="SHA3-512"

osv-scanner

$ osv-scanner scan --sbom bom.32.json 
Scanned /home/atr0phy/workspace/spring-boot-33/build/reports/bom.32.json as CycloneDX SBOM and found 40 packages
╭─────────────────────────────────────┬──────┬───────────┬────────────────────────────────────────────────┬─────────┬─────────────╮ ≈
│ OSV URL                             │ CVSS │ ECOSYSTEM │ PACKAGE                                        │ VERSION │ SOURCE      │
├─────────────────────────────────────┼──────┼───────────┼────────────────────────────────────────────────┼─────────┼─────────────┤ ≈
│ https://osv.dev/GHSA-24rp-q3w6-vc56 │ 10.0 │ Maven     │ org.postgresql:postgresql                      │ 42.7.1  │ bom.32.json │
│ https://osv.dev/GHSA-vmq6-5m68-f53m │ 7.1  │ Maven     │ ch.qos.logback:logback-core                    │ 1.4.11  │ bom.32.json │
│ https://osv.dev/GHSA-7w75-32cg-r6g2 │      │ Maven     │ org.apache.tomcat.embed:tomcat-embed-core      │ 10.1.16 │ bom.32.json │
│ https://osv.dev/GHSA-2wrp-6fg6-hmc5 │ 8.1  │ Maven     │ org.springframework:spring-web                 │ 6.1.1   │ bom.32.json │
│ https://osv.dev/GHSA-ccgv-vj62-xf9h │ 8.1  │ Maven     │ org.springframework:spring-web                 │ 6.1.1   │ bom.32.json │
│ https://osv.dev/GHSA-hgjh-9rj2-g67j │ 8.1  │ Maven     │ org.springframework:spring-web                 │ 6.1.1   │ bom.32.json │
│ https://osv.dev/GHSA-v682-8vv8-vpwr │      │ Maven     │ org.apache.tomcat.embed:tomcat-embed-websocket │ 10.1.16 │ bom.32.json │
│ https://osv.dev/GHSA-vmq6-5m68-f53m │ 7.1  │ Maven     │ ch.qos.logback:logback-classic                 │ 1.4.11  │ bom.32.json │
╰─────────────────────────────────────┴──────┴───────────┴────────────────────────────────────────────────┴─────────┴─────────────╯ ≈

試していた build.gradle.kts

上記のSBOM生成時は、複数の脆弱性が見たかったので id("org.springframework.boot") version "3.2.0" を使用した

import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    id("org.springframework.boot") version "3.3.0"
    id("io.spring.dependency-management") version "1.1.5"
    kotlin("jvm") version "1.9.24"
    kotlin("plugin.spring") version "1.9.24"
    id("org.cyclonedx.bom") version "1.8.2"
}

group = "com.github.atr0phy"
version = "0.0.1-SNAPSHOT"

java {
    sourceCompatibility = JavaVersion.VERSION_17
}

repositories {
    mavenCentral()
}

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-web")
    // implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    // わざとCVEの含まれるバージョンを入れる
    implementation("org.postgresql:postgresql:42.7.1")
    testImplementation("org.springframework.boot:spring-boot-starter-test")
    testRuntimeOnly("org.junit.platform:junit-platform-launcher")
}

tasks.withType<KotlinCompile> {
    kotlinOptions {
        freeCompilerArgs += "-Xjsr305=strict"
        jvmTarget = "17"
    }
}

tasks.withType<Test> {
    useJUnitPlatform()
}

tasks.cyclonedxBom {
    // ほぼ公式のサンプル通り
    setIncludeConfigs(listOf("runtimeClasspath"))
    setSkipConfigs(listOf("compileClasspath", "testCompileClasspath"))
    setProjectType("application")
    setSchemaVersion("1.5")
    setOutputName("bom")
    setOutputFormat("json")
    setIncludeBomSerialNumber(true)
    setIncludeLicenseText(true)
    setComponentVersion("2.0.0")
}