diff --git a/src/remote.rs b/src/remote.rs index 0c44252..7c0f1e2 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -1333,11 +1333,12 @@ fn svg_is_plain(svg: &str) -> bool { if l.contains(" Resp { "click" => ("computer_use_click", json!({"x": x, "y": y, "button": v["button"].as_str().unwrap_or("left"), "count": v["count"].as_u64().unwrap_or(1).clamp(1, 3), "modifier_keys": mods(v)})), // 虛擬觸控板: the pointer moves (no click), and a drag goes along the finger's path. "move" => ("computer_use_mouse_move", json!({"x": x, "y": y})), - "drag" => ("computer_use_drag", json!({"path": v["path"], "modifier_keys": mods(v)})), + // (A finger's path is a few dozen points; a longer one is cut, not walked for minutes.) + "drag" => ("computer_use_drag", json!({"path": v["path"].as_array().map(|a| a.iter().take(MAX_DRAG_POINTS).cloned().collect::>()).unwrap_or_default(), "modifier_keys": mods(v)})), "type" => ("computer_use_typing", json!({"value": v["text"]})), // (A combination too: "cmd+tab", from the key bar.) "key" => ("computer_use_press_key", json!({"key": v["key"]})), @@ -3696,6 +3701,24 @@ mod tests { use super::*; + /// A chart goes to the phone only as shapes and words: whatever a bot (or a page it read) + /// writes in a diagram's labels, links and styles, nothing in the drawing can run. + #[test] + fn a_drawn_chart_runs_nothing() { + for bad in ["", "", "", "", "", "", "", ""] { + assert!(!svg_is_plain(bad), "{bad}"); + } + for fine in ["turn on = yes, onward", "", "conclusion=1"] { + assert!(svg_is_plain(fine), "{fine}"); + } + for src in ["graph TD\n A[\"\"] --> B[\"\"]", "graph TD\n A --> B\n click A href \"javascript:alert(1)\"", "graph TD\n A[\"x\\\" onload=\\\"alert(1)\"] --> B"] { + if let Ok(svg) = crate::diagram::svg(src, false) { + let l = svg.to_ascii_lowercase(); + assert!(!svg_is_plain(&svg) || (!l.contains("