Conversation
Resolves clipboard paste issues in PTY SSH sessions by implementing bracketed paste mode support and handling Event::Paste events. Changes: - Enable bracketed paste mode in TerminalStateGuard::new() - Disable bracketed paste mode in restore_terminal_state() - Add Event::Paste handler in handle_input_event() - Increase SmallVec capacity from 8 to 64 bytes for paste content - Update PtyMessage::LocalInput to use SmallVec<[u8; 64]> - Add comprehensive unit tests for paste event handling This fixes paste operations on all platforms (macOS Cmd+V, Linux Ctrl+Shift+V, Windows Ctrl+V) by properly capturing and forwarding pasted content through the SSH channel. Tests: All 455 tests pass, including 8 new paste event tests
Security & Performance ReviewAnalysis Summary
Prioritized Issue ListHIGH (1 issue)H1: Missing paste content size limit - potential memory exhaustion
MEDIUM (3 issues)M1: Empty paste returns Some(empty vec) instead of None
M2: Channel overflow on large paste - silent data drop
M3: Bracketed paste mode not enabled in
LOW (1 issue)L1: Unnecessary memory copy in paste handler
Positive FindingsThe implementation has several good qualities:
Security ConsiderationsPaste content is NOT sanitized for escape sequences in input direction The paste handler sends raw bytes directly to the SSH channel without filtering. This is correct behavior for a terminal emulator - paste content should be transmitted verbatim to the remote shell. The bracketed paste mode ( However, if the remote shell does not support bracketed paste mode, pasted content containing escape sequences could affect the remote terminal. This is a known limitation of terminal emulators and is not specific to this PR. Manual Testing Checklist
SummaryThis PR correctly implements paste support with proper terminal state management. The main concern is H1 (missing size limit) which should be addressed before merge to prevent potential memory exhaustion. The medium and low issues are recommendations for robustness and efficiency improvements. |
- Add 1MB size limit to prevent memory exhaustion attacks (H1 issue) - Return None for empty paste to avoid unnecessary channel sends (M1 issue) - Use from_vec() instead of into_bytes() + from_slice() to avoid double copy (L1 issue) - Add test for paste size limit behavior 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add tests for all Ctrl+key combinations (C, D, Z, A, E, U, K, W, L, R, B, F) - Add tests for arrow keys (Up, Down, Left, Right) - Add tests for all function keys (F1-F12) and verify F13+ returns None - Add tests for special keys (Enter, Tab, Backspace, Esc, Home, End, PageUp, PageDown, Insert, Delete) - Add tests for KeyEventKind::Release and Repeat being ignored - Add tests for modifier keys (Shift accepted, Alt/Meta ignored for chars) - Add tests for Unicode and emoji character input - Add test for mouse events returning None - Add test for Ctrl+char out of range
Summary
This PR fixes clipboard paste operations in PTY mode SSH sessions by implementing bracketed paste mode support and handling
Event::Pasteevents.Fixes #88
Changes
Terminal State Management (
src/pty/terminal.rs)EnableBracketedPasteandDisableBracketedPastefrom crosstermTerminalStateGuard::new()restore_terminal_state()for proper cleanupInput Event Handling (
src/pty/session/input.rs)Event::Paste(text)handler inhandle_input_event()SmallVeccapacity from 8 to 64 bytes to efficiently handle paste contentPTY Message Types (
src/pty/mod.rs)PtyMessage::LocalInputto useSmallVec<[u8; 64]>for consistencyTesting
All 455 tests pass, including 8 new paste event tests:
test_paste_event_small- Small text paste (< 64 bytes)test_paste_event_large- Large text paste (> 64 bytes)test_paste_event_empty- Empty pastetest_paste_event_special_chars- Special characters and newlinestest_paste_event_unicode- Unicode characterstest_paste_event_multiline- Multi-line script pastetest_key_event_still_works- Regular key events still worktest_resize_event_ignored- Resize events still ignoredPlatform Support
This fix enables paste operations on:
Technical Details
SmallVec<[u8; 64]>keeps most paste content stack-allocatedTest Plan