Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions pkgs/id/src/world/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 52 additions & 0 deletions pkgs/id/src/world/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down