From ab8a852f155eba5144b88c75d983db54833b1977 Mon Sep 17 00:00:00 2001 From: haffel Date: Sat, 12 Sep 2026 12:05:48 +0200 Subject: [PATCH] Reject invalid X11 paste targets --- .agents/CLIPBHOARD_HARDENING_CHECKLIST.md | 5 +++++ src/platform/linux/x11_input.rs | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/.agents/CLIPBHOARD_HARDENING_CHECKLIST.md b/.agents/CLIPBHOARD_HARDENING_CHECKLIST.md index dd7e18a..3fd2a00 100644 --- a/.agents/CLIPBHOARD_HARDENING_CHECKLIST.md +++ b/.agents/CLIPBHOARD_HARDENING_CHECKLIST.md @@ -81,6 +81,9 @@ Each bounded iteration must: ## Build, packaging, and acceptance evidence - [x] Core tests pass: 20 tests observed after storage mutation failure coverage on 2026-09-10. +- [x] X11-feature tests pass: 24 tests, including rejection of `None` and + `PointerRoot` as paste targets (plus Docker GTK/X11/package build, + 2026-09-12). - [x] Rust formatting check passes on 2026-09-10. - [x] X11-only cargo check passes on 2026-09-10. - [x] Full GTK/X11 build passes in the declared Docker environment (Docker build, 2026-09-10). @@ -95,6 +98,8 @@ Each bounded iteration must: packages are still not installed. - Clippy is unavailable in the current Rust toolchain. - No GUI, X11, Cinnamon, or packaging integration tests are present in the tree. +- X11 paste now rejects non-concrete focus values before injecting keystrokes; + real application-target acceptance remains manual evidence. - Diagnostics previously printed a fixed log filename even though the rolling logger creates date-suffixed files; this is now reported as the log directory. - The initial implementation is now committed; future work must keep the tree diff --git a/src/platform/linux/x11_input.rs b/src/platform/linux/x11_input.rs index 82a9bc4..b891bf2 100644 --- a/src/platform/linux/x11_input.rs +++ b/src/platform/linux/x11_input.rs @@ -40,6 +40,7 @@ impl X11Input { } pub fn paste_into(&self, target: xproto::Window) -> Result<()> { + validate_paste_target(target)?; self.connection .set_input_focus(xproto::InputFocus::NONE, target, x11rb::CURRENT_TIME)? .check()?; @@ -92,6 +93,16 @@ impl X11Input { } } +fn validate_paste_target(target: xproto::Window) -> Result<()> { + // X11 uses 0 (None) and 1 (PointerRoot) as special focus values; neither + // identifies a concrete application window that can safely receive paste. + anyhow::ensure!( + target > 1, + "X11 did not provide a concrete paste target window" + ); + Ok(()) +} + fn keycode_for_keysym( connection: &RustConnection, keysym: xproto::Keysym, @@ -111,3 +122,15 @@ fn keycode_for_keysym( } anyhow::bail!("keysym {keysym:#x} is not present in the X11 keyboard mapping") } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn rejects_non_concrete_focus_targets() { + assert!(validate_paste_target(0).is_err()); + assert!(validate_paste_target(1).is_err()); + assert!(validate_paste_target(42).is_ok()); + } +}