Skip to content

armgit / cua

Public Imported from GitHub
0

Scale computer-use 2.0 with open-source drivers, cross-OS sandboxes, and benchmarks for training, evaluation, and data generation.

fix(cua-driver): refuse Linux background clicks that only hit a Chromium frame (#4188)

Francesco Bonacci7ee9b37edc4e
diff --git a/libs/cua-driver/rust/Skills/cua-driver/LINUX.md b/libs/cua-driver/rust/Skills/cua-driver/LINUX.md
index fc782f8ad4..c4fa2f56a9 100644
--- a/libs/cua-driver/rust/Skills/cua-driver/LINUX.md
+++ b/libs/cua-driver/rust/Skills/cua-driver/LINUX.md
@@ -197,7 +197,13 @@ takes the focus-free AT-SPI `do_action`-at-point path (`x11_atspi`), exactly
like the macOS/Windows background pixel click. It falls to the MPX
virtual-pointer path (`x11_pixel`) only for non-AX surfaces, **and that path
needs a real Xorg + `/dev/uinput`** — under Xvnc / minimal containers without
-uinput, escalate to `delivery_mode:"foreground"`. (`type_text` in the
+uinput, escalate to `delivery_mode:"foreground"`. The AT-SPI path only fires
+a control under the point: when the hit test finds nothing deeper than the
+application's own frame or window (Chromium page content before its AT-SPI
+tree is populated), no action is fired. Chromium/Electron targets without a
+real focus-free pointer return `background_unavailable` before the capture is
+consumed, so retry the same capture-bound click with
+`delivery_mode:"foreground"` when foreground input is authorized. (`type_text` in the
`background` rung is focus-dependent for non-editable widgets; that's the one
genuine background limitation, and `foreground` is the documented escalation.)
diff --git a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rs b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rs
index 50f7bea440..2b1e192db9 100644
--- a/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rs
+++ b/libs/cua-driver/rust/crates/cua-driver-e2e/tests/standalone_browser_behavior_test.rs
@@ -4336,6 +4336,138 @@ fn run_dialog_background_refusal(spec: &BrowserSpec) {
);
}
+/// Page content under every window pixel: a transparent full-viewport button
+/// that forwards its click to the fixture's journaled increment counter.
+#[cfg(target_os = "linux")]
+fn standalone_full_viewport_click_html() -> String {
+ standalone_fixture_html().replace(
+ "</body>",
+ r#"<button id="pixel-cover" aria-label="pixel-cover"
+ style="position:fixed;inset:0;width:100vw;height:100vh;z-index:2147483647;opacity:0.01;border:0"
+ onclick="document.getElementById('btn-increment').click()">pixel-cover</button>
+</body>"#,
+ )
+}
+
+/// A capture-bound background pixel click on Chromium page content must not
+/// report success without an effect. Chromium's X11 renderer drops focus-free
+/// synthetic input and its AT-SPI hit test at the point resolves only to the
+/// top-level frame, so the canonical Xvfb lanes must return the structured
+/// `background_unavailable` refusal before admission. The refused capture then
+/// stays usable for the explicit foreground escalation, which must land.
+#[cfg(target_os = "linux")]
+fn run_capture_bound_pixel_click_background_refusal(spec: &BrowserSpec) {
+ let scenario = format!(
+ "{}-{}-standalone-capture-bound-pixel-click",
+ std::env::consts::OS,
+ spec.name
+ );
+ let case = CaseSpec::delivered(
+ format!(
+ "{}-{}-standalone-capture-bound-pixel-click-px-background",
+ std::env::consts::OS,
+ spec.name
+ ),
+ spec.name.clone(),
+ "standalone-chromium",
+ "capture_bound_pixel_click",
+ Targeting::Px,
+ Delivery::Background,
+ Scope::Window,
+ DriverRoute::Composite,
+ vec![
+ OracleKind::FixtureState,
+ OracleKind::Focus,
+ OracleKind::ZOrder,
+ OracleKind::NoLeakedInput,
+ ],
+ )
+ .expecting_refusal(vec![RefusalCode::BackgroundUnavailable]);
+ execute_case(case, |evidence| {
+ let mut fixture =
+ launch_browser_with_html(spec, &scenario, standalone_full_viewport_click_html());
+ *evidence = recording_evidence(fixture.driver.recording_dir());
+ wait_for_text(&fixture.server, "lbl-counter", "counter=0");
+ let session = format!("standalone-pixel-click-{}", fixture.pid);
+ let mut click_args = None;
+ let observation = run_with_background_oracles(&mut fixture, |fixture| {
+ let state = fixture.driver.call(
+ "get_window_state",
+ serde_json::json!({
+ "pid": fixture.pid as i64,
+ "window_id": fixture.window_id,
+ "session": session,
+ }),
+ );
+ assert!(!state.is_error(), "window capture: {}", state.raw);
+ let capture_id = state.structured()["capture_id"]
+ .as_str()
+ .unwrap_or_else(|| panic!("window capture has no capture_id: {}", state.raw))
+ .to_owned();
+ let width = state.structured()["screenshot_width"]
+ .as_f64()
+ .expect("capture width");
+ let height = state.structured()["screenshot_height"]
+ .as_f64()
+ .expect("capture height");
+ // Below the browser toolbar, inside the full-viewport button.
+ let args = serde_json::json!({
+ "session": session,
+ "pid": fixture.pid as i64,
+ "window_id": fixture.window_id,
+ "x": (width / 2.0).round(),
+ "y": (height * 0.65).round(),
+ "capture_id": capture_id,
+ "delivery_mode": "background",
+ });
+ let refused = fixture.driver.call("click", args.clone());
+ assert!(
+ refused.is_error(),
+ "background pixel click on Chromium page content reported success \
+ without a refusal: {}",
+ refused.raw
+ );
+ assert_eq!(
+ refused.structured()["code"],
+ "background_unavailable",
+ "{}",
+ refused.raw
+ );
+ assert_eq!(
+ refused.structured()["escalation"]["recommended"],
+ "foreground",
+ "{}",
+ refused.raw
+ );
+ thread::sleep(Duration::from_millis(500));
+ wait_for_text(&fixture.server, "lbl-counter", "counter=0");
+ click_args = Some(args);
+ Observation::refused(
+ RefusalCode::BackgroundUnavailable,
+ vec![OracleKind::FixtureState],
+ refused.text(),
+ Evidence::default(),
+ )
+ });
+ let mut foreground = click_args.expect("background click arguments");
+ foreground["delivery_mode"] = serde_json::Value::String("foreground".to_owned());
+ let landed = fixture.driver.call("click", foreground.clone());
+ assert!(
+ !landed.is_error(),
+ "foreground retry did not reuse the refused capture: {}",
+ landed.raw
+ );
+ wait_for_text(&fixture.server, "lbl-counter", "counter=1");
+ let reused = fixture.driver.call("click", foreground);
+ assert!(
+ reused.is_error(),
+ "a consumed capture was accepted again: {}",
+ reused.raw
+ );
+ observation
+ });
+}
+
fn run_upload(spec: &BrowserSpec) {
let scenario = format!("{}-{}-standalone-upload", std::env::consts::OS, spec.name);
execute_case(case(&spec.name, "browser_file_upload"), |evidence| {
@@ -4865,6 +4997,11 @@ standalone_browser_test!(
standalone_browser_dialog_background_refusal,
run_dialog_background_refusal
);
+#[cfg(target_os = "linux")]
+standalone_browser_test!(
+ standalone_browser_capture_bound_pixel_click_background_refusal,
+ run_capture_bound_pixel_click_background_refusal
+);
standalone_browser_test!(standalone_browser_upload, run_upload);
standalone_browser_test!(standalone_browser_pointer_actions, run_pointer_actions);
standalone_browser_test!(standalone_browser_download, run_download);
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/at_point_policy.rs b/libs/cua-driver/rust/crates/platform-linux/src/at_point_policy.rs
new file mode 100644
index 0000000000..4c61fc5e60
--- /dev/null
+++ b/libs/cua-driver/rust/crates/platform-linux/src/at_point_policy.rs
@@ -0,0 +1,103 @@
+//! Pure routing facts for Linux background pixel clicks.
+//!
+//! Kept free of X11, AT-SPI, and `/proc` I/O so the decisions are unit-tested
+//! on every host, not only on Linux.
+
+/// AT-SPI roles of an application's top-level shell: the application node,
+/// its frames and windows. A pixel hit test that resolves only to one of
+/// these did not find the control under the point. Chromium on Linux is the
+/// common case: until its accessibility tree is populated, the page content
+/// is a bare `frame` whose `doDefault` does nothing. Firing that action and
+/// reporting a click is a false success, so the shell is never an at-point
+/// click target; the caller falls through to its pointer route or refuses.
+pub(crate) fn is_top_level_shell_role(role: &str) -> bool {
+ matches!(
+ role.trim().to_ascii_lowercase().as_str(),
+ "application" | "frame" | "window" | "desktop frame"
+ )
+}
+
+/// Whether one `/proc/<pid>/cmdline` belongs to a Chromium helper process
+/// (renderer, zygote, or GPU process).
+///
+/// The kernel separates arguments with NUL, but Chromium rewrites its own
+/// process title with `setproctitle`, which joins the whole command line
+/// with spaces into a single NUL-terminated string. Matching only
+/// NUL-separated arguments misses every Google Chrome and Chromium helper,
+/// so both separators are accepted.
+pub(crate) fn cmdline_is_chromium_helper(raw: &[u8]) -> bool {
+ String::from_utf8_lossy(raw)
+ .split(|ch: char| ch == '\0' || ch.is_whitespace())
+ .any(|arg| {
+ matches!(
+ arg,
+ "--type=renderer" | "--type=zygote" | "--type=gpu-process"
+ )
+ })
+}
+
+#[cfg(test)]
+mod tests {
+ use super::{cmdline_is_chromium_helper, is_top_level_shell_role};
+
+ #[test]
+ fn application_frames_and_windows_are_never_click_targets() {
+ for role in ["frame", "window", "application", "desktop frame", " Frame "] {
+ assert!(is_top_level_shell_role(role), "{role:?}");
+ }
+ }
+
+ #[test]
+ fn controls_and_documents_remain_click_targets() {
+ for role in [
+ "push button",
+ "button",
+ "link",
+ "check box",
+ "menu item",
+ "document web",
+ "internal frame",
+ "dialog",
+ "panel",
+ ] {
+ assert!(!is_top_level_shell_role(role), "{role:?}");
+ }
+ }
+
+ #[test]
+ fn nul_separated_chromium_helper_is_detected() {
+ assert!(cmdline_is_chromium_helper(
+ b"/usr/lib/chromium/chromium\0--type=renderer\0--lang=en-US\0"
+ ));
+ assert!(cmdline_is_chromium_helper(
+ b"/opt/app/app\0--type=zygote\0--no-zygote-sandbox\0"
+ ));
+ }
+
+ #[test]
+ fn setproctitle_rewritten_chrome_helper_is_detected() {
+ // Google Chrome 151 renderer as `/proc/<pid>/cmdline` shows it after
+ // Chromium's setproctitle: one space-joined string.
+ assert!(cmdline_is_chromium_helper(
+ b"/opt/google/chrome/chrome --type=renderer --crashpad-handler-pid=7960 \
+ --enable-crash-reporter --lang=en-US --num-raster-threads=4\0"
+ ));
+ assert!(cmdline_is_chromium_helper(
+ b"/opt/google/chrome/chrome --type=gpu-process --ozone-platform=x11\0\0\0"
+ ));
+ }
+
+ #[test]
+ fn unrelated_processes_are_not_chromium_helpers() {
+ assert!(!cmdline_is_chromium_helper(
+ b"/usr/bin/gedit\0--new-window\0"
+ ));
+ assert!(!cmdline_is_chromium_helper(
+ b"/usr/bin/python3 tool.py --type=renderer-like\0"
+ ));
+ assert!(!cmdline_is_chromium_helper(
+ b"/usr/lib/webkit2gtk-4.1/WebKitWebProcess 7 12\0"
+ ));
+ assert!(!cmdline_is_chromium_helper(b""));
+ }
+}
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/atspi/cache.rs b/libs/cua-driver/rust/crates/platform-linux/src/atspi/cache.rs
index a0c4d5fec1..5775df1c9d 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/atspi/cache.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/atspi/cache.rs
@@ -168,7 +168,10 @@ pub(crate) fn hit_test(pid: u32, xid: u64, sx: i32, sy: i32) -> Option<(usize, C
.enumerate()
.filter_map(|(pos, (_, e))| {
let (x, y, w, h) = e.bounds?;
- (w > 0 && h > 0).then_some((pos, x, y, w, h, native::is_passive_role(&e.role)))
+ // The application's own frame is never the control under a
+ // point; leave such a hit to the live descent.
+ (w > 0 && h > 0 && !crate::at_point_policy::is_top_level_shell_role(&e.role))
+ .then_some((pos, x, y, w, h, native::is_passive_role(&e.role)))
})
.collect();
let pos = native::select_click_target(&frames, sx, sy)?;
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs b/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs
index 2d6fae1074..90e2e4780e 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/atspi/native.rs
@@ -3188,7 +3188,7 @@ fn at_point_activation_index(
actions: &[String],
is_deepest_hit: bool,
) -> Option<usize> {
- if is_container_role(role) {
+ if is_container_role(role) || crate::at_point_policy::is_top_level_shell_role(role) {
return None;
}
if !is_deepest_hit && role.trim().eq_ignore_ascii_case("canvas") {
@@ -4895,7 +4895,11 @@ pub fn perform_action_at_point(
// children, but the area/role split is what actually disambiguates.
let mut frames: Vec<(usize, i32, i32, u32, u32, bool)> = Vec::new();
for (i, v) in visited.iter().enumerate() {
- if v.actions.is_empty() || !v.has_component || is_container_role(&v.role) {
+ if v.actions.is_empty()
+ || !v.has_component
+ || is_container_role(&v.role)
+ || crate::at_point_policy::is_top_level_shell_role(&v.role)
+ {
continue;
}
let Some(Ok(proxies)) = call(v.acc.proxies()).await else {
@@ -5023,6 +5027,9 @@ pub fn perform_action_at_screen_point(
.await
.0
.into_iter()
+ .filter(|&(idx, ..)| {
+ !crate::at_point_policy::is_top_level_shell_role(&action_nodes[idx].role)
+ })
.map(|(idx, x, y, w, h)| {
(idx, x, y, w, h, is_passive_role(&action_nodes[idx].role))
})
@@ -7077,6 +7084,27 @@ mod at_point_rules_tests {
);
}
+ #[test]
+ fn top_level_frame_default_action_is_never_a_pixel_click() {
+ // Chrome 151 on X11: the hit test over page content resolves only to
+ // `frame "… - Google Chrome"` [doDefault]. Firing it changes nothing,
+ // so it must not be reported as the click, as ancestor or deepest hit.
+ for role in ["frame", "window", "application", "desktop frame"] {
+ for deepest in [false, true] {
+ assert_eq!(
+ at_point_activation_index(role, &acts(&["doDefault"]), deepest),
+ None,
+ "{role} deepest={deepest}"
+ );
+ }
+ }
+ // The page content itself remains actionable once exposed.
+ assert_eq!(
+ at_point_activation_index("push button", &acts(&["doDefault"]), true),
+ Some(0)
+ );
+ }
+
#[test]
fn real_actuators_still_fire_from_any_depth() {
assert_eq!(
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/lib.rs b/libs/cua-driver/rust/crates/platform-linux/src/lib.rs
index 391e19849e..de74ead569 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/lib.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/lib.rs
@@ -72,6 +72,11 @@ pub mod wayland;
// Keeping it un-gated lets the unit tests run on any host.
pub mod terminal;
+// Pure background pixel-click routing facts; un-gated so their unit tests run
+// on every host.
+#[cfg_attr(not(target_os = "linux"), allow(dead_code))]
+mod at_point_policy;
+
#[cfg(target_os = "linux")]
pub mod xauth;
diff --git a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs
index 1785f4063f..d3bdddda73 100644
--- a/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs
+++ b/libs/cua-driver/rust/crates/platform-linux/src/tools/impl_.rs
@@ -2781,12 +2781,9 @@ fn type_text_ax_result(pid: u32, text_len: usize, route: &str) -> ToolResult {
/// own argv. Reads `/proc`; cheap and only invoked on the rare AT-SPI confirm.
fn is_chromium_embedder(pid: u32) -> bool {
fn argv_is_chromium_helper(p: u32) -> bool {
- match fs::read(format!("/proc/{p}/cmdline")) {
- Ok(raw) => String::from_utf8_lossy(&raw).split('\0').any(|arg| {
- arg == "--type=renderer" || arg == "--type=zygote" || arg == "--type=gpu-process"
- }),
- Err(_) => false,
- }
+ fs::read(format!("/proc/{p}/cmdline"))
+ .map(|raw| crate::at_point_policy::cmdline_is_chromium_helper(&raw))
+ .unwrap_or(false)
}
// Single-process / the embedder itself carrying a Chromium switch.
if argv_is_chromium_helper(pid) {
diff --git a/scripts/ci/run-rust-standalone-browser-e2e.sh b/scripts/ci/run-rust-standalone-browser-e2e.sh
index 4fc00ba3ed..ca45817572 100755
--- a/scripts/ci/run-rust-standalone-browser-e2e.sh
+++ b/scripts/ci/run-rust-standalone-browser-e2e.sh
@@ -112,7 +112,10 @@ else
standalone_browser_dialogs
)
if [[ "${HOST_OS}" == Linux ]]; then
- tests+=(standalone_browser_dialog_background_refusal)
+ tests+=(
+ standalone_browser_dialog_background_refusal
+ standalone_browser_capture_bound_pixel_click_background_refusal
+ )
fi
tests+=(
standalone_browser_download