From 05bb7ea59caabc691342eaea61478d328ea1a59b Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Sun, 8 Nov 2026 20:29:04 -0600 Subject: [PATCH 1/2] fix(id/world): reject malformed chat.history count types (#7892) A supplied count that is not an unsigned integer was silently treated as omitted and served the default 16 lines. Only an omitted count now falls back to 16; any other JSON kind returns bad_args. Adds string, negative, fractional, null, and object cases to the existing default/clamp world-level regression test. --- pkgs/id/crates/id-worlds/src/world/actor.rs | 27 +++++++++------ pkgs/id/crates/id-worlds/src/world/tests.rs | 38 +++++++++++++++++++++ 2 files changed, 54 insertions(+), 11 deletions(-) diff --git a/pkgs/id/crates/id-worlds/src/world/actor.rs b/pkgs/id/crates/id-worlds/src/world/actor.rs index 982c0634a7..8edcf89f78 100644 --- a/pkgs/id/crates/id-worlds/src/world/actor.rs +++ b/pkgs/id/crates/id-worlds/src/world/actor.rs @@ -1648,17 +1648,22 @@ impl WorldActor { "form.cancel" => self.execute_form_cancel(&request.args), "loc.position" => self.execute_loc_position(&request.args), "chat.say" => self.execute_chat(&request.args), - "chat.history" => Ok(serde_json::json!({ - "lines": chat_history( - &self.core.events, - request - .args - .get("count") - .and_then(serde_json::Value::as_u64) - .unwrap_or(16) - .min(crate::world_caps::MAX_CHAT_HISTORY_LINES as u64) as usize, - ), - })), + "chat.history" => { + // A supplied `count` must be an unsigned integer; only an + // omitted count falls back to the default. Treating a + // malformed count as omitted silently turns a client error + // into a successful read (#7892). + let count = match request.args.get("count") { + None => 16, + Some(value) => value.as_u64().ok_or_else(CapError::bad_args)? as usize, + }; + Ok(serde_json::json!({ + "lines": chat_history( + &self.core.events, + count.min(crate::world_caps::MAX_CHAT_HISTORY_LINES), + ), + })) + } "records.read" => self.execute_records_read(&request.args), "schedule.at" => self.execute_schedule_at(&request.args), "schedule.cancel" => self.execute_schedule_cancel(&request.args), diff --git a/pkgs/id/crates/id-worlds/src/world/tests.rs b/pkgs/id/crates/id-worlds/src/world/tests.rs index 12febdf9b1..1f6038d292 100644 --- a/pkgs/id/crates/id-worlds/src/world/tests.rs +++ b/pkgs/id/crates/id-worlds/src/world/tests.rs @@ -2886,6 +2886,31 @@ mod tests { "chat.history", serde_json::json!({"count": 100_000}), ), + ( + "hist-string", + "chat.history", + serde_json::json!({"count": "2"}), + ), + ( + "hist-negative", + "chat.history", + serde_json::json!({"count": -1}), + ), + ( + "hist-fractional", + "chat.history", + serde_json::json!({"count": 1.5}), + ), + ( + "hist-null", + "chat.history", + serde_json::json!({"count": null}), + ), + ( + "hist-object", + "chat.history", + serde_json::json!({"count": {"n": 2}}), + ), ] .into_iter() .filter(|(id, _, _)| !self.answered.contains(*id)) @@ -2948,6 +2973,19 @@ mod tests { assert_eq!(lines.len(), crate::world_caps::MAX_CHAT_HISTORY_LINES); assert_eq!(lines[0]["text"], "line-7"); assert_eq!(lines[63]["text"], "line-70"); + // A supplied count of the wrong JSON kind is rejected, never + // treated as omitted (#7892). + for id in [ + "hist-string", + "hist-negative", + "hist-fractional", + "hist-null", + "hist-object", + ] { + let malformed = &results[id]; + assert_eq!(malformed["ok"], false, "{id}: {malformed}"); + assert_eq!(malformed["error"], "bad_args", "{id}: {malformed}"); + } // records.read whose first record cannot fit one page is BadArgs, // never an empty page that looks complete. let oversized_result = &results["records-oversized"]; From 4f6da165e6c382c3631f07949fd9a6f5229d2517 Mon Sep 17 00:00:00 2001 From: repo-worker-code-k Date: Tue, 10 Nov 2026 19:08:54 -0600 Subject: [PATCH 2/2] fix(id): clamp chat history count before conversion --- pkgs/id/crates/id-worlds/src/world/actor.rs | 6 +++++- pkgs/id/crates/id-worlds/src/world/tests.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/pkgs/id/crates/id-worlds/src/world/actor.rs b/pkgs/id/crates/id-worlds/src/world/actor.rs index 8edcf89f78..0bf2e5c91d 100644 --- a/pkgs/id/crates/id-worlds/src/world/actor.rs +++ b/pkgs/id/crates/id-worlds/src/world/actor.rs @@ -1655,7 +1655,11 @@ impl WorldActor { // into a successful read (#7892). let count = match request.args.get("count") { None => 16, - Some(value) => value.as_u64().ok_or_else(CapError::bad_args)? as usize, + Some(value) => value + .as_u64() + .ok_or_else(CapError::bad_args)? + .min(crate::world_caps::MAX_CHAT_HISTORY_LINES as u64) + as usize, }; Ok(serde_json::json!({ "lines": chat_history( diff --git a/pkgs/id/crates/id-worlds/src/world/tests.rs b/pkgs/id/crates/id-worlds/src/world/tests.rs index 1f6038d292..9a0edfd80a 100644 --- a/pkgs/id/crates/id-worlds/src/world/tests.rs +++ b/pkgs/id/crates/id-worlds/src/world/tests.rs @@ -2886,6 +2886,11 @@ mod tests { "chat.history", serde_json::json!({"count": 100_000}), ), + ( + "hist-u32-overflow", + "chat.history", + serde_json::json!({"count": 4_294_967_296_u64}), + ), ( "hist-string", "chat.history", @@ -2973,6 +2978,9 @@ mod tests { assert_eq!(lines.len(), crate::world_caps::MAX_CHAT_HISTORY_LINES); assert_eq!(lines[0]["text"], "line-7"); assert_eq!(lines[63]["text"], "line-70"); + let large = &results["hist-u32-overflow"]; + assert_eq!(large["ok"], true, "{large}"); + assert_eq!(large["value"]["lines"], clamped["value"]["lines"]); // A supplied count of the wrong JSON kind is rejected, never // treated as omitted (#7892). for id in [