From 2d01d5ce58320e43577ca975b18214a7e1f9f68f Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Tue, 3 Nov 2026 00:08:34 -0600 Subject: [PATCH] fix(id): refuse repeated tag pairs in publish (#4772) LocalEvents::publish checked each tag individually but never the batch against itself, so a repeated exact (name, value) pair recorded two identical live claims. Refuse the repeat before anything is recorded, in the sibling-validator style (tag.clear, ChainExt.after, note.revise parents). Same name with different values, and bare plus valued, stay legal. --- pkgs/id/src/local_events.rs | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pkgs/id/src/local_events.rs b/pkgs/id/src/local_events.rs index f199090acc..f4be9fadee 100644 --- a/pkgs/id/src/local_events.rs +++ b/pkgs/id/src/local_events.rs @@ -276,8 +276,12 @@ impl LocalEvents { tags: &[(String, Option)], ) -> Result { let document = DocumentRef::for_bytes(media_type, content)?; + let mut seen = HashSet::with_capacity(tags.len()); for (name, value) in tags { check_tag(name, value.as_deref())?; + if !seen.insert((name, value)) { + bail!("a publish names the same tag twice"); + } } let id = self.record(DOCUMENT_KIND, None, Some(document.clone()), None, None, &[])?; let mut claims = Vec::with_capacity(tags.len()); @@ -1101,6 +1105,44 @@ mod tests { assert!(check_tag("e\u{301}", None).is_err()); } + #[test] + fn test_publish_refuses_a_repeated_tag_pair_before_recording() { + // Regression for #4772: a repeated exact (name, value) pair in one + // publish call recorded two identical live claims. The batch must be + // refused before anything is recorded, like the sibling validators + // (tag.clear claim lists, ChainExt.after, note.revise parents). + let (_dir, mut events) = open_events(); + assert!(events.frontier().unwrap().is_empty()); + for tags in [ + vec![ + ("city".to_owned(), Some("Seattle".to_owned())), + ("city".to_owned(), Some("Seattle".to_owned())), + ], + vec![("city".to_owned(), None), ("city".to_owned(), None)], + ] { + assert!(events.publish("text/plain", b"hello", &tags).is_err()); + assert!( + events.frontier().unwrap().is_empty(), + "a refused publish records nothing" + ); + } + } + + #[test] + fn test_publish_accepts_distinct_pairs_sharing_a_name() { + // Same name with different values, and bare plus valued, are distinct + // claims and must stay legal — only the exact pair repeats refuse. + let (_dir, mut events) = open_events(); + let tags = vec![ + ("city".to_owned(), Some("Seattle".to_owned())), + ("city".to_owned(), Some("Portland".to_owned())), + ("city".to_owned(), None), + ]; + let published = events.publish("text/plain", b"hello", &tags).unwrap(); + assert_eq!(published.claims.len(), 3); + assert_eq!(events.tags_on(published.id).unwrap().len(), 3); + } + fn open_events() -> (tempfile::TempDir, LocalEvents) { let dir = tempfile::tempdir().unwrap(); let events = LocalEvents::open(dir.path(), SigningKey::from_bytes(&[7; 32])).unwrap();