Skip to content

Commit

Permalink
Added severity score vector (#2569)
Browse files Browse the repository at this point in the history
* Added severity score vector
  • Loading branch information
Cheshiriks authored Sep 11, 2023
1 parent e34bab5 commit 9db8b12
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 12 deletions.
7 changes: 7 additions & 0 deletions db/v-2/tables/cosv-metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,11 @@
<changeSet id="cosv-metadata-4" author="nulls">
<renameColumn tableName="cosv_metadata" oldColumnName="published" newColumnName="submitted" columnDataType="DATETIME(3)"/>
</changeSet>

<changeSet id="cosv-metadata-5" author="frolov">
<dropColumn tableName="cosv_metadata">
<column name="severity"/>
</dropColumn>
</changeSet>

</databaseChangeLog>
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ class VulnerabilityService(
cosvId = "default-${Random.nextInt()}",
summary = "STUB",
details = "STUB",
severity = null,
severityNum = 0,
submitted = getCurrentLocalDateTime().toJavaLocalDateTime(),
modified = getCurrentLocalDateTime().toJavaLocalDateTime(),
Expand All @@ -229,7 +228,7 @@ class VulnerabilityService(
)
)
val newName = "SOTV-${getCurrentLocalDateTime().year}-${metadata.requiredId()}"
cosvMetadataRepository.saveAndFlush(metadata.apply {
cosvMetadataRepository.save(metadata.apply {
cosvId = newName
})
newName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import kotlinx.datetime.LocalDateTime
* @property cosvId [com.saveourtool.osv4k.OsvSchema.id]
* @property summary [com.saveourtool.osv4k.OsvSchema.summary]
* @property details [com.saveourtool.osv4k.OsvSchema.details]
* @property severity [com.saveourtool.osv4k.Severity.score]
* @property severityNum [com.saveourtool.osv4k.Severity.scoreNum]
* @property modified [com.saveourtool.osv4k.OsvSchema.modified]
* @property submitted
Expand All @@ -24,7 +23,6 @@ data class CosvMetadataDto(
val cosvId: String,
val summary: String,
val details: String,
val severity: String?,
val severityNum: Int,
val modified: LocalDateTime,
val submitted: LocalDateTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import kotlinx.serialization.Serializable
* @property creationDateTime [LocalDateTime] of creation
* @property lastUpdatedDateTime [LocalDateTime] of last updating
* @property tags
* @property severity
*/
@Serializable
data class VulnerabilityDto(
Expand All @@ -41,6 +42,7 @@ data class VulnerabilityDto(
val creationDateTime: LocalDateTime? = null,
val lastUpdatedDateTime: LocalDateTime? = null,
val tags: Set<String> = emptySet(),
val severity: String = "",
) {
/**
* @return map where key is LocalDateTime and value is a label of LocalDateTime
Expand Down Expand Up @@ -77,7 +79,6 @@ data class VulnerabilityDto(
)
val vulnerabilityPrefixes = listOf(
"CVE-",

)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,8 @@ const val CVE_NAME_ERROR_MESSAGE = "CVE identifier is invalid"
* Error message that is shown when tag is invalid.
*/
const val TAG_ERROR_MESSAGE = "Tag length should be in [3, 15] range, no commas are allowed."

/**
* Error message that is shown when severity score vector is invalid.
*/
const val SEVERITY_VECTOR_ERROR_MESSAGE = "Severity score vector is invalid"
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import kotlinx.datetime.toKotlinLocalDateTime
* @property cosvId [com.saveourtool.osv4k.OsvSchema.id]
* @property summary [com.saveourtool.osv4k.OsvSchema.summary]
* @property details [com.saveourtool.osv4k.OsvSchema.details]
* @property severity [com.saveourtool.osv4k.Severity.score]
* @property severityNum [com.saveourtool.osv4k.Severity.scoreNum]
* @property modified [com.saveourtool.osv4k.OsvSchema.modified]
* @property submitted when vulnerability submitted to saveourtool platform
Expand All @@ -31,7 +30,6 @@ class CosvMetadata(
var cosvId: String,
var summary: String,
var details: String,
var severity: String?,
var severityNum: Int,
var modified: LocalDateTime,
var submitted: LocalDateTime,
Expand All @@ -50,7 +48,6 @@ class CosvMetadata(
cosvId = cosvId,
summary = summary,
details = details,
severity = severity,
severityNum = severityNum,
modified = modified.toKotlinLocalDateTime(),
submitted = submitted.toKotlinLocalDateTime(),
Expand All @@ -74,7 +71,6 @@ class CosvMetadata(
cosvId = cosvId,
summary = summary,
details = details,
severity = severity,
severityNum = severityNum,
modified = modified.toJavaLocalDateTime(),
submitted = submitted.toJavaLocalDateTime(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ class CosvRepositoryInStorage(
cosvId = id,
summary = summary ?: "Summary not provided",
details = details ?: "Details not provided",
severity = severity?.firstOrNull()?.score,
severityNum = severity?.firstOrNull()?.scoreNum?.toInt() ?: 0,
modified = modified.toJavaLocalDateTime(),
submitted = getCurrentLocalDateTime().toJavaLocalDateTime(),
Expand All @@ -149,7 +148,6 @@ class CosvRepositoryInStorage(
private fun CosvMetadata.updateBy(entry: CosvSchema<*, *, *, *>): CosvMetadata = apply {
summary = entry.summary ?: "Summary not provided"
details = entry.details ?: "Details not provided"
severity = entry.severity?.firstOrNull()?.score
severityNum = entry.severity?.firstOrNull()
?.scoreNum
?.toInt() ?: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CosvService(
severity = listOf(
Severity(
type = SeverityType.CVSS_V3,
score = "N/A",
score = vulnerabilityDto.severity,
scoreNum = vulnerabilityDto.progress.toString(),
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.saveourtool.save.validation.*

private const val URL_PLACEHOLDER = "https://example.com"
private const val EMAIL_PLACEHOLDER = "[email protected]"
private const val SEVERITY_VECTOR_PLACEHOLDER = "CVSS:3.1/AV:_/AC:_/PR:_/UI:_/S:_/C:_/I:_/A:_"

private const val NAME_TOOLTIP = "Allowed symbols: letters, digits, dots, hyphens and underscores." +
"No dot, hyphen or underscore at the beginning and at the end of the line."
Expand All @@ -18,6 +19,9 @@ private const val NAME_ORG_PROJECT_TOOLTIP = "Name must not be longer than $NAMI
"Allowed symbols: letters, digits, dots, hyphens and underscores." +
"No dot, hyphen or underscore at the beginning and at the end of the line."

private const val SEVERITY_VECTOR_TOOLTIP = "It's a string representation of the Common Vulnerability Scoring System (CVSS)." +
"If you know it, please indicate in this field."

/**
* @property str
* @property placeholder
Expand Down Expand Up @@ -148,6 +152,12 @@ enum class InputTypes(
tooltip = "If you know the vulnerability identifier, you can enter it here",
),
CVE_DATE("CVE date"),
COSV_VECTORE(
"Severity score vector",
SEVERITY_VECTOR_ERROR_MESSAGE,
placeholder = SEVERITY_VECTOR_PLACEHOLDER,
tooltip = SEVERITY_VECTOR_TOOLTIP,
),
;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ val createVulnerabilityView: VFC = VFC {
}
}

inputTextFormOptional {
form = InputTypes.COSV_VECTORE
textValue = vulnerability.relatedLink
classes = "col-12 my-2 px-2 text-left"
name = "Severity score vector"
onChangeFun = { event -> setVulnerability { it.copy(severity = event.target.value) } }
}

div {
className = ClassName("col-12 my-2 px-2 text-left")
label {
Expand Down

0 comments on commit 9db8b12

Please sign in to comment.