diff --git a/crates/engine/src/cmd/props.rs b/crates/engine/src/cmd/props.rs index c8c4681ed..e80c846f8 100644 --- a/crates/engine/src/cmd/props.rs +++ b/crates/engine/src/cmd/props.rs @@ -109,10 +109,18 @@ pub fn effect_from(cmd: &str, p: &Value, key: &str) -> Result> { Ok(Some(effect)) } +/// Most keys an effect object may carry (the widest effect takes about a dozen). +const MAX_EFFECT_KEYS: usize = 32; + /// Refuse the keys of effect `given` that `parse` ignores, naming the keys the effect takes. Set to /// null, a key it reads fails to parse or changes the effect; a key it ignores changes nothing. fn refuse_ignored_effect_keys(cmd: &str, at: &str, given: &Value, parse: impl Fn(&Value) -> Option) -> Result<()> { let Some(fields) = given.as_object() else { return Ok(()) }; + // Each key is probed by reparsing the whole object without it: bounded, or a long list of + // unknown keys costs its length squared before it is refused. + if fields.len() > MAX_EFFECT_KEYS { + return Err(bad(cmd, format!("{at}: more than {MAX_EFFECT_KEYS} properties"))); + } let parsed = parse(given); let ignored: Vec<&str> = fields .iter()