Skip to content

fix(tui): avoid clipboard helper path hijacking#33

Open
BunsDev wants to merge 1 commit into
mainfrom
codex/fix-clipboard-copy-executable-hijacking-vulnerability
Open

fix(tui): avoid clipboard helper path hijacking#33
BunsDev wants to merge 1 commit into
mainfrom
codex/fix-clipboard-copy-executable-hijacking-vulnerability

Conversation

@BunsDev
Copy link
Copy Markdown
Member

@BunsDev BunsDev commented Jun 3, 2026

Motivation

  • Close a local code-execution vector where clipboard helpers were spawned by unqualified executable names (e.g. pbcopy, xclip, powershell) which can be hijacked by attacker-controlled current-directory/PATH entries.

Description

  • Route all TUI copy paths to the shared clipboard writer by making copy_to_clipboard and try_copy_to_clipboard call crate::image_paste::write_clipboard_text instead of spawning bare helpers.
  • Add resolver helpers in crates/tui/src/image_paste.rs: trusted_command_path (checks fixed system locations like /usr/bin and /usr/local/bin) and trusted_windows_powershell (resolves PowerShell under SystemRoot), and use those resolved paths when invoking external helpers.
  • Replace direct Command::new("pbcopy"|"xclip"|"xsel"|"wl-paste"|"powershell") calls with invocations that prefer resolved, trusted absolute paths and skip helpers if none are found.
  • Small cleanup: remove unused std::io::Write import in message_copy.rs and update related call sites in app.rs to use the centralized helper.

Testing

  • Ran cargo check -p claurst-tui --no-default-features which completed successfully with one unrelated warning in rustle.rs.
  • Ran git diff --check (no new issues introduced by this patch).
  • cargo check --workspace is blocked by missing system ALSA pkg-config dependency in the environment and could not be completed here.
  • cargo clippy / cargo fmt --all --check could not be fully validated due to existing repo-wide issues unrelated to this change.

Codex Task

Copilot AI review requested due to automatic review settings June 3, 2026 11:51
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the TUI’s clipboard integration against local executable-path hijacking by centralizing clipboard text writes and resolving clipboard helper executables via trusted absolute paths rather than relying on unqualified names.

Changes:

  • Centralize “copy text to clipboard” behavior by routing copy_to_clipboard and try_copy_to_clipboard through crate::image_paste::write_clipboard_text.
  • Add trusted helper resolution in image_paste.rs (fixed-location lookup on Unix; SystemRoot-based resolution for Windows PowerShell) and use it for clipboard write subprocesses.
  • Remove now-unneeded per-callsite clipboard spawning logic/imports in message_copy.rs and app.rs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src-rust/crates/tui/src/message_copy.rs Removes ad-hoc clipboard spawning and routes copy through the shared clipboard writer.
src-rust/crates/tui/src/image_paste.rs Introduces trusted helper resolution and applies it to clipboard text writing helpers.
src-rust/crates/tui/src/app.rs Simplifies clipboard copy helper to call the centralized trusted clipboard writer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// Windows: PowerShell Get-Clipboard

use std::path::PathBuf;
use std::path::{Path, PathBuf};
Comment on lines +16 to +19
#[cfg(not(target_os = "windows"))]
fn trusted_command_path(paths: &[&'static str]) -> Option<&'static str> {
paths.iter().copied().find(|path| Path::new(path).is_file())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants