From 30573041bf07264d2be52ee2617cf4ae63803c7d Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 02:21:05 -0600 Subject: [PATCH 1/2] fix(id): restore refuses Issued display names mint could not produce (#2960) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WorldCore::restore inserted journaled participants verbatim, so a hand-edited or fork-copied journal could restore empty, control-bearing, or over-length display names that mint (which sanitizes and refuses empty results) can never produce — and checkpointing then re-journaled them permanently. Refuse the whole restore when a journaled name is empty or differs from sanitize_display_name(name), beside the existing participant-0 refusal. Legitimately minted journals always carry sanitized names, so none are affected. Tests beside restore_refuses_an_issued_participant_zero: empty, control-bearing, 49-char, untrimmed, and control-only names refused; a minted journal restores fine. --- pkgs/id/src/world/core.rs | 14 ++++++++ pkgs/id/src/world/tests.rs | 69 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 83 insertions(+) diff --git a/pkgs/id/src/world/core.rs b/pkgs/id/src/world/core.rs index 258eaf1c7b..b0b750f178 100644 --- a/pkgs/id/src/world/core.rs +++ b/pkgs/id/src/world/core.rs @@ -228,6 +228,20 @@ impl WorldCore { participant.id != 0, "participant 0 is the reserved host identity and cannot be issued" ); + // #2960: the journaled display name must be one mint + // could have produced. Mint sanitizes every name + // (control and format characters stripped, capped at + // 48 chars, trimmed) and refuses an empty result, so a + // name that differs from its own sanitization — or is + // empty — comes from a journal no live path can write; + // refuse the whole restore. + ensure!( + !participant.display_name.is_empty() + && participant.display_name + == sanitize_display_name(&participant.display_name), + "participant {} has a display name mint could not have produced", + participant.id + ); ensure!( !core.capabilities.contains_key(&participant.id), "participant {} issued twice", diff --git a/pkgs/id/src/world/tests.rs b/pkgs/id/src/world/tests.rs index c13fd32edb..6ba23280c8 100644 --- a/pkgs/id/src/world/tests.rs +++ b/pkgs/id/src/world/tests.rs @@ -1783,6 +1783,75 @@ mod tests { } } + #[test] + fn restore_refuses_issued_display_names_mint_could_not_produce() { + // #2960: restore inserts journaled participants verbatim, but + // mint sanitizes every display name (control/format characters + // stripped, 48-char cap, trimmed) and refuses an empty result. + // A journaled name mint could never have produced — empty, + // control-bearing, over-length, or untrimmed — must refuse the + // whole restore, while a legitimately minted journal restores + // with byte-identical names. + let mut source = world(8); + let (owner, owner_token) = source + .issue_capability("Ada", WorldScopes::GUEST, CapabilityBounds::default()) + .unwrap(); + let legitimate = JournalEntry::Issued { + participant: owner.clone(), + digest: hex_encode(&token_digest(owner_token.expose())), + scopes: WorldScopes::GUEST.bits(), + parent: None, + expires_at: None, + uses: None, + used: 0, + subject: None, + }; + let header = JournalEntry::Created { + world_id: "test-world".to_owned(), + version: JOURNAL_VERSION, + }; + // A legitimately minted name restores fine. + WorldCore::restore( + "test-world", + WorldLimits::default(), + [header.clone(), legitimate], + ) + .unwrap(); + for bad_name in [ + String::new(), + "a\u{7}\n".to_owned() + &"x".repeat(98), + "a".repeat(49), + "Ada ".to_owned(), + "\u{1}\u{2}".to_owned(), + ] { + let forged = JournalEntry::Issued { + participant: Participant { + id: 1, + display_name: bad_name.clone(), + }, + digest: "ab".repeat(32), + scopes: WorldScopes::GUEST.bits(), + parent: None, + expires_at: None, + uses: None, + used: 0, + subject: None, + }; + let err = match WorldCore::restore( + "test-world", + WorldLimits::default(), + [header.clone(), forged], + ) { + Ok(_) => panic!("restore must refuse display name {bad_name:?}"), + Err(err) => err, + }; + assert!( + err.to_string().contains("display name"), + "error must name the display name rule: {err}" + ); + } + } + #[test] fn events_are_sequenced_and_reconnect_can_catch_up() { let mut core = world(8); From fe525be0a44100191699fe3b0783dca93c9c0d49 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 02:52:06 -0600 Subject: [PATCH 2/2] fix(id): accept pre-#2112 legacy display names on restore (#2960) Codex P2 on #4279: journals minted before 872aa09f (#2112) used a control-only display-name sanitizer, so legitimate names with ZWJ/ZWNJ (family emoji) are not fixed points of the current sanitizer and the #2960 restore check would have rejected those whole worlds. Restore now accepts a fixed point of either sanitizer; names no mint version could produce (empty, control-bearing, >48 chars, untrimmed) are still refused. Adds legacy_sanitize_display_name (the exact pre-#2112 function), a util test, and a restore test for a ZWJ family-emoji name. --- pkgs/id/src/world/core.rs | 19 ++++++++++++++----- pkgs/id/src/world/mod.rs | 3 ++- pkgs/id/src/world/tests.rs | 23 +++++++++++++++++++++++ pkgs/id/src/world/util.rs | 26 +++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 7 deletions(-) diff --git a/pkgs/id/src/world/core.rs b/pkgs/id/src/world/core.rs index b0b750f178..b41bb5bf1e 100644 --- a/pkgs/id/src/world/core.rs +++ b/pkgs/id/src/world/core.rs @@ -232,13 +232,22 @@ impl WorldCore { // could have produced. Mint sanitizes every name // (control and format characters stripped, capped at // 48 chars, trimmed) and refuses an empty result, so a - // name that differs from its own sanitization — or is - // empty — comes from a journal no live path can write; - // refuse the whole restore. + // name that is a fixed point of neither sanitization + // — or is empty — comes from a journal no live path + // can write; refuse the whole restore. The pre-#2112 + // sanitizer (control characters only) is also accepted: + // journals minted before format stripping landed can + // legitimately carry ZWJ/ZWNJ names such as family + // emoji, and those worlds restored fine before this + // check existed. ensure!( !participant.display_name.is_empty() - && participant.display_name - == sanitize_display_name(&participant.display_name), + && (participant.display_name + == sanitize_display_name(&participant.display_name) + || participant.display_name + == legacy_sanitize_display_name( + &participant.display_name + )), "participant {} has a display name mint could not have produced", participant.id ); diff --git a/pkgs/id/src/world/mod.rs b/pkgs/id/src/world/mod.rs index 40accdbf39..15ecd8fe69 100644 --- a/pkgs/id/src/world/mod.rs +++ b/pkgs/id/src/world/mod.rs @@ -47,7 +47,8 @@ pub use handle::WorldHandle; pub use metrics::{HistogramSnapshot, MetricsSnapshot, WorldMetrics}; pub use util::{EventPage, hex_encode, publish_records}; pub(crate) use util::{ - constant_time_eq, hex_decode_32, sanitize_chat, sanitize_display_name, token_digest, + constant_time_eq, hex_decode_32, legacy_sanitize_display_name, sanitize_chat, + sanitize_display_name, token_digest, }; /// A chat participant may send at most this many lines during the rolling window. diff --git a/pkgs/id/src/world/tests.rs b/pkgs/id/src/world/tests.rs index 6ba23280c8..ae9fe16a38 100644 --- a/pkgs/id/src/world/tests.rs +++ b/pkgs/id/src/world/tests.rs @@ -1817,6 +1817,29 @@ mod tests { [header.clone(), legitimate], ) .unwrap(); + // A name minted before #2112's format stripping — a fixed point + // of the legacy sanitizer only, here a ZWJ family emoji — also + // restores fine: those journals predate the current sanitizer + // and restored successfully before this check existed. + let legacy = JournalEntry::Issued { + participant: Participant { + id: 1, + display_name: "\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}".to_owned(), + }, + digest: "ab".repeat(32), + scopes: WorldScopes::GUEST.bits(), + parent: None, + expires_at: None, + uses: None, + used: 0, + subject: None, + }; + WorldCore::restore( + "test-world", + WorldLimits::default(), + [header.clone(), legacy], + ) + .unwrap(); for bad_name in [ String::new(), "a\u{7}\n".to_owned() + &"x".repeat(98), diff --git a/pkgs/id/src/world/util.rs b/pkgs/id/src/world/util.rs index 4f3c42a094..365e6bf30f 100644 --- a/pkgs/id/src/world/util.rs +++ b/pkgs/id/src/world/util.rs @@ -75,6 +75,22 @@ pub(crate) fn sanitize_display_name(name: &str) -> String { .to_owned() } +/// The display-name sanitizer as it existed before #2112 (commit +/// 872aa09f) added format-character stripping: control characters +/// stripped, 48-char cap, trimmed. Journals written by that earlier +/// mint can legitimately carry names that are fixed points of this +/// version but not of the current one — ZWJ/ZWNJ sequences such as +/// family emoji are the common case — and restore accepts those for +/// journal compatibility (see the #2960 check in `WorldCore::restore`). +pub(crate) fn legacy_sanitize_display_name(name: &str) -> String { + name.chars() + .filter(|ch| !ch.is_control()) + .take(48) + .collect::() + .trim() + .to_owned() +} + pub(crate) fn sanitize_chat(text: &str) -> String { text.chars() .filter(|ch| { @@ -88,7 +104,7 @@ pub(crate) fn sanitize_chat(text: &str) -> String { #[cfg(test)] mod tests { - use super::{sanitize_chat, sanitize_display_name}; + use super::{legacy_sanitize_display_name, sanitize_chat, sanitize_display_name}; #[test] fn display_name_strips_bidi_override() { @@ -106,6 +122,14 @@ mod tests { assert_eq!(sanitize_display_name("a\u{200c}b"), "ab"); } + #[test] + fn legacy_display_name_keeps_joiners_but_strips_controls() { + let family = "\u{1f468}\u{200d}\u{1f469}\u{200d}\u{1f467}"; + assert_eq!(legacy_sanitize_display_name(family), family); + assert_eq!(legacy_sanitize_display_name("a\u{7}b"), "ab"); + assert_eq!(legacy_sanitize_display_name(" Ada "), "Ada"); + } + #[test] fn display_name_strips_control_chars() { assert_eq!(sanitize_display_name("a\u{7}b"), "ab");