From 842d03afd52f4c6631eb1ba91a341062d8f95610 Mon Sep 17 00:00:00 2001 From: hive-bumblebee Date: Thu, 19 Nov 2026 18:34:40 +0000 Subject: [PATCH 1/3] feat(results): preserve open NVT type discriminator (#735) --- crates/gvm-gateway-domain/src/lib_test.rs | 2 ++ crates/gvm-gateway-domain/src/results.rs | 3 +++ crates/gvm-gateway-gvmd/src/conversions.rs | 6 ++++- crates/gvm-gateway-rest/src/reports_test.rs | 2 ++ crates/gvm-gateway-rest/src/results.rs | 6 +++++ crates/gvm-gateway-rest/src/results_test.rs | 28 +++++++++++++++++++++ docs/report-projection-adoption.md | 4 +++ spec/rest-api/results.yaml | 6 +++++ worklog.md | 1 + 9 files changed, 57 insertions(+), 1 deletion(-) diff --git a/crates/gvm-gateway-domain/src/lib_test.rs b/crates/gvm-gateway-domain/src/lib_test.rs index d3f15f46..9fbf0fb3 100644 --- a/crates/gvm-gateway-domain/src/lib_test.rs +++ b/crates/gvm-gateway-domain/src/lib_test.rs @@ -456,6 +456,7 @@ fn scan_result_serializes_camel_case() { cvss_base: Some(9.8), cves: vec!["CVE-2024-1234".to_string()], tags: None, + type_: None, type_metadata: None, epss: None, }), @@ -523,6 +524,7 @@ fn nvt_ref_omits_empty_cves() { cvss_base: None, cves: vec![], tags: None, + type_: None, type_metadata: None, epss: None, }; diff --git a/crates/gvm-gateway-domain/src/results.rs b/crates/gvm-gateway-domain/src/results.rs index dfeca149..7d7bc02c 100644 --- a/crates/gvm-gateway-domain/src/results.rs +++ b/crates/gvm-gateway-domain/src/results.rs @@ -82,6 +82,9 @@ pub struct NvtRef { #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option, /// Source-shaped NVT type metadata supplied by gvmd. + /// Open discriminator supplied by the typed NVT source. + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + pub type_: Option, #[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")] pub type_metadata: Option, /// EPSS selections supplied by gvmd for this NVT. diff --git a/crates/gvm-gateway-gvmd/src/conversions.rs b/crates/gvm-gateway-gvmd/src/conversions.rs index 9cbaf36f..18a7f04d 100644 --- a/crates/gvm-gateway-gvmd/src/conversions.rs +++ b/crates/gvm-gateway-gvmd/src/conversions.rs @@ -500,6 +500,7 @@ pub(crate) fn result_from_gmp( cvss_base, cves: n.cves, tags: n.tags, + type_: n.type_, type_metadata: n.type_metadata, epss: n.epss.map(epss_from_gmp).transpose()?, }) @@ -546,6 +547,7 @@ pub(crate) fn result_from_report_vulnerability( cvss_base: None, cves: vulnerability.cves, tags: None, + type_: None, type_metadata: None, epss: None, }), @@ -595,6 +597,7 @@ pub(crate) fn report_closed_cve_from_gmp( cvss_base: None, cves: closed_cve.cve.clone().into_iter().collect(), tags: None, + type_: None, type_metadata: None, epss: None, }), @@ -1140,7 +1143,8 @@ fn nvt_ref_from_gmp(nvt: gvm_gmp::responses::common::NvtReference) -> NvtRef { NvtRef { oid: Some(nvt.oid), name: nvt.name, - family: nvt.type_, + family: None, + type_: nvt.type_, cvss_base: None, cves: vec![], tags: None, diff --git a/crates/gvm-gateway-rest/src/reports_test.rs b/crates/gvm-gateway-rest/src/reports_test.rs index 3c62ed17..7d1589ff 100644 --- a/crates/gvm-gateway-rest/src/reports_test.rs +++ b/crates/gvm-gateway-rest/src/reports_test.rs @@ -147,6 +147,7 @@ fn report_vulnerability_response_preserves_aggregate_fields() { cvss_base: None, cves: vec!["CVE-2026-0001".to_string()], tags: None, + type_: None, type_metadata: None, epss: None, }), @@ -218,6 +219,7 @@ fn report_closed_cve_response_preserves_closed_cve_fields() { cvss_base: None, cves: vec!["CVE-2025-9999".to_string()], tags: None, + type_: None, type_metadata: None, epss: None, }), diff --git a/crates/gvm-gateway-rest/src/results.rs b/crates/gvm-gateway-rest/src/results.rs index 08f05a4c..93250c60 100644 --- a/crates/gvm-gateway-rest/src/results.rs +++ b/crates/gvm-gateway-rest/src/results.rs @@ -59,6 +59,8 @@ pub(crate) struct NvtRefResponse { tags: Option, /// Source-shaped NVT type metadata supplied by gvmd. The gateway preserves this value without /// parsing or narrowing its schema. + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + type_: Option, #[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")] type_metadata: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -74,6 +76,7 @@ impl From for NvtRefResponse { cvss_base: n.cvss_base, cves: n.cves, tags: n.tags, + type_: n.type_, type_metadata: n.type_metadata, epss: n.epss.map(EpssResponse::from), } @@ -141,6 +144,8 @@ pub(crate) struct NvtRefSummaryResponse { cves: Vec, #[serde(skip_serializing_if = "Option::is_none")] tags: Option, + #[serde(rename = "type", skip_serializing_if = "Option::is_none")] + type_: Option, #[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")] type_metadata: Option, } @@ -154,6 +159,7 @@ impl From for NvtRefSummaryResponse { cvss_base: nvt.cvss_base, cves: nvt.cves, tags: nvt.tags, + type_: nvt.type_, type_metadata: nvt.type_metadata, } } diff --git a/crates/gvm-gateway-rest/src/results_test.rs b/crates/gvm-gateway-rest/src/results_test.rs index 9a1a5de4..e0856cb5 100644 --- a/crates/gvm-gateway-rest/src/results_test.rs +++ b/crates/gvm-gateway-rest/src/results_test.rs @@ -69,6 +69,7 @@ fn result_response_preserves_source_shaped_type_metadata() { cvss_base: None, cves: Vec::new(), tags: None, + type_: None, type_metadata: Some("{\"future\":[1,true]}".to_string()), epss: None, }), @@ -135,6 +136,7 @@ fn result_response_omits_absent_type_metadata() { cvss_base: None, cves: Vec::new(), tags: None, + type_: None, type_metadata: None, epss: None, }); @@ -155,6 +157,7 @@ fn result_response_serializes_distinct_epss_selections() { cvss_base: None, cves: Vec::new(), tags: None, + type_: None, type_metadata: None, epss: Some(Epss { max_epss: EpssSelection { @@ -198,6 +201,7 @@ fn summary_nvt_reference_does_not_expose_epss() { cvss_base: None, cves: Vec::new(), tags: None, + type_: None, type_metadata: None, epss: Some(Epss { max_epss: EpssSelection { @@ -222,3 +226,27 @@ fn summary_nvt_reference_does_not_expose_epss() { let value = serde_json::to_value(nvt).expect("summary NVT reference should serialize"); assert!(value.get("epss").is_none()); } + +// Intent: both full and nested summary DTOs preserve unknown discriminators without altering metadata. +#[test] +fn nvt_open_type_full_and_summary() { + for kind in [Some("nvt"), Some("package"), Some("future-source"), None] { + let n = NvtRef { + oid: None, + name: None, + family: None, + cvss_base: None, + cves: vec![], + tags: None, + type_: kind.map(str::to_owned), + type_metadata: Some("{opaque}".into()), + epss: None, + }; + let full = serde_json::to_value(super::NvtRefResponse::from(n.clone())).unwrap(); + let summary = serde_json::to_value(super::NvtRefSummaryResponse::from(n)).unwrap(); + for json in [full, summary] { + assert_eq!(json["typeMetadata"], "{opaque}"); + assert_eq!(json.get("type").and_then(serde_json::Value::as_str), kind); + } + } +} diff --git a/docs/report-projection-adoption.md b/docs/report-projection-adoption.md index 588279ba..a035369c 100644 --- a/docs/report-projection-adoption.md +++ b/docs/report-projection-adoption.md @@ -3,3 +3,7 @@ ## #734 applications GET /reports/{id}/applications preserves optional hostsCount, occurrences and open-string threat from typed upstream application summaries. Zero is distinct from absence; severity remains server-calculated. No live Agent qualification is claimed. + +## #735 NVT type + +JSON type is an optional open string. Ordinary results (including report embedded results) map typed NvtRef.type_; notes/overrides map typed NvtReference.type_, correcting the former misprojection as family. Aggregate vulnerability and closed-CVE sources lack a typed discriminator and keep it absent. Metadata is unchanged; missing NVTs remain missing. diff --git a/spec/rest-api/results.yaml b/spec/rest-api/results.yaml index ed83a55a..dbced587 100644 --- a/spec/rest-api/results.yaml +++ b/spec/rest-api/results.yaml @@ -130,6 +130,9 @@ components: type: string tags: type: string + type: + type: string + description: Open backend NVT discriminator; unknown values are preserved. typeMetadata: type: string description: Source-shaped NVT type metadata supplied by gvmd. The gateway preserves this value without parsing or narrowing its schema. @@ -154,6 +157,9 @@ components: type: string tags: type: string + type: + type: string + description: Open backend NVT discriminator; unknown values are preserved. typeMetadata: type: string description: Source-shaped NVT type metadata supplied by gvmd. The gateway preserves this value without parsing or narrowing its schema. diff --git a/worklog.md b/worklog.md index 659afab4..986de973 100644 --- a/worklog.md +++ b/worklog.md @@ -64,3 +64,4 @@ - #734: preserve typed optional counts/threat and server severity. Dependency baseline pending. - #734 slice-boundary correction: explicit u32 schema bounds now live with application counts, not the later reference slice. Added generated schema regression; preserved curated limits. +- #735: open JSON type on full/summary result NVTs; typed note/override references no longer mislabel discriminator as family. Aggregate sources retain absence. From f5f1426325bb8bd8eba370a7536aba1f7b9db8db Mon Sep 17 00:00:00 2001 From: hive-bumblebee Date: Thu, 19 Nov 2026 18:50:53 +0000 Subject: [PATCH 2/3] test(results): qualify typed open NVT discriminator projections (#735) --- crates/gvm-gateway-domain/src/results.rs | 2 +- .../gvm-gateway-gvmd/src/conversions_test.rs | 54 +++++++++++++++++++ crates/gvm-gateway-rest/src/results.rs | 5 +- worklog.md | 1 + 4 files changed, 59 insertions(+), 3 deletions(-) diff --git a/crates/gvm-gateway-domain/src/results.rs b/crates/gvm-gateway-domain/src/results.rs index 7d7bc02c..dee47f46 100644 --- a/crates/gvm-gateway-domain/src/results.rs +++ b/crates/gvm-gateway-domain/src/results.rs @@ -81,10 +81,10 @@ pub struct NvtRef { /// NVT tags. #[serde(skip_serializing_if = "Option::is_none")] pub tags: Option, - /// Source-shaped NVT type metadata supplied by gvmd. /// Open discriminator supplied by the typed NVT source. #[serde(rename = "type", skip_serializing_if = "Option::is_none")] pub type_: Option, + /// Source-shaped NVT type metadata supplied by gvmd. #[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")] pub type_metadata: Option, /// EPSS selections supplied by gvmd for this NVT. diff --git a/crates/gvm-gateway-gvmd/src/conversions_test.rs b/crates/gvm-gateway-gvmd/src/conversions_test.rs index 3a32899b..32b8ec67 100644 --- a/crates/gvm-gateway-gvmd/src/conversions_test.rs +++ b/crates/gvm-gateway-gvmd/src/conversions_test.rs @@ -1627,3 +1627,57 @@ fn target_source_conversion_preserves_upstream_optional_and_open_values() { assert_eq!(target.source.as_deref(), expected); } } + +#[test] +fn typed_result_and_nested_reference_types_remain_open_and_optional() { + // Intent (#735): test typed conversion, not just DTO construction; classic, + // nonclassic, future and parser-normalized empty values must agree across + // result, note and override sources, without fabricating a missing NVT. + for (element, expected) in [ + ("nvt", Some("nvt")), + ("package", Some("package")), + ("future-source", Some("future-source")), + ("", None), + ("", None), + ] { + let nvt = + format!(r#"{element}opaque"#); + let xml = format!( + r#"Result{nvt}"# + ); + let parsed = GetResultsResponse::from_response(&GmpResponse::from(xml.as_str())).unwrap(); + let result = result_from_gmp(parsed.items.into_iter().next().unwrap()).unwrap(); + let mapped = result.nvt.unwrap(); + assert_eq!(mapped.type_.as_deref(), expected); + assert_eq!(mapped.type_metadata.as_deref(), Some("opaque")); + let xml = format!( + r#"Note{nvt}"# + ); + let parsed = GetNotesResponse::from_response(&GmpResponse::from(xml.as_str())).unwrap(); + assert_eq!( + note_from_gmp(parsed.items.into_iter().next().unwrap()) + .nvt + .unwrap() + .type_ + .as_deref(), + expected + ); + let xml = format!( + r#"Override{nvt}"# + ); + let parsed = GetOverridesResponse::from_response(&GmpResponse::from(xml.as_str())).unwrap(); + assert_eq!( + override_from_gmp(parsed.items.into_iter().next().unwrap()) + .nvt + .unwrap() + .type_ + .as_deref(), + expected + ); + } + let parsed = GetResultsResponse::from_response(&GmpResponse::from(r#"No NVT"#)).unwrap(); + assert!(result_from_gmp(parsed.items.into_iter().next().unwrap()) + .unwrap() + .nvt + .is_none()); +} diff --git a/crates/gvm-gateway-rest/src/results.rs b/crates/gvm-gateway-rest/src/results.rs index 93250c60..8da9e5b4 100644 --- a/crates/gvm-gateway-rest/src/results.rs +++ b/crates/gvm-gateway-rest/src/results.rs @@ -57,10 +57,10 @@ pub(crate) struct NvtRefResponse { cves: Vec, #[serde(skip_serializing_if = "Option::is_none")] tags: Option, - /// Source-shaped NVT type metadata supplied by gvmd. The gateway preserves this value without - /// parsing or narrowing its schema. + /// Open backend NVT discriminator; unknown values are preserved. #[serde(rename = "type", skip_serializing_if = "Option::is_none")] type_: Option, + /// Opaque backend type metadata, preserved without interpretation. #[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")] type_metadata: Option, #[serde(skip_serializing_if = "Option::is_none")] @@ -146,6 +146,7 @@ pub(crate) struct NvtRefSummaryResponse { tags: Option, #[serde(rename = "type", skip_serializing_if = "Option::is_none")] type_: Option, + /// Opaque backend type metadata, preserved without interpretation. #[serde(rename = "typeMetadata", skip_serializing_if = "Option::is_none")] type_metadata: Option, } diff --git a/worklog.md b/worklog.md index 986de973..bcdb688d 100644 --- a/worklog.md +++ b/worklog.md @@ -65,3 +65,4 @@ - #734 slice-boundary correction: explicit u32 schema bounds now live with application counts, not the later reference slice. Added generated schema regression; preserved curated limits. - #735: open JSON type on full/summary result NVTs; typed note/override references no longer mislabel discriminator as family. Aggregate sources retain absence. +- #735 acceptance review: typed classic/nonclassic/future/empty/absent discriminator projections qualified; description comments corrected. From a2e9b2c26678e07228c74a428ad0868fc3580353 Mon Sep 17 00:00:00 2001 From: hive-bumblebee Date: Thu, 19 Nov 2026 19:05:09 +0000 Subject: [PATCH 3/3] fix(results): retain legacy family alias with open NVT type (#735) --- crates/gvm-gateway-gvmd/src/conversions.rs | 2 +- docs/report-projection-adoption.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/gvm-gateway-gvmd/src/conversions.rs b/crates/gvm-gateway-gvmd/src/conversions.rs index 18a7f04d..f74b0197 100644 --- a/crates/gvm-gateway-gvmd/src/conversions.rs +++ b/crates/gvm-gateway-gvmd/src/conversions.rs @@ -1143,7 +1143,7 @@ fn nvt_ref_from_gmp(nvt: gvm_gmp::responses::common::NvtReference) -> NvtRef { NvtRef { oid: Some(nvt.oid), name: nvt.name, - family: None, + family: nvt.type_.clone(), type_: nvt.type_, cvss_base: None, cves: vec![], diff --git a/docs/report-projection-adoption.md b/docs/report-projection-adoption.md index a035369c..56c67c89 100644 --- a/docs/report-projection-adoption.md +++ b/docs/report-projection-adoption.md @@ -6,4 +6,4 @@ GET /reports/{id}/applications preserves optional hostsCount, occurrences and op ## #735 NVT type -JSON type is an optional open string. Ordinary results (including report embedded results) map typed NvtRef.type_; notes/overrides map typed NvtReference.type_, correcting the former misprojection as family. Aggregate vulnerability and closed-CVE sources lack a typed discriminator and keep it absent. Metadata is unchanged; missing NVTs remain missing. +JSON type is an optional open string. Ordinary results (including report embedded results) map typed NvtRef.type_; notes/overrides map typed NvtReference.type_, retaining the legacy family alias for backward compatibility. Aggregate vulnerability and closed-CVE sources lack a typed discriminator and keep it absent. Metadata is unchanged; missing NVTs remain missing.