Skip to content

Fix shell metacharacter injection in file-drop path quoting#37

Merged
lassejlv merged 2 commits intopaste-featurefrom
copilot/sub-pr-36
Feb 22, 2026
Merged

Fix shell metacharacter injection in file-drop path quoting#37
lassejlv merged 2 commits intopaste-featurefrom
copilot/sub-pr-36

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 22, 2026

The handle_file_drop path-quoting logic only triggered for paths containing spaces, ', or ", leaving paths with shell metacharacters like $, `, *, !, &, |, ; sent unquoted to the terminal — allowing unintended shell expansion or command injection.

Change

Always apply POSIX single-quote escaping to every dropped path, unconditionally:

// before: only quoted paths containing spaces or quote chars
if path_str.contains(' ') || path_str.contains('\'') || path_str.contains('"') {
    text.push('\'');
    text.push_str(&path_str.replace('\'', "'\\''"));
    text.push('\'');
} else {
    text.push_str(&path_str);  // unsafe for $, `, *, !, &, |, ;
}

// after: always single-quote every path
text.push('\'');
text.push_str(&path_str.replace('\'', "'\\''"));
text.push('\'');

This is both simpler and correct — POSIX single-quoting suppresses all shell metacharacter interpretation, and the '\'' idiom correctly handles embedded single quotes.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: lassejlv <77295879+lassejlv@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for bracketed paste and file drag-and-drop Fix shell metacharacter injection in file-drop path quoting Feb 22, 2026
Copilot AI requested a review from lassejlv February 22, 2026 23:08
Copy link
Copy Markdown
Member

@lassejlv lassejlv left a comment

Choose a reason for hiding this comment

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

Check an extra time if its good enough

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 22, 2026

Check an extra time if its good enough

Checked again — everything looks good:

  • bracketed_paste_mode(): correctly reads TermMode::BRACKETED_PASTE from the alacritty terminal lock.
  • Paste handler: wraps content with \x1b[200~ / \x1b[201~ when bracketed paste is active, falls back to a raw write otherwise — correct per the protocol.
  • File drop handler (fixed in 8eee132): now always applies POSIX single-quote escaping to every path. The '\'' idiom handles embedded single quotes, and wrapping everything in single quotes suppresses all shell metacharacter interpretation ($, `, *, !, &, |, ;).
  • Render pipeline: .on_drop(cx.listener(Self::handle_file_drop)) is correctly wired in.
  • cargo check passes cleanly. CI on paste-feature is green.

Copilot AI requested a review from lassejlv February 22, 2026 23:17
@lassejlv lassejlv marked this pull request as ready for review February 22, 2026 23:19
@lassejlv lassejlv merged commit bbea9d8 into paste-feature Feb 22, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants