Skip to content

Commit 216a193

Browse files
authored
fix(tui): avoid clipboard helper path hijacking (#33)
Verified locally before merge: cargo check -p claurst-tui --no-default-features (known claurst-tui::rustle warning only); rustfmt --edition 2021 --check src-rust/crates/tui/src/image_paste.rs; git diff --check. Follow-up also resolves clipboard read/image paste helpers through trusted absolute paths. Co-authored-by: Nova <nova@openclaw.ai>
1 parent 74d167e commit 216a193

3 files changed

Lines changed: 170 additions & 192 deletions

File tree

src-rust/crates/tui/src/app.rs

Lines changed: 2 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -487,63 +487,10 @@ impl HistorySearch {
487487
}
488488
}
489489

490-
/// Attempt to copy text to the system clipboard using platform CLI tools.
490+
/// Attempt to copy text to the system clipboard using trusted platform clipboard helpers.
491491
/// Returns true if successful.
492492
pub fn try_copy_to_clipboard(text: &str) -> bool {
493-
// Windows
494-
#[cfg(target_os = "windows")]
495-
{
496-
use std::io::Write;
497-
if let Ok(mut child) = std::process::Command::new("clip")
498-
.stdin(std::process::Stdio::piped())
499-
.stdout(std::process::Stdio::null())
500-
.stderr(std::process::Stdio::null())
501-
.spawn()
502-
{
503-
if let Some(mut stdin) = child.stdin.take() {
504-
let _ = stdin.write_all(text.as_bytes());
505-
drop(stdin);
506-
}
507-
return child.wait().map(|s| s.success()).unwrap_or(false);
508-
}
509-
}
510-
// macOS
511-
#[cfg(target_os = "macos")]
512-
{
513-
use std::io::Write;
514-
if let Ok(mut child) = std::process::Command::new("pbcopy")
515-
.stdin(std::process::Stdio::piped())
516-
.spawn()
517-
{
518-
if let Some(stdin) = child.stdin.as_mut() {
519-
let _ = stdin.write_all(text.as_bytes());
520-
}
521-
return child.wait().map(|s| s.success()).unwrap_or(false);
522-
}
523-
}
524-
// Linux / Wayland / X11
525-
#[cfg(target_os = "linux")]
526-
{
527-
use std::io::Write;
528-
for cmd in &["wl-copy", "xclip -selection clipboard", "xsel --clipboard --input"] {
529-
let parts: Vec<&str> = cmd.split_whitespace().collect();
530-
if let Some((prog, args)) = parts.split_first() {
531-
if let Ok(mut child) = std::process::Command::new(prog)
532-
.args(args)
533-
.stdin(std::process::Stdio::piped())
534-
.spawn()
535-
{
536-
if let Some(stdin) = child.stdin.as_mut() {
537-
let _ = stdin.write_all(text.as_bytes());
538-
}
539-
if child.wait().map(|s| s.success()).unwrap_or(false) {
540-
return true;
541-
}
542-
}
543-
}
544-
}
545-
}
546-
false
493+
crate::image_paste::write_clipboard_text(text)
547494
}
548495

549496
/// Map a character to its QWERTY Latin keyboard-position equivalent.

0 commit comments

Comments
 (0)