From 92fe8dc7c34fa0c29f5cd248af9d4bf1e5cd2a9b Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 04:33:21 -0600 Subject: [PATCH 1/2] id(world-manifest): reject unknown world.toml keys instead of silently dropping them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WorldManifest had no deny_unknown_fields and the nested WorldExecutionProfile is #[serde(default)] only, so a typo'd grants/ceiling/schedules key — or a typo inside [profile] — parsed clean, planned zero steps, and diff reported no drift: a revocation the admin wrote was never applied and nothing said so. Per the triage pin on #2876 (Shape 1): WorldManifest gains deny_unknown_fields (its only deserialization is this TOML parse), and parse() explicitly rejects unknown [profile] keys naming the offending key. WorldExecutionProfile itself stays lenient — it is also deserialized from host-returned wire JSON, where a newer host may send fields this build does not know. Fixes #2876 --- pkgs/id/src/world_manifest.rs | 74 ++++++++++++++++++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/pkgs/id/src/world_manifest.rs b/pkgs/id/src/world_manifest.rs index 98baa61560..84f1745cf6 100644 --- a/pkgs/id/src/world_manifest.rs +++ b/pkgs/id/src/world_manifest.rs @@ -24,7 +24,7 @@ use crate::world_limits::WorldExecutionProfile; /// alone by [`plan`], so a minimal manifest drifts nothing; a field that is /// present — even empty, like `grants = []` — is authoritative. #[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] -#[serde(default, rename_all = "snake_case")] +#[serde(default, rename_all = "snake_case", deny_unknown_fields)] pub struct WorldManifest { /// A content hash of an already-installed module, encoded as 1 to 64 plain /// hexadecimal digits (no `blake3:` prefix). Mutually exclusive with @@ -148,13 +148,56 @@ impl ApplyStep { /// /// # Errors /// -/// Invalid TOML, or fields that name an unknown capability. +/// Invalid TOML, an unknown key (top-level, or inside `[profile]`), or +/// fields that name an unknown capability. pub fn parse(text: &str) -> Result { + reject_unknown_profile_keys(text)?; let manifest: WorldManifest = toml::from_str(text).map_err(anyhow::Error::new)?; manifest.validate()?; Ok(manifest) } +/// The `[profile]` table's known keys: the fields of +/// [`WorldExecutionProfile`]. The list lives here, next to [`parse`], +/// because the profile struct itself must stay lenient: it is also +/// deserialized from host-returned JSON (see `current_world_state` in +/// `commands::world`), where a newer host may send fields this build +/// does not know. +const PROFILE_KEYS: [&str; 6] = [ + "wasm_fuel", + "wasm_memory_bytes", + "wasm_message_bytes", + "native_memory_bytes", + "native_cpu_seconds", + "native_call_deadline_ms", +]; + +/// Reject unknown keys in a manifest's `[profile]` table, naming the key. +/// +/// `WorldManifest` denies unknown top-level keys via serde, but the +/// nested profile cannot use `deny_unknown_fields` (see +/// [`PROFILE_KEYS`]), so [`parse`] checks the table itself: a typo'd +/// limit key (`wasm_fuell = 1`) must fail loudly instead of silently +/// leaving the live profile alone (#2876). +fn reject_unknown_profile_keys(text: &str) -> Result<()> { + let document: toml::Table = toml::from_str(text).map_err(anyhow::Error::new)?; + let Some(profile) = document.get("profile") else { + return Ok(()); + }; + let Some(profile) = profile.as_table() else { + // Not a table: the manifest deserialization in `parse` reports it. + return Ok(()); + }; + for key in profile.keys() { + ensure!( + PROFILE_KEYS.contains(&key.as_str()), + "unknown key {key:?} in [profile] of world manifest (known keys: {})", + PROFILE_KEYS.join(", ") + ); + } + Ok(()) +} + impl WorldManifest { /// Validate the manifest: grants and ceiling name only known capabilities, /// schedule ids are bounded printable ASCII, and fire times are positive. @@ -463,6 +506,33 @@ wasm_fuel = 5_000_000 assert_eq!(round_trip(&manifest).unwrap(), manifest); } + #[test] + fn unknown_top_level_keys_are_rejected() { + // #2876: a typo'd or bogus top-level key must fail parse, naming + // the key — never silently drop a revocation the admin wrote. + let err = parse("grant = []").unwrap_err(); + assert!(format!("{err}").contains("grant"), "{err}"); + let err = parse("bogus_key = 1").unwrap_err(); + assert!(format!("{err}").contains("bogus_key"), "{err}"); + } + + #[test] + fn typoed_field_keys_are_rejected() { + // The probe matrix from #2876: each of these used to parse clean + // and plan zero steps. + for text in ["ceilin = []", "schedule = {}", "seeds = 99"] { + assert!(parse(text).is_err(), "parsed clean: {text}"); + } + } + + #[test] + fn unknown_profile_keys_are_rejected() { + // #2876: same strictness inside [profile], enforced by parse + // itself because the profile struct stays lenient for host JSON. + let err = parse("[profile]\nwasm_fuell = 1").unwrap_err(); + assert!(format!("{err}").contains("wasm_fuell"), "{err}"); + } + #[test] fn an_empty_manifest_drifts_nothing() { let manifest = WorldManifest::default(); From 3e7563705ccd29b23dea5b121e0a6c0de0f946f0 Mon Sep 17 00:00:00 2001 From: Drewry Pope Date: Sun, 1 Nov 2026 04:40:00 -0600 Subject: [PATCH 2/2] =?UTF-8?q?id(world-manifest):=20profile=20key=20probe?= =?UTF-8?q?=20via=20typed=20deserializer=20=E2=80=94=20preserve=20full=20u?= =?UTF-8?q?64=20range?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Codex review (P2) on the previous commit: reject_unknown_profile_keys converted the whole document to toml::Table (toml::Value), whose integers are i64-capped, so a manifest with seed above i64::MAX — accepted by the typed WorldManifest as u64 — failed parse in diff and apply even with no [profile] section. Replace the Value walk with a deny_unknown_fields probe struct read through the typed TOML deserializer: known profile fields deserialize as IgnoredAny (their values are validated by the real parse), unknown keys are rejected naming the key, and full-width u64 values pass through. Adds full_width_u64_values_still_parse covering seed and wasm_fuel at u64::MAX. --- pkgs/id/src/world_manifest.rs | 84 +++++++++++++++++++++-------------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/pkgs/id/src/world_manifest.rs b/pkgs/id/src/world_manifest.rs index 84f1745cf6..aaf8940817 100644 --- a/pkgs/id/src/world_manifest.rs +++ b/pkgs/id/src/world_manifest.rs @@ -157,44 +157,48 @@ pub fn parse(text: &str) -> Result { Ok(manifest) } -/// The `[profile]` table's known keys: the fields of -/// [`WorldExecutionProfile`]. The list lives here, next to [`parse`], -/// because the profile struct itself must stay lenient: it is also -/// deserialized from host-returned JSON (see `current_world_state` in -/// `commands::world`), where a newer host may send fields this build -/// does not know. -const PROFILE_KEYS: [&str; 6] = [ - "wasm_fuel", - "wasm_memory_bytes", - "wasm_message_bytes", - "native_memory_bytes", - "native_cpu_seconds", - "native_call_deadline_ms", -]; - /// Reject unknown keys in a manifest's `[profile]` table, naming the key. /// /// `WorldManifest` denies unknown top-level keys via serde, but the -/// nested profile cannot use `deny_unknown_fields` (see -/// [`PROFILE_KEYS`]), so [`parse`] checks the table itself: a typo'd -/// limit key (`wasm_fuell = 1`) must fail loudly instead of silently -/// leaving the live profile alone (#2876). +/// nested profile cannot use `deny_unknown_fields` on +/// [`WorldExecutionProfile`] itself: that struct must stay lenient +/// because it is also deserialized from host-returned JSON (see +/// `current_world_state` in `commands::world`), where a newer host may +/// send fields this build does not know. So [`parse`] runs this probe +/// instead: a typo'd limit key (`wasm_fuell = 1`) must fail loudly +/// instead of silently leaving the live profile alone (#2876). +/// +/// The probe deserializes through the typed TOML deserializer, never +/// `toml::Value` — whose integers are `i64`-capped — so full-width +/// `u64` values the real types accept (a `seed` or `wasm_fuel` above +/// `i64::MAX`) pass through untouched. The known fields' values are +/// irrelevant here (the real parse validates them), so they are read +/// as [`serde::de::IgnoredAny`]. fn reject_unknown_profile_keys(text: &str) -> Result<()> { - let document: toml::Table = toml::from_str(text).map_err(anyhow::Error::new)?; - let Some(profile) = document.get("profile") else { - return Ok(()); - }; - let Some(profile) = profile.as_table() else { - // Not a table: the manifest deserialization in `parse` reports it. - return Ok(()); - }; - for key in profile.keys() { - ensure!( - PROFILE_KEYS.contains(&key.as_str()), - "unknown key {key:?} in [profile] of world manifest (known keys: {})", - PROFILE_KEYS.join(", ") - ); - } + #[derive(Deserialize)] + struct ProfileProbe { + #[serde(default)] + profile: Option, + } + + #[derive(Deserialize)] + #[serde(deny_unknown_fields)] + struct ProfileKeysProbe { + #[serde(default)] + wasm_fuel: Option, + #[serde(default)] + wasm_memory_bytes: Option, + #[serde(default)] + wasm_message_bytes: Option, + #[serde(default)] + native_memory_bytes: Option, + #[serde(default)] + native_cpu_seconds: Option, + #[serde(default)] + native_call_deadline_ms: Option, + } + + let _: ProfileProbe = toml::from_str(text).map_err(anyhow::Error::new)?; Ok(()) } @@ -533,6 +537,18 @@ wasm_fuel = 5_000_000 assert!(format!("{err}").contains("wasm_fuell"), "{err}"); } + #[test] + fn full_width_u64_values_still_parse() { + // Regression (Codex review of the fix for this issue): the + // [profile] key check must not route the document through + // toml::Value, whose i64 integers would reject u64 values the + // typed manifest accepts. + let manifest = parse("seed = 18446744073709551615").unwrap(); + assert_eq!(manifest.seed, Some(u64::MAX)); + let manifest = parse("[profile]\nwasm_fuel = 18446744073709551615").unwrap(); + assert_eq!(manifest.profile.wasm_fuel, Some(u64::MAX)); + } + #[test] fn an_empty_manifest_drifts_nothing() { let manifest = WorldManifest::default();