From 37230e01a5a8c5a1a610596aa3cbf22e52c395be Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 01:05:52 -0600 Subject: [PATCH 1/2] fix(id): validate Issued scopes in WorldCore::restore (#2890) Restore now refuses a journaled Issued entry whose scopes fail WorldScopes::from_bits (unnamed bits) or lack JOIN, mirroring mint, with errors naming the participant. Admin BUILDER/MODERATOR bits still round-trip via ALL_BITS. Regression tests cover the unnamed-bit and JOIN-less refusals plus guest/builder/moderator restores. --- pkgs/id/src/world/core.rs | 17 ++++++++- pkgs/id/src/world/tests.rs | 70 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 86 insertions(+), 1 deletion(-) diff --git a/pkgs/id/src/world/core.rs b/pkgs/id/src/world/core.rs index 258eaf1c7b..17e7adc4db 100644 --- a/pkgs/id/src/world/core.rs +++ b/pkgs/id/src/world/core.rs @@ -253,6 +253,21 @@ impl WorldCore { participant.id ); } + // #2890: mint refuses scope bits from_bits rejects + // and scopes without JOIN; a journaled Issued entry + // must meet the same bar, or restore would resurrect + // a capability mint could never have issued. + let Some(validated_scopes) = WorldScopes::from_bits(scopes) else { + anyhow::bail!( + "participant {} journaled scopes {scopes:#04x} name no scope", + participant.id + ); + }; + ensure!( + validated_scopes.contains(WorldScopes::JOIN), + "participant {} journaled scopes must include join scope", + participant.id + ); core.next_participant_id = core.next_participant_id.max( participant .id @@ -264,7 +279,7 @@ impl WorldCore { CapabilityRecord { digest, participant, - scopes: WorldScopes(scopes), + scopes: validated_scopes, parent, revoked: false, bounds: CapabilityBounds { expires_at, uses }, diff --git a/pkgs/id/src/world/tests.rs b/pkgs/id/src/world/tests.rs index c13fd32edb..1b0d31b14e 100644 --- a/pkgs/id/src/world/tests.rs +++ b/pkgs/id/src/world/tests.rs @@ -699,6 +699,76 @@ mod tests { ); } + fn issued_entry(scopes: u8) -> JournalEntry { + let secret = "ef".repeat(32); + let digest = hex_encode(&token_digest(&format!("1.{secret}"))); + JournalEntry::Issued { + participant: Participant { + id: 1, + display_name: "ann".to_owned(), + }, + digest, + scopes, + parent: None, + expires_at: None, + uses: None, + used: 0, + subject: None, + } + } + + fn restore_with_scopes(scopes: u8) -> anyhow::Result { + WorldCore::restore( + "scopes", + WorldLimits::default(), + vec![ + JournalEntry::Created { + world_id: "scopes".to_owned(), + version: JOURNAL_VERSION, + }, + issued_entry(scopes), + ], + ) + } + + #[test] + fn restore_refuses_issued_scopes_naming_no_scope() { + // 0x80 names no scope; from_bits rejects the whole byte. + let error = restore_with_scopes(0x87).unwrap_err(); + assert!( + error.to_string().contains("participant 1"), + "error names the participant: {error}" + ); + assert!( + error.to_string().contains("name no scope"), + "error explains the refusal: {error}" + ); + } + + #[test] + fn restore_refuses_issued_scopes_without_join() { + for scopes in [0, WorldScopes::CHAT.0, WorldScopes::INPUT.0] { + let error = restore_with_scopes(scopes).unwrap_err(); + assert!( + error.to_string().contains("join scope"), + "scopes {scopes:#04x} refused for missing JOIN: {error}" + ); + } + } + + #[test] + fn restore_accepts_guest_and_admin_bit_scopes() { + for scopes in [ + WorldScopes::GUEST.0, + WorldScopes::JOIN.0 | WorldScopes::BUILDER.0, + WorldScopes::JOIN.0 | WorldScopes::MODERATOR.0, + ] { + let restored = restore_with_scopes(scopes).unwrap(); + let record = restored.core.capabilities.get(&1).unwrap(); + assert_eq!(record.scopes.bits(), scopes, "scopes round-trip"); + } + } + #[test] fn a_restore_closes_presence_the_journal_left_open() { let secret = "cd".repeat(32); From 2e03b81fede8bdae5a712ae09a7b65283fe6baf8 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Mon, 2 Nov 2026 01:43:28 -0600 Subject: [PATCH 2/2] test(id): prefix restore scope test names --- pkgs/id/src/world/tests.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkgs/id/src/world/tests.rs b/pkgs/id/src/world/tests.rs index 1b0d31b14e..d7e2471bb7 100644 --- a/pkgs/id/src/world/tests.rs +++ b/pkgs/id/src/world/tests.rs @@ -732,7 +732,7 @@ mod tests { } #[test] - fn restore_refuses_issued_scopes_naming_no_scope() { + fn test_restore_refuses_issued_scopes_naming_no_scope() { // 0x80 names no scope; from_bits rejects the whole byte. let error = restore_with_scopes(0x87).unwrap_err(); assert!( @@ -746,7 +746,7 @@ mod tests { } #[test] - fn restore_refuses_issued_scopes_without_join() { + fn test_restore_refuses_issued_scopes_without_join() { for scopes in [0, WorldScopes::CHAT.0, WorldScopes::INPUT.0] { let error = restore_with_scopes(scopes).unwrap_err(); assert!( @@ -757,7 +757,7 @@ mod tests { } #[test] - fn restore_accepts_guest_and_admin_bit_scopes() { + fn test_restore_accepts_guest_and_admin_bit_scopes() { for scopes in [ WorldScopes::GUEST.0, WorldScopes::JOIN.0 | WorldScopes::BUILDER.0,