From 4178b40037ef9a3e1fd57f82c007103a3a6ee1e1 Mon Sep 17 00:00:00 2001 From: hive-bumblebee <278179999+hive-bumblebee@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:39:56 +0000 Subject: [PATCH 1/5] fix(reports): reject cross-report backend result pages --- .../src/gvmd_adapter/ports/reports.rs | 22 ++++++ crates/gvm-gateway-gvmd/tests/report_scope.rs | 75 +++++++++++++++++++ crates/gvm-gateway-rest/src/reports.rs | 9 ++- spec/rest-api/reports.yaml | 11 +++ spec/rest-api/test-spec.md | 15 ++++ worklog.md | 7 ++ 6 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 crates/gvm-gateway-gvmd/tests/report_scope.rs diff --git a/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs b/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs index 96676b78..d50c0d6f 100644 --- a/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs +++ b/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs @@ -142,6 +142,7 @@ impl ReportPort for GvmdAdapter { }, ) .await?; + ensure_report_result_scope(&results_parsed.items, id)?; report.results = results_parsed .items .into_iter() @@ -321,6 +322,7 @@ impl ReportPort for GvmdAdapter { }, ) .await?; + ensure_report_result_scope(&parsed.items, report_id)?; let items = parsed .items .into_iter() @@ -709,3 +711,23 @@ fn unsupported_typed_report_detail_error(command: &str, resource: &str) -> Gatew "{resource} are not available because gvmd does not implement `{command}` on this backend version; the proxy does not emulate unsupported GMP commands" )) } + +// An endpoint-owned report identity must never be weakened by backend filtering. +// Fail the entire response rather than returning a cross-report page or quietly +// dropping rows and making pagination counts untrustworthy. +fn ensure_report_result_scope( + results: &[gvm_gmp::responses::ScanResult], + report_id: &str, +) -> Result<(), GatewayError> { + if results.iter().any(|result| { + result + .report + .as_ref() + .is_some_and(|report| !report.id.as_str().eq_ignore_ascii_case(report_id)) + }) { + return Err(GatewayError::BackendUnavailable( + "backend returned results outside the requested report".into(), + )); + } + Ok(()) +} diff --git a/crates/gvm-gateway-gvmd/tests/report_scope.rs b/crates/gvm-gateway-gvmd/tests/report_scope.rs new file mode 100644 index 00000000..765da30d --- /dev/null +++ b/crates/gvm-gateway-gvmd/tests/report_scope.rs @@ -0,0 +1,75 @@ +//! Regression coverage for endpoint-owned report isolation (issue #741). +use gvm_gateway_domain::{GatewayError, ReportPort, ResultQuery}; +use gvm_gateway_gvmd::GvmdAdapter; +use gvm_mock_server::{GmpVersion, MockGmpServer, ServerMode}; + +const PATH_REPORT: &str = "aabbccdd-0000-4000-8000-000000000001"; +const OTHER_REPORT: &str = "aabbccdd-0000-4000-8000-000000000002"; + +async fn adapter_with_result(report_id: &str) -> (GvmdAdapter, MockGmpServer) { + let response = format!( + r#"Scoped result8.0Report11"# + ); + let server = MockGmpServer::builder() + .mode(ServerMode::Fixture) + .version(GmpVersion::V22_8) + .override_response("get_results", &response) + .unix_socket_auto() + .build() + .await + .expect("start fixture server"); + let adapter = GvmdAdapter::unix_socket(server.socket_path().expect("socket")); + adapter + .connect_session("scope-session", "admin", "admin") + .await + .expect("authenticate"); + (adapter, server) +} + +#[tokio::test] +async fn report_results_fail_closed_when_backend_returns_a_different_report() { + // A misbehaving backend must not leak rows or return misleading filtered + // counts, even when it responds with a syntactically successful payload. + let (adapter, server) = adapter_with_result(OTHER_REPORT).await; + let result = adapter + .get_report_results( + "scope-session", + PATH_REPORT, + &ResultQuery { + page: 1, + per_page: 25, + ..Default::default() + }, + ) + .await; + assert!( + matches!(result, Err(GatewayError::BackendUnavailable(detail)) + if detail == "backend returned results outside the requested report") + ); + server.shutdown().await; +} + +#[tokio::test] +async fn report_scope_accepts_equivalent_uuid_case_without_rewriting_payload() { + // UUID spelling is not identity: an uppercase requested path remains the + // same report while the server's original lowercase spelling is retained. + let (adapter, server) = adapter_with_result(PATH_REPORT).await; + let result = adapter + .get_report_results( + "scope-session", + &PATH_REPORT.to_uppercase(), + &ResultQuery { + page: 1, + per_page: 25, + ..Default::default() + }, + ) + .await + .expect("same report"); + assert_eq!(result.data.len(), 1); + assert_eq!( + result.data[0].report.as_ref().expect("report").id, + PATH_REPORT + ); + server.shutdown().await; +} diff --git a/crates/gvm-gateway-rest/src/reports.rs b/crates/gvm-gateway-rest/src/reports.rs index e67daf65..c6feb613 100644 --- a/crates/gvm-gateway-rest/src/reports.rs +++ b/crates/gvm-gateway-rest/src/reports.rs @@ -1338,13 +1338,18 @@ pub(crate) fn get_report_results_docs(op: TransformOperation<'_>) -> TransformOp .id("getReportResults") .tag("Reports") .summary("Get paginated results for a report") - .description("Returns a paginated list of results for a specific report.") + .description("Returns results and counts scoped to the report in the path, including boolean filters. Reserved report/pagination controls and unsupported inclusive comparisons such as severity>=7 return 400. Cross-report backend rows fail as 502 rather than being returned or silently discarded.") .security_requirement("bearerAuth") .input::<(Path, Query)>() .response_with::<200, Json, _>(ok_json("Paginated list of results")); + let op = problem_response::<400>(op, "Invalid filter or request"); let op = problem_response::<401>(op, "Authentication required or session expired"); - problem_response::<404>(op, "Resource not found") + let op = problem_response::<404>(op, "Resource not found"); + problem_response::<502>( + op, + "Backend response violates report scope or is unavailable", + ) } /// OpenAPI transform for `GET /api/v1/reports/{id}/vulnerabilities`. diff --git a/spec/rest-api/reports.yaml b/spec/rest-api/reports.yaml index 23adfc69..c507595f 100644 --- a/spec/rest-api/reports.yaml +++ b/spec/rest-api/reports.yaml @@ -141,6 +141,15 @@ paths: operationId: getReportResults tags: [Reports] summary: Get paginated results for a report + description: | + Results and counts remain restricted to the report in the path, including + when caller or saved filters contain boolean alternatives. Endpoint-owned + report scope and pagination controls cannot be overridden. Supported + comparison operators retain GMP semantics; unsupported inclusive operators + such as `severity>=7` or `severity<=7` return 400 rather than being silently + ignored. Use supported strict or equality comparisons explicitly. + A backend response containing rows from another report fails as 502; + the gateway never drops those rows while retaining misleading counts. parameters: - $ref: "./common.yaml#/components/parameters/FilterString" - $ref: "./common.yaml#/components/parameters/FilterId" @@ -153,6 +162,8 @@ paths: application/json: schema: $ref: "./results.yaml#/components/schemas/ResultList" + "400": + $ref: "./common.yaml#/components/responses/BadRequest" "401": $ref: "./common.yaml#/components/responses/Unauthorized" "502": diff --git a/spec/rest-api/test-spec.md b/spec/rest-api/test-spec.md index dc687bda..588cc75d 100644 --- a/spec/rest-api/test-spec.md +++ b/spec/rest-api/test-spec.md @@ -370,3 +370,18 @@ raw result/catalog refs with unknown types and escaped opaque identifiers. Generated/curated OpenAPI parity remains required. These fixtures are not live Agent/gvmd or KEV-feed qualification. KEV-specific tests await actual producer and typed library contracts; absence is never a synthetic negative observation. + + +## Report-result scope and comparison contract (#741) + +- Seed two reports with overlapping high/low severities. Both strict severity + predicates and explicit boolean alternatives must return only path-report rows, + with counts and pagination computed in that scope. +- Compose saved and inline filters through the typed upstream scope helper; + reject attempts to replace report identity or endpoint-owned pagination. +- Unsupported inclusive `>=`/`<=` comparators outside quoted literal values + return 400 before the results operation, never silently ignored success. +- A deliberately inconsistent successful backend response containing another + report ID returns a sanitized 502, not partial data with unadjusted counts. +- Upper/lowercase UUID spellings identify the same report. Keep returned payload + spelling and optional source metadata unchanged. diff --git a/worklog.md b/worklog.md index bd4e7700..b2c5f0dd 100644 --- a/worklog.md +++ b/worklog.md @@ -87,3 +87,10 @@ - #742 independent review repeated immutable gvmd source/schema and typed-model search: refs/EPSS producers present, no KEV contract found. Corrected producer source anchors. Following explicit parent authorization and fresh authenticated all-state duplicate searches (KEV and “known exploited”), filed gvmd #3254 and rust-gvm #873, and cross-linked API #742 comment 7018718816. No runtime branch publication. Expanded raw refs regression to diverse feed types, escaped URL, CVE compatibility and duplicate/order retention. - #742 focused typed/REST collection regressions pass; required full-workspace Clippy, formatting and docs validation pass. Full workspace rerun pending final result. - Independent read-only review of parent b02/732-agent-os-metadata (dcd4706; #730–732) against issue acceptance and specs found no concrete blocker in scheduler compatibility/range mapping, inventory-token authentication/capabilities/status/confidentiality/cache, or OS omission/open-string mapping. Parent worktree and branches were not changed. + +# API #741 report result isolation + +- 2026-11-19: Rooted at PR740 head9a5664f. Read contract/code and pinned local gvmd producer. +- Identified protected `_and_report_id` control in gvmd source; filed rust-gvm#871 for typed composition and strict comparator validation, rather than parsing GMP in gateway. +- Adding defense-in-depth response scope invariant: backend cross-report rows fail the whole page with sanitized502; UUID case-equivalent identities remain accepted. +- Waiting on upstream helper plus shared immutable dependency adoption before final adapter integration/testing/publication. From 63c82137a54ff5784335faa3ff68555b369069e6 Mon Sep 17 00:00:00 2001 From: hive-bumblebee Date: Thu, 19 Nov 2026 18:47:41 +0000 Subject: [PATCH 2/5] fix(reports): compose protected report scope through typed upstream helper --- Cargo.lock | 10 +- Cargo.toml | 10 +- .../src/gvmd_adapter/ports/reports.rs | 41 +++---- .../tests/gvmd_adapter_test.rs | 4 +- crates/gvm-gateway-gvmd/tests/report_scope.rs | 101 ++++++++++++++++++ worklog.md | 4 + 6 files changed, 140 insertions(+), 30 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7f8657b1..60b34f6b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,7 +642,7 @@ dependencies = [ [[package]] name = "gvm-client" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=b6f33da1224aa4950f39dc3db0e6d5607e0e0f89#b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" +source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" dependencies = [ "async-trait", "gvm-connection", @@ -656,7 +656,7 @@ dependencies = [ [[package]] name = "gvm-connection" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=b6f33da1224aa4950f39dc3db0e6d5607e0e0f89#b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" +source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" dependencies = [ "async-trait", "gvm-protocol", @@ -799,7 +799,7 @@ dependencies = [ [[package]] name = "gvm-gmp" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=b6f33da1224aa4950f39dc3db0e6d5607e0e0f89#b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" +source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" dependencies = [ "base64 0.23.1", "gvm-protocol", @@ -813,7 +813,7 @@ dependencies = [ [[package]] name = "gvm-mock-server" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=b6f33da1224aa4950f39dc3db0e6d5607e0e0f89#b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" +source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" dependencies = [ "base64 0.23.1", "clap", @@ -833,7 +833,7 @@ dependencies = [ [[package]] name = "gvm-protocol" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=b6f33da1224aa4950f39dc3db0e6d5607e0e0f89#b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" +source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" dependencies = [ "quick-xml", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index 8d7910ff..c8c4a63e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,11 +25,11 @@ axum = "0.8.9" clap = { version = "4.6.1", features = ["derive"] } # Keep all five workspace components on one immutable rust-gvm commit so Cargo # resolves a coherent upstream snapshot. -gvm-client = { git = "https://github.com/greenbone/rust-gvm", rev = "b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" } -gvm-connection = { git = "https://github.com/greenbone/rust-gvm", rev = "b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" } -gvm-gmp = { git = "https://github.com/greenbone/rust-gvm", rev = "b6f33da1224aa4950f39dc3db0e6d5607e0e0f89", features = ["serde"] } -gvm-mock-server = { git = "https://github.com/greenbone/rust-gvm", rev = "b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" } -gvm-protocol = { git = "https://github.com/greenbone/rust-gvm", rev = "b6f33da1224aa4950f39dc3db0e6d5607e0e0f89" } +gvm-client = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } +gvm-connection = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } +gvm-gmp = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7", features = ["serde"] } +gvm-mock-server = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } +gvm-protocol = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } http = "1.4.1" opentelemetry = { version = "0.33.0", features = ["trace"] } opentelemetry-otlp = { version = "0.33.0", features = ["grpc-tonic", "trace"] } diff --git a/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs b/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs index d50c0d6f..958918d2 100644 --- a/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs +++ b/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs @@ -82,7 +82,7 @@ impl ReportPort for GvmdAdapter { // Fetch only report metadata; embedded results are loaded below through // the explicit result-window request. - let mut request = GetReportRequest::new(report_id); + let mut request = GetReportRequest::new(report_id.clone()); request.details = Some(false); let parsed = self .execute_with_session(session_token, "reports.get", request) @@ -119,12 +119,15 @@ impl ReportPort for GvmdAdapter { } // Fetch the explicitly requested embedded-result window for this report. - let filter = paginated_filter( - Some(&format!("report_id={id}")), - None, - opts.page, - opts.per_page, - )?; + let filter = Some( + gvm_gmp::compose_report_results_filter( + &report_id, + None, + None, + GmpPagination::new(opts.page as usize, opts.per_page as usize), + ) + .map_err(|error| GatewayError::InvalidInput(error.to_string()))?, + ); let results_parsed = self .execute_with_session( @@ -286,25 +289,27 @@ impl ReportPort for GvmdAdapter { report_id: &str, query: &ResultQuery, ) -> Result { - // Validate that the report_id is a valid UUID - let _ = parse_entity_id(report_id)?; + let scope_id = parse_entity_id(report_id)?; let filter_id = query .filter_id .as_deref() .map(parse_entity_id) .transpose()?; - let filter = self - .paginated_filter_resolving_filter_id( - session_token, - Some(&format!("report_id={report_id}")), + let saved_filter = self + .saved_filter_term(session_token, filter_id.as_ref()) + .await?; + // Keep wire semantics in rust-gvm: its protected scope control is + // independent of the caller's boolean expression and applies to counts. + let filter = Some( + gvm_gmp::compose_report_results_filter( + &scope_id, + saved_filter.as_deref(), query.filter_string.as_deref(), - filter_id.as_ref(), - query.page, - query.per_page, - &["report_id"], + GmpPagination::new(query.page as usize, query.per_page as usize), ) - .await?; + .map_err(|error| GatewayError::InvalidInput(error.to_string()))?, + ); let parsed = self .execute_with_session( diff --git a/crates/gvm-gateway-gvmd/tests/gvmd_adapter_test.rs b/crates/gvm-gateway-gvmd/tests/gvmd_adapter_test.rs index d6720dab..11b7d0ec 100644 --- a/crates/gvm-gateway-gvmd/tests/gvmd_adapter_test.rs +++ b/crates/gvm-gateway-gvmd/tests/gvmd_adapter_test.rs @@ -1855,7 +1855,7 @@ async fn gvmd_adapter_direct_lists_emit_backend_pagination_filter() { } ), "get_results", - "filter=\"report_id=550e8400-e29b-41d4-a716-446655440000 name=Target first=11 rows=10\"" + "filter=\"name=Target _and_report_id=550e8400-e29b-41d4-a716-446655440000 first=11 rows=10\"" ); assert_backend_pagination!( adapter, @@ -3966,7 +3966,7 @@ async fn gvmd_adapter_get_report_results_resolves_filter_id_into_inline_filter() .expect("get_results command should be recorded"); let xml = String::from_utf8(command.raw_xml().to_vec()).expect("xml command"); assert!(xml.contains( - "filter=\"threat=Alarm report_id=550e8400-e29b-41d4-a716-446655440000 severity>5 first=1 rows=25\"" + "filter=\"threat=Alarm severity>5 _and_report_id=550e8400-e29b-41d4-a716-446655440000 first=1 rows=25\"" )); assert!(!xml.contains("filter_id")); diff --git a/crates/gvm-gateway-gvmd/tests/report_scope.rs b/crates/gvm-gateway-gvmd/tests/report_scope.rs index 765da30d..7b6bdaa5 100644 --- a/crates/gvm-gateway-gvmd/tests/report_scope.rs +++ b/crates/gvm-gateway-gvmd/tests/report_scope.rs @@ -73,3 +73,104 @@ async fn report_scope_accepts_equivalent_uuid_case_without_rewriting_payload() { ); server.shutdown().await; } + +#[tokio::test] +async fn protected_scope_applies_to_boolean_results_counts_and_saved_filters() { + // Each report has high and low findings. The low OR arm must not escape + // the path report, and pagination counts must be scoped before slicing. + let server = MockGmpServer::builder() + .mode(ServerMode::Stateful) + .version(GmpVersion::V22_8) + .seed(|store| { + for report in [PATH_REPORT, OTHER_REPORT] { + let report_id = uuid::Uuid::parse_str(report).unwrap(); + store.create(gvm_mock_server::Resource::with_id( + "report", "Report", report_id, + )); + for (index, severity) in [(0, "8.0"), (1, "5.0")] { + let mut result = gvm_mock_server::Resource::with_id( + "result", + "Finding", + uuid::Uuid::new_v5(&report_id, &[index]), + ); + result.set_attr("report_id", report); + result.set_attr("severity", severity); + store.create(result); + } + } + let mut filter = gvm_mock_server::Resource::with_id( + "filter", + "Saved alternative", + uuid::Uuid::parse_str("123e4567-e89b-12d3-a456-426614174000").unwrap(), + ); + filter.set_attr("term", "severity>7 OR severity<6"); + filter.set_attr("type", "result"); + store.create(filter); + }) + .unix_socket_auto() + .build() + .await + .unwrap(); + let adapter = GvmdAdapter::unix_socket(server.socket_path().unwrap()); + adapter + .connect_session("scope-session", "admin", "admin") + .await + .unwrap(); + for saved in [false, true] { + for page in [1, 2] { + let query = ResultQuery { + filter_string: (!saved).then(|| "severity>7 OR severity<6".to_string()), + filter_id: saved.then(|| "123e4567-e89b-12d3-a456-426614174000".to_string()), + page, + per_page: 1, + }; + let results = adapter + .get_report_results("scope-session", PATH_REPORT, &query) + .await + .unwrap(); + assert_eq!(results.pagination.total, 2, "saved={saved}, page={page}"); + assert_eq!(results.data.len(), 1); + assert_eq!(results.data[0].report.as_ref().unwrap().id, PATH_REPORT); + } + } + server.shutdown().await; +} + +#[tokio::test] +async fn invalid_report_filter_controls_fail_before_result_execution() { + // Unsupported comparators and endpoint-owned controls are client errors, + // not silently ignored predicates or backend result requests. + let (adapter, server) = adapter_with_result(PATH_REPORT).await; + for filter in [ + "severity>=7", + "severity<=7", + "severity==7", + "report_id=x", + "_and_report_id=x", + "first=9", + "rows=100", + ] { + server.clear_history(); + let result = adapter + .get_report_results( + "scope-session", + PATH_REPORT, + &ResultQuery { + filter_string: Some(filter.to_string()), + page: 1, + per_page: 25, + ..Default::default() + }, + ) + .await; + assert!( + matches!(result, Err(GatewayError::InvalidInput(_))), + "{filter}: {result:?}" + ); + assert!(!server + .command_history() + .iter() + .any(|record| record.command_name() == "get_results")); + } + server.shutdown().await; +} diff --git a/worklog.md b/worklog.md index b2c5f0dd..126e6801 100644 --- a/worklog.md +++ b/worklog.md @@ -94,3 +94,7 @@ - Identified protected `_and_report_id` control in gvmd source; filed rust-gvm#871 for typed composition and strict comparator validation, rather than parsing GMP in gateway. - Adding defense-in-depth response scope invariant: backend cross-report rows fail the whole page with sanitized502; UUID case-equivalent identities remain accepted. - Waiting on upstream helper plus shared immutable dependency adoption before final adapter integration/testing/publication. + +- Adopted upstream immutable feature stack b6f33da; reviewed 270-method typed facade (three newly blocked REST adopters). Building isolated target; native compiler provisioned inside workspace only. +- Integrated typed compose_report_results_filter at both report result read paths; saved terms resolve first and no filter_id is forwarded. Added transport regressions for caller/saved boolean alternatives, report-scoped counts across pages, and rejection before result execution for unsupported or endpoint-owned predicates. +- Focused testing initially used CLI path patches; final manifest and regenerated lockfile now pin all five upstream crates to published immutable 64b9d01820c8b4715265bbae06293462c24fdfe7 (rust-gvm#872), without local patches. All 120 focused adapter/scope tests and strict workspace Clippy passed; full workspace tests running. From ed91120fa90e26cca4a1499fc79771e70e655942 Mon Sep 17 00:00:00 2001 From: hive-bumblebee Date: Thu, 19 Nov 2026 18:50:09 +0000 Subject: [PATCH 3/5] test: pin architecture invariant to protected-filter upstream revision --- crates/gvm-gateway-gvmd/tests/architecture.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/gvm-gateway-gvmd/tests/architecture.rs b/crates/gvm-gateway-gvmd/tests/architecture.rs index 091c00a5..49c53fab 100644 --- a/crates/gvm-gateway-gvmd/tests/architecture.rs +++ b/crates/gvm-gateway-gvmd/tests/architecture.rs @@ -18,7 +18,7 @@ const RUST_GVM_COMPONENTS: &[&str] = &[ // immutable upstream stack commit; this is not a released tag. const RUST_GVM_DEPENDENCY_URL: &str = "https://github.com/greenbone/rust-gvm"; const RUST_GVM_DEPENDENCY_VERSION: &str = "0.11.1"; -const RUST_GVM_DEPENDENCY_REVISION: &str = "b6f33da1224aa4950f39dc3db0e6d5607e0e0f89"; +const RUST_GVM_DEPENDENCY_REVISION: &str = "64b9d01820c8b4715265bbae06293462c24fdfe7"; // The feature stack adds AD verification/discovery and inventory-token helpers // to the previous 267-method baseline. All 270 helpers are deliberately reviewed // in the matching snapshot and disposition ledger. From d7af80dfb84a19c7c9fabc1d5338ca0c84316516 Mon Sep 17 00:00:00 2001 From: hive-bumblebee Date: Thu, 19 Nov 2026 19:03:43 +0000 Subject: [PATCH 4/5] test(reports): adopt source-aligned filter quotes and reject transport overrides --- Cargo.lock | 10 +- Cargo.toml | 10 +- crates/gvm-gateway-gvmd/tests/architecture.rs | 2 +- crates/gvm-gateway-gvmd/tests/report_scope.rs | 108 ++++++++++++++++++ worklog.md | 9 ++ 5 files changed, 128 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60b34f6b..56f5976b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -642,7 +642,7 @@ dependencies = [ [[package]] name = "gvm-client" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" +source = "git+https://github.com/greenbone/rust-gvm?rev=fa990ad0c8aab4609dec7999f01e9922713fe71b#fa990ad0c8aab4609dec7999f01e9922713fe71b" dependencies = [ "async-trait", "gvm-connection", @@ -656,7 +656,7 @@ dependencies = [ [[package]] name = "gvm-connection" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" +source = "git+https://github.com/greenbone/rust-gvm?rev=fa990ad0c8aab4609dec7999f01e9922713fe71b#fa990ad0c8aab4609dec7999f01e9922713fe71b" dependencies = [ "async-trait", "gvm-protocol", @@ -799,7 +799,7 @@ dependencies = [ [[package]] name = "gvm-gmp" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" +source = "git+https://github.com/greenbone/rust-gvm?rev=fa990ad0c8aab4609dec7999f01e9922713fe71b#fa990ad0c8aab4609dec7999f01e9922713fe71b" dependencies = [ "base64 0.23.1", "gvm-protocol", @@ -813,7 +813,7 @@ dependencies = [ [[package]] name = "gvm-mock-server" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" +source = "git+https://github.com/greenbone/rust-gvm?rev=fa990ad0c8aab4609dec7999f01e9922713fe71b#fa990ad0c8aab4609dec7999f01e9922713fe71b" dependencies = [ "base64 0.23.1", "clap", @@ -833,7 +833,7 @@ dependencies = [ [[package]] name = "gvm-protocol" version = "0.11.1" -source = "git+https://github.com/greenbone/rust-gvm?rev=64b9d01820c8b4715265bbae06293462c24fdfe7#64b9d01820c8b4715265bbae06293462c24fdfe7" +source = "git+https://github.com/greenbone/rust-gvm?rev=fa990ad0c8aab4609dec7999f01e9922713fe71b#fa990ad0c8aab4609dec7999f01e9922713fe71b" dependencies = [ "quick-xml", "thiserror", diff --git a/Cargo.toml b/Cargo.toml index c8c4a63e..ec46c705 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,11 +25,11 @@ axum = "0.8.9" clap = { version = "4.6.1", features = ["derive"] } # Keep all five workspace components on one immutable rust-gvm commit so Cargo # resolves a coherent upstream snapshot. -gvm-client = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } -gvm-connection = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } -gvm-gmp = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7", features = ["serde"] } -gvm-mock-server = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } -gvm-protocol = { git = "https://github.com/greenbone/rust-gvm", rev = "64b9d01820c8b4715265bbae06293462c24fdfe7" } +gvm-client = { git = "https://github.com/greenbone/rust-gvm", rev = "fa990ad0c8aab4609dec7999f01e9922713fe71b" } +gvm-connection = { git = "https://github.com/greenbone/rust-gvm", rev = "fa990ad0c8aab4609dec7999f01e9922713fe71b" } +gvm-gmp = { git = "https://github.com/greenbone/rust-gvm", rev = "fa990ad0c8aab4609dec7999f01e9922713fe71b", features = ["serde"] } +gvm-mock-server = { git = "https://github.com/greenbone/rust-gvm", rev = "fa990ad0c8aab4609dec7999f01e9922713fe71b" } +gvm-protocol = { git = "https://github.com/greenbone/rust-gvm", rev = "fa990ad0c8aab4609dec7999f01e9922713fe71b" } http = "1.4.1" opentelemetry = { version = "0.33.0", features = ["trace"] } opentelemetry-otlp = { version = "0.33.0", features = ["grpc-tonic", "trace"] } diff --git a/crates/gvm-gateway-gvmd/tests/architecture.rs b/crates/gvm-gateway-gvmd/tests/architecture.rs index 49c53fab..db37887d 100644 --- a/crates/gvm-gateway-gvmd/tests/architecture.rs +++ b/crates/gvm-gateway-gvmd/tests/architecture.rs @@ -18,7 +18,7 @@ const RUST_GVM_COMPONENTS: &[&str] = &[ // immutable upstream stack commit; this is not a released tag. const RUST_GVM_DEPENDENCY_URL: &str = "https://github.com/greenbone/rust-gvm"; const RUST_GVM_DEPENDENCY_VERSION: &str = "0.11.1"; -const RUST_GVM_DEPENDENCY_REVISION: &str = "64b9d01820c8b4715265bbae06293462c24fdfe7"; +const RUST_GVM_DEPENDENCY_REVISION: &str = "fa990ad0c8aab4609dec7999f01e9922713fe71b"; // The feature stack adds AD verification/discovery and inventory-token helpers // to the previous 267-method baseline. All 270 helpers are deliberately reviewed // in the matching snapshot and disposition ledger. diff --git a/crates/gvm-gateway-gvmd/tests/report_scope.rs b/crates/gvm-gateway-gvmd/tests/report_scope.rs index 7b6bdaa5..223465bc 100644 --- a/crates/gvm-gateway-gvmd/tests/report_scope.rs +++ b/crates/gvm-gateway-gvmd/tests/report_scope.rs @@ -174,3 +174,111 @@ async fn invalid_report_filter_controls_fail_before_result_execution() { } server.shutdown().await; } + +#[tokio::test] +async fn quote_disguised_scope_and_window_overrides_never_reach_result_transport() { + // These are not literals in gvmd: apostrophes/backslashes do not quote or + // escape, and an embedded double quote does not open a literal. Validate + // both resolved saved terms and inline terms before any result request. + for term in [ + "name='benign _and_report_id=other'", + r#"name="benign\" _and_report_id=other x="end""#, + r#"name=ab"cd _and_report_id=other x="end""#, + "name='benign rows=99'", + r#"name="benign\" first=99 x="end""#, + "name='severity>=5'", + r#"name="benign\" severity<=5 x="end""#, + ] { + let filter_id = "123e4567-e89b-12d3-a456-426614174000"; + let server = MockGmpServer::builder() + .mode(ServerMode::Stateful) + .version(GmpVersion::V22_8) + .seed(|store| { + let mut filter = gvm_mock_server::Resource::with_id( + "filter", + "Untrusted saved filter", + uuid::Uuid::parse_str(filter_id).unwrap(), + ); + filter.set_attr("term", term); + filter.set_attr("type", "result"); + store.create(filter); + }) + .unix_socket_auto() + .build() + .await + .unwrap(); + let adapter = GvmdAdapter::unix_socket(server.socket_path().unwrap()); + adapter + .connect_session("scope-session", "admin", "admin") + .await + .unwrap(); + for saved in [false, true] { + server.clear_history(); + let result = adapter + .get_report_results( + "scope-session", + PATH_REPORT, + &ResultQuery { + filter_string: (!saved).then(|| term.to_string()), + filter_id: saved.then(|| filter_id.to_string()), + page: 1, + per_page: 25, + }, + ) + .await; + assert!( + matches!(result, Err(GatewayError::InvalidInput(_))), + "saved={saved}, term={term}: {result:?}" + ); + let history = server.command_history(); + assert_eq!( + history + .iter() + .any(|record| record.command_name() == "get_filters"), + saved, + "saved terms must be resolved before validation" + ); + assert!( + !history + .iter() + .any(|record| record.command_name() == "get_results"), + "saved={saved}, term={term}: unsafe text reached result transport" + ); + } + server.shutdown().await; + } +} + +#[tokio::test] +async fn real_quoted_filter_literals_still_reach_result_transport() { + // The strict upstream boundary must not reject reserved/operator spellings + // inside genuine double-quoted literals. Fixture playback isolates gateway + // dispatch from the deliberately bounded stateful mock predicate parser. + let (adapter, server) = adapter_with_result(PATH_REPORT).await; + for term in [ + r#"name="_and_report_id=other rows=99 severity>=5""#, + r#"name="ends in backslash\""#, + "name=O'Brien", + ] { + server.clear_history(); + let result = adapter + .get_report_results( + "scope-session", + PATH_REPORT, + &ResultQuery { + filter_string: Some(term.to_string()), + page: 1, + per_page: 25, + ..Default::default() + }, + ) + .await + .expect("supported literal is dispatched"); + assert_eq!(result.data.len(), 1); + assert!(server + .command_history() + .iter() + .any(|record| record.command_name() == "get_results")); + } + server.shutdown().await; +} diff --git a/worklog.md b/worklog.md index 126e6801..42ce81ef 100644 --- a/worklog.md +++ b/worklog.md @@ -98,3 +98,12 @@ - Adopted upstream immutable feature stack b6f33da; reviewed 270-method typed facade (three newly blocked REST adopters). Building isolated target; native compiler provisioned inside workspace only. - Integrated typed compose_report_results_filter at both report result read paths; saved terms resolve first and no filter_id is forwarded. Added transport regressions for caller/saved boolean alternatives, report-scoped counts across pages, and rejection before result execution for unsupported or endpoint-owned predicates. - Focused testing initially used CLI path patches; final manifest and regenerated lockfile now pin all five upstream crates to published immutable 64b9d01820c8b4715265bbae06293462c24fdfe7 (rust-gvm#872), without local patches. All 120 focused adapter/scope tests and strict workspace Clippy passed; full workspace tests running. + +- Parent full-suite retries exposed two stale dependency-adoption expectations: application fixture intentionally lacks severity (kept absent), and the exact dependency invariant now pins64b9d018. Both corrected without weakening production contracts. The fixture correction is already present in stack730 and need not be cherry-picked into final741. Full-suite retry in progress. +- Full workspace `cargo test --workspace --locked` completed successfully, including OpenAPI parity and doctests; zero failures. Strict workspace Clippy was already successful at this code state. Integration into issue-specific final stack pending sibling slice completion. + +## API #741 quote-override transport follow-up +- Independent upstream parser review corrected quote semantics in rust-gvm #872 at fa990ad0c8aab4609dec7999f01e9922713fe71b. Updated all five manifest/lock pins and exact architecture invariant; no local protocol parsing or parent edits. +- Added transport regressions for disguised scope/window controls and inclusive operators in both inline and resolved saved terms; assert InvalidInput and absence of get_results. Real double-quoted literals, terminal backslashes and ordinary apostrophes remain dispatchable using fixture playback. +- Confirmed negative regression fails against 64b9d018 (old helper dispatches and returns an empty successful page). At fa990ad all six report-scope transport tests pass (including OR, counts/paging, saved and inline reserved/quote cases), as do all 22 architecture tests. Exact manifest/lock coherence and fmt/diff checks pass. +- Required `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` passed (only pre-existing Cargo manifest unused-dependency warnings). Tooling sourced /workspace/api-agent-env, isolated CARGO_TARGET_DIR=/workspace/.cache/api-filter-target. No parent checkout or specifications modified; no push/PR requested. From 212950023a93849a84df5359756f174116253475 Mon Sep 17 00:00:00 2001 From: hive-bumblebee <278179999+hive-bumblebee@users.noreply.github.com> Date: Fri, 20 Nov 2026 11:37:01 +0000 Subject: [PATCH 5/5] fix(reports): reject results with missing report associations --- .../src/gvmd_adapter/ports/reports.rs | 2 +- crates/gvm-gateway-gvmd/tests/report_scope.rs | 65 ++++++++++++++++++- crates/gvm-gateway-rest/src/reports.rs | 2 +- spec/rest-api/reports.yaml | 2 +- spec/rest-api/test-spec.md | 5 +- worklog.md | 5 ++ 6 files changed, 73 insertions(+), 8 deletions(-) diff --git a/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs b/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs index 958918d2..b0989cda 100644 --- a/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs +++ b/crates/gvm-gateway-gvmd/src/gvmd_adapter/ports/reports.rs @@ -728,7 +728,7 @@ fn ensure_report_result_scope( result .report .as_ref() - .is_some_and(|report| !report.id.as_str().eq_ignore_ascii_case(report_id)) + .is_none_or(|report| !report.id.as_str().eq_ignore_ascii_case(report_id)) }) { return Err(GatewayError::BackendUnavailable( "backend returned results outside the requested report".into(), diff --git a/crates/gvm-gateway-gvmd/tests/report_scope.rs b/crates/gvm-gateway-gvmd/tests/report_scope.rs index 223465bc..26e21481 100644 --- a/crates/gvm-gateway-gvmd/tests/report_scope.rs +++ b/crates/gvm-gateway-gvmd/tests/report_scope.rs @@ -1,5 +1,5 @@ //! Regression coverage for endpoint-owned report isolation (issue #741). -use gvm_gateway_domain::{GatewayError, ReportPort, ResultQuery}; +use gvm_gateway_domain::{GatewayError, GetReportOpts, ReportPort, ResultQuery}; use gvm_gateway_gvmd::GvmdAdapter; use gvm_mock_server::{GmpVersion, MockGmpServer, ServerMode}; @@ -10,10 +10,21 @@ async fn adapter_with_result(report_id: &str) -> (GvmdAdapter, MockGmpServer) { let response = format!( r#"Scoped result8.0Report11"# ); + adapter_with_results_xml(&response, GmpVersion::V22_8).await +} + +async fn adapter_with_results_xml( + response: &str, + version: GmpVersion, +) -> (GvmdAdapter, MockGmpServer) { + let report_response = format!( + r#"Path report"# + ); let server = MockGmpServer::builder() .mode(ServerMode::Fixture) - .version(GmpVersion::V22_8) - .override_response("get_results", &response) + .version(version) + .override_response("get_reports", &report_response) + .override_response("get_results", response) .unix_socket_auto() .build() .await @@ -282,3 +293,51 @@ async fn real_quoted_filter_literals_still_reach_result_transport() { } server.shutdown().await; } + +#[tokio::test] +async fn missing_report_reference_is_rejected_for_scoped_and_embedded_results() { + // A successful payload is not proof of isolation. Without a report ID, no + // row can be verified against either endpoint's path-owned identity. + let response = r#"Unverifiable finding8.011"#; + for embedded in [false, true] { + // 22.7 exercises the supported older-backend read path: structured + // snapshot enrichment is unavailable, but result isolation still applies. + let (adapter, server) = adapter_with_results_xml(response, GmpVersion::V22_7).await; + let result = if embedded { + adapter + .get_report( + "scope-session", + PATH_REPORT, + &GetReportOpts { + page: 1, + per_page: 25, + }, + ) + .await + .map(|_| ()) + } else { + adapter + .get_report_results( + "scope-session", + PATH_REPORT, + &ResultQuery { + page: 1, + per_page: 25, + ..Default::default() + }, + ) + .await + .map(|_| ()) + }; + assert!( + matches!(result, Err(GatewayError::BackendUnavailable(ref detail)) + if detail == "backend returned results outside the requested report"), + "embedded={embedded}: {result:?}" + ); + assert!(server + .command_history() + .iter() + .any(|entry| entry.command_name() == "get_results")); + server.shutdown().await; + } +} diff --git a/crates/gvm-gateway-rest/src/reports.rs b/crates/gvm-gateway-rest/src/reports.rs index c6feb613..5a040712 100644 --- a/crates/gvm-gateway-rest/src/reports.rs +++ b/crates/gvm-gateway-rest/src/reports.rs @@ -1338,7 +1338,7 @@ pub(crate) fn get_report_results_docs(op: TransformOperation<'_>) -> TransformOp .id("getReportResults") .tag("Reports") .summary("Get paginated results for a report") - .description("Returns results and counts scoped to the report in the path, including boolean filters. Reserved report/pagination controls and unsupported inclusive comparisons such as severity>=7 return 400. Cross-report backend rows fail as 502 rather than being returned or silently discarded.") + .description("Returns results and counts scoped to the report in the path, including boolean filters. Reserved report/pagination controls and unsupported inclusive comparisons such as severity>=7 return 400. Backend rows with missing or mismatched report references fail as 502 rather than being returned or silently discarded.") .security_requirement("bearerAuth") .input::<(Path, Query)>() .response_with::<200, Json, _>(ok_json("Paginated list of results")); diff --git a/spec/rest-api/reports.yaml b/spec/rest-api/reports.yaml index c507595f..3ced772e 100644 --- a/spec/rest-api/reports.yaml +++ b/spec/rest-api/reports.yaml @@ -148,7 +148,7 @@ paths: comparison operators retain GMP semantics; unsupported inclusive operators such as `severity>=7` or `severity<=7` return 400 rather than being silently ignored. Use supported strict or equality comparisons explicitly. - A backend response containing rows from another report fails as 502; + A backend response with missing or mismatched row report references fails as 502; the gateway never drops those rows while retaining misleading counts. parameters: - $ref: "./common.yaml#/components/parameters/FilterString" diff --git a/spec/rest-api/test-spec.md b/spec/rest-api/test-spec.md index 588cc75d..2699be60 100644 --- a/spec/rest-api/test-spec.md +++ b/spec/rest-api/test-spec.md @@ -381,7 +381,8 @@ and typed library contracts; absence is never a synthetic negative observation. reject attempts to replace report identity or endpoint-owned pagination. - Unsupported inclusive `>=`/`<=` comparators outside quoted literal values return 400 before the results operation, never silently ignored success. -- A deliberately inconsistent successful backend response containing another - report ID returns a sanitized 502, not partial data with unadjusted counts. +- A successful backend response with a missing report association or another + report ID returns a sanitized 502 for both scoped-result and embedded-report + loading, not partial data with unadjusted counts. - Upper/lowercase UUID spellings identify the same report. Keep returned payload spelling and optional source metadata unchanged. diff --git a/worklog.md b/worklog.md index a7541606..ba2b7431 100644 --- a/worklog.md +++ b/worklog.md @@ -134,3 +134,8 @@ Validation (source /workspace/api-agent-env; CARGO_TARGET_DIR=/workspace/.cache/ - Verification in progress using report-test-env and an isolated copy of the existing cache; no dependency changes. - Final verification: full REST suite 214 passed (including generated no-store schema), gateway contract 30 passed (including served-generated/curated header-schema parity); fmt check and required strict workspace/all-target/all-feature Clippy passed. Used an isolated copy of the existing report cache to avoid other worktree artifacts; no dependency changes. + +## 2026-11-20 — issue #741 review +- Review correctly identified that successful rows missing their report association bypassed the response-side scope check. +- Reject absent and mismatched report identities before conversion for both report-results and embedded-report paths; preserve case-equivalent UUID acceptance. +- Added successful-response fixture coverage without a report association through both typed adapter paths. Updated the published report error contract to describe unverifiable rows.