diff --git a/pkgs/id/src/world/core.rs b/pkgs/id/src/world/core.rs index 82f80da4f8..77b8fd35c4 100644 --- a/pkgs/id/src/world/core.rs +++ b/pkgs/id/src/world/core.rs @@ -180,6 +180,15 @@ impl WorldCore { subject, } => { let digest = hex_decode_32(&digest).context("malformed capability digest")?; + // #2972: participant 0 is the reserved host/system + // identity. Mint can never issue it (ids start at 1), + // so an Issued entry naming it is a forged host + // capability with a journal-chosen digest — refuse + // the whole restore before anything is applied. + ensure!( + participant.id != 0, + "participant 0 is the reserved host identity and cannot be issued" + ); 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 855272566a..435c269184 100644 --- a/pkgs/id/src/world/tests.rs +++ b/pkgs/id/src/world/tests.rs @@ -1524,6 +1524,58 @@ mod tests { assert!(WorldCore::restore("test-world", WorldLimits::default(), entries).is_err()); } + #[test] + fn restore_refuses_an_issued_participant_zero() { + // #2972: participant 0 is the reserved host/system identity — + // mint can never issue it, so a journal issuing it to itself + // (with a self-chosen digest) must be refused outright, whether + // the forged entry stands alone or follows legitimate entries. + let mut source = world(8); + let (owner, owner_token) = source + .issue_capability("Ada", WorldScopes::GUEST, CapabilityBounds::default()) + .unwrap(); + let legitimate = JournalEntry::Issued { + participant: owner, + digest: hex_encode(&token_digest(owner_token.expose())), + scopes: WorldScopes::GUEST.bits(), + parent: None, + expires_at: None, + uses: None, + used: 0, + subject: None, + }; + let forged = JournalEntry::Issued { + participant: Participant { + id: 0, + display_name: "host".to_owned(), + }, + digest: "ab".repeat(32), + 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, + }; + for entries in [ + vec![header.clone(), forged.clone()], + vec![header, legitimate, forged], + ] { + let err = match WorldCore::restore("test-world", WorldLimits::default(), entries) { + Ok(_) => panic!("restore must refuse an Issued participant 0"), + Err(err) => err, + }; + assert!( + err.to_string().contains("reserved host identity"), + "error must name the reserved id: {err}" + ); + } + } + #[test] fn events_are_sequenced_and_reconnect_can_catch_up() { let mut core = world(8);