fix(tui): avoid clipboard helper path hijacking#33
Open
BunsDev wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
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_clipboardandtry_copy_to_clipboardthroughcrate::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.rsandapp.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()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
pbcopy,xclip,powershell) which can be hijacked by attacker-controlled current-directory/PATH entries.Description
copy_to_clipboardandtry_copy_to_clipboardcallcrate::image_paste::write_clipboard_textinstead of spawning bare helpers.crates/tui/src/image_paste.rs:trusted_command_path(checks fixed system locations like/usr/binand/usr/local/bin) andtrusted_windows_powershell(resolves PowerShell underSystemRoot), and use those resolved paths when invoking external helpers.Command::new("pbcopy"|"xclip"|"xsel"|"wl-paste"|"powershell")calls with invocations that prefer resolved, trusted absolute paths and skip helpers if none are found.std::io::Writeimport inmessage_copy.rsand update related call sites inapp.rsto use the centralized helper.Testing
cargo check -p claurst-tui --no-default-featureswhich completed successfully with one unrelated warning inrustle.rs.git diff --check(no new issues introduced by this patch).cargo check --workspaceis blocked by missing system ALSA pkg-config dependency in the environment and could not be completed here.cargo clippy/cargo fmt --all --checkcould not be fully validated due to existing repo-wide issues unrelated to this change.Codex Task