Skip to content

Commit dc27c01

Browse files
committed
feat(vulnerable-code): Support getting summary / description information
Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent b76402b commit dc27c01

File tree

4 files changed

+43
-6
lines changed

4 files changed

+43
-6
lines changed

clients/vulnerable-code/src/main/kotlin/VulnerableCodeService.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.ossreviewtoolkit.clients.vulnerablecode
2121

22+
import kotlinx.serialization.SerialName
2223
import kotlinx.serialization.Serializable
2324
import kotlinx.serialization.json.Json
2425
import kotlinx.serialization.json.JsonNames
@@ -129,6 +130,10 @@ interface VulnerableCodeService {
129130
/** The VulnerableCode-specific identifier for this vulnerability. */
130131
val vulnerabilityId: String,
131132

133+
/** A description of the vulnerability. Older versions of VulnerableCode do not have this field. */
134+
@SerialName("summary")
135+
val description: String? = null,
136+
132137
/** A list with [VulnerabilityReference]s pointing to sources of information about this vulnerability. */
133138
val references: List<VulnerabilityReference>,
134139

plugins/advisors/vulnerable-code/src/funTest/kotlin/VulnerableCodeFunTest.kt

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ class VulnerableCodeFunTest : WordSpec({
4646
"CVE-2023-49295"
4747
)
4848

49-
getValue("CVE-2023-49295").references.find {
49+
val vulnerability = getValue("CVE-2023-49295")
50+
vulnerability.summary shouldBe "quic-go is an implementation of the QUIC protocol (RFC 9000, RFC..."
51+
52+
vulnerability.references.find {
5053
it.url.toString() == "https://nvd.nist.gov/vuln/detail/CVE-2023-49295"
5154
} shouldNotBeNull {
5255
scoringSystem shouldBe "cvssv3"
@@ -74,7 +77,10 @@ class VulnerableCodeFunTest : WordSpec({
7477
"CVE-2023-2976"
7578
)
7679

77-
getValue("CVE-2023-2976").references.find {
80+
val vulnerability = getValue("CVE-2023-2976")
81+
vulnerability.summary shouldBe "Use of Java's default temporary directory for file creation in `..."
82+
83+
vulnerability.references.find {
7884
it.url.toString() == "https://nvd.nist.gov/vuln/detail/CVE-2023-2976"
7985
} shouldNotBeNull {
8086
scoringSystem shouldBe "cvssv3"
@@ -98,7 +104,10 @@ class VulnerableCodeFunTest : WordSpec({
98104
"CVE-2023-42503"
99105
)
100106

101-
getValue("CVE-2023-42503").references.find {
107+
val vulnerability = getValue("CVE-2023-42503")
108+
vulnerability.summary shouldBe "Improper Input Validation, Uncontrolled Resource Consumption vul..."
109+
110+
vulnerability.references.find {
102111
it.url.toString() == "https://nvd.nist.gov/vuln/detail/CVE-2023-42503"
103112
} shouldNotBeNull {
104113
scoringSystem shouldBe "cvssv3"
@@ -124,7 +133,10 @@ class VulnerableCodeFunTest : WordSpec({
124133
"CVE-2024-48948"
125134
)
126135

127-
getValue("CVE-2024-48948").references.find {
136+
val vulnerability = getValue("CVE-2024-48948")
137+
vulnerability.summary shouldBe "The Elliptic package 6.5.7 for Node.js, in its for ECDSA impleme..."
138+
139+
vulnerability.references.find {
128140
it.url.toString() == "https://github.com/indutny/elliptic"
129141
} shouldNotBeNull {
130142
scoringSystem shouldBe "cvssv3.1"

plugins/advisors/vulnerable-code/src/main/kotlin/VulnerableCode.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ import org.ossreviewtoolkit.utils.ort.OkHttpClientHelper
5757
*/
5858
private const val BULK_REQUEST_SIZE = 100
5959

60+
/**
61+
* The maximum length for the summary as derived from the description of a vulnerability.
62+
*/
63+
private const val MAX_SUMMARY_LENGTH = 64
64+
6065
/**
6166
* An [AdviceProvider] implementation that obtains security vulnerability information from a
6267
* [VulnerableCode][https://github.com/aboutcode-org/vulnerablecode] instance.
@@ -133,8 +138,19 @@ class VulnerableCode(
133138
* Convert this vulnerability from the VulnerableCode data model to a [Vulnerability]. Populate [issues] if this
134139
* fails.
135140
*/
136-
private fun VulnerableCodeService.Vulnerability.toModel(issues: MutableList<Issue>): Vulnerability =
137-
Vulnerability(id = preferredCommonId(), references = references.flatMap { it.toModel(issues) })
141+
private fun VulnerableCodeService.Vulnerability.toModel(issues: MutableList<Issue>): Vulnerability {
142+
val description = description?.ifBlank { null }
143+
return Vulnerability(
144+
id = preferredCommonId(),
145+
// VulnerableCode API v1 has no dedicated summary field (its summary actually is the description), so try to
146+
// summarize the description.
147+
summary = description?.take(MAX_SUMMARY_LENGTH)?.let {
148+
if (it.length < description.length) "$it..." else it
149+
},
150+
description = description,
151+
references = references.flatMap { it.toModel(issues) }
152+
)
153+
}
138154

139155
/**
140156
* Convert this reference from the VulnerableCode data model to a list of [VulnerabilityReference] objects.

plugins/advisors/vulnerable-code/src/test/kotlin/VulnerableCodeTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,8 @@ class VulnerableCodeTest : WordSpec({
193193
val expLog4jVulnerabilities = listOf(
194194
Vulnerability(
195195
id = "GHSA-jfh8-c2jp-5v3q",
196+
summary = "Remote code injection in Log4j",
197+
description = "Remote code injection in Log4j",
196198
references = listOf(
197199
VulnerabilityReference(
198200
URI("http://ref.com/files/165225/Apache-Log4j2-2.14.1-Remote-Code-Execution.html"),
@@ -205,6 +207,8 @@ class VulnerableCodeTest : WordSpec({
205207
),
206208
Vulnerability(
207209
id = "CVE-2021-44832",
210+
summary = "Improper Input Validation and Injection in Apache Log4j2",
211+
description = "Improper Input Validation and Injection in Apache Log4j2",
208212
references = listOf(
209213
VulnerabilityReference(
210214
URI("https://access.redhat.com/hydra/rest/securitydata/cve/CVE-2021-44832.json"),

0 commit comments

Comments
 (0)