feat: typed CVSS score-map constructors - #802
Conversation
The typed accessors on ContentTrait (csaf-rs#715) cover the read direction; construction still goes through the untyped serde_json maps the CSAF schemas declare for cvss_v2/cvss_v3/cvss_v4. Add the write direction: - cvss_v2_to_score_map / cvss_v3_to_score_map / cvss_v4_to_score_map render a typed cvss-rs model into the JSON object the property carries (the Cvss enum itself has no Serialize impl; the per-version structs serialize to exactly the FIRST schema shape). - cvss_v2/cvss_v3/cvss_v4_score_map_from_vector parse a vector string and recompute the base score and severity band from the metrics, so the mandatory consistency tests 6.1.9/6.1.10 hold by construction. This makes the cvss module public; the validate_* helpers it already carried become public API with it.
|
|
||
| /// The CVSS v3.x severity band of a base score. | ||
| fn v3_severity(score: f64) -> cvss_rs::v3::Severity { | ||
| use cvss_rs::v3::Severity; |
There was a problem hiding this comment.
It might make sense to use map_score_to_severity here, this is the existing implementation used for the tests and also cares about correct rounding.
(Looking at that, I just realized that test 6.1.9 does not yet check the severity for CVSS 2.0, #806, so the corresponding function for 2.0 does not yet exist)
|
|
||
| /// The CVSS v2.0 severity band of a base score. | ||
| fn v2_severity(score: f64) -> cvss_rs::v2_0::Severity { | ||
| use cvss_rs::v2_0::Severity; |
There was a problem hiding this comment.
We are currently in discussion, but the official first.org JSON schema for CVSS v2.0 does not include a "severity" field, so CSAF will likely reject documents that contain it. Severity will only be allowed starting with CVSS v3.
|
Thanks for both comments, @aschierl-xitaso. Here is where I landed before pushing the next commits. CVSS v2.0 severity I checked the schema at https://www.first.org/cvss/cvss-v2.0.json to ground the decision. It defines 19 properties with I will therefore drop the Severity banding for v3/v4 Agreed on reusing Missing required While grounding the severity question in the schemas I noticed a gap in the current commits: all four FIRST schemas list Public surface of One question back to you: the PR currently flips |
|
I wouldn't expose the CVSS functionality here. Long term, these things should be part of cvss-rs itself. |
Opened two (of a series of) PRs, proposing this to cvss-rs: |
The typed CVSS accessors on
ContentTrait(#715) cover the read direction for the untypedcvss_v2/cvss_v3/cvss_v4score maps. The write direction still forces consumers to hand-buildserde_jsonmaps. This adds the construction counterpart:cvss_v2_to_score_map/cvss_v3_to_score_map/cvss_v4_to_score_maprender a typedcvss-rsmodel into the JSON object the property carries. (TheCvssenum itself has noSerializeimpl; the per-version structs do, and their serde shape is exactly the FIRST schema's.)cvss_v2_score_map_from_vector/cvss_v3_score_map_from_vector/cvss_v4_score_map_from_vectorparse a vector string and recompute the base score and severity band from the parsed metrics, so the mandatory consistency tests 6.1.9/6.1.10 hold by construction — an emitted document can never disagree with its own vectors.The
cvssmodule becomes public for this; thevalidate_*helpers it already carried become public API with it (happy to scope thosepub(crate)instead if you'd rather keep the surface minimal).Motivation
A downstream SBOM/vulnerability tool emitting CSAF 2.0 currently rebuilds these JSON maps metric-by-metric to keep 6.1.9/6.1.10 green. With the typed models already in the tree, the crate can offer that construction once, for everyone.
Notes
calculated_base_scorereturnsNone).cvss_rs::ParseErrorfrom the vectorFromStrimpls.