From 344fad36e9d6f242afaa2c26871ef9bbed40e8b2 Mon Sep 17 00:00:00 2001 From: incrypto32 Date: Tue, 11 Feb 2025 13:43:14 +0400 Subject: [PATCH] graph: Prevent duplicate source subgraphs in manifest validation --- graph/src/data/subgraph/mod.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/graph/src/data/subgraph/mod.rs b/graph/src/data/subgraph/mod.rs index cbb4a11a2aa..d14b2c89b29 100644 --- a/graph/src/data/subgraph/mod.rs +++ b/graph/src/data/subgraph/mod.rs @@ -719,6 +719,23 @@ impl UnvalidatedSubgraphManifest { )); } + // Check for duplicate source subgraphs + let mut seen_sources = std::collections::HashSet::new(); + for ds in data_sources.iter() { + if let DataSource::Subgraph(ds) = ds { + let source_id = ds.source.address(); + if !seen_sources.insert(source_id.clone()) { + errors.push(SubgraphManifestValidationError::DataSourceValidation( + "subgraph".to_string(), + anyhow!( + "Multiple subgraph datasources cannot use the same source subgraph {}", + source_id + ), + )); + } + } + } + errors }