Repository navigation
feat(viewer): paste host clipboard text during human control - #427
Merged
Merged
Conversation
The control bar gets a Paste button right of Return control. A click reads the host clipboard once on a worker thread: UTF-8 text only, at most 4096 characters and 16 KiB, within one second. X11 converts CLIPBOARD to UTF8_STRING on an unmapped window and refuses INCR; Wayland uses wl-clipboard-rs data-control. The viewer binds every missing character before typing, then types 32 characters per event loop turn through the takeover injector, so a revoke, expiry, return, collapse, close or session end stops it within one step. The text never crosses stdio and never enters logs, errors, events or evidence. The session clipboard stays empty, and buffers are zeroed. One trailing line break is dropped. Refusals show "Nothing to paste", "Too long to paste" or "Paste unavailable" for 4 s. Closes #366
A Paste click applies a grant that expired since the last loop turn before it reads, so an expired grant never starts a read. A read whose paste stopped asks for no content, and only one read thread runs, so a clipboard that never answers cannot pile up threads. Typed text releases a held Control, Alt or Super for each character, so a paste never triggers a shortcut. A lone trailing carriage return is dropped like a line feed. On Wayland a text/plain offer is read too; its bytes must still be UTF-8.
A Tab or line break in pasted text released no held modifier, so a held Control sent Control+Tab or Control+Return and a held Shift sent Shift+Tab. They now release a held Control, Alt, Super or Shift and press it again afterwards, like the characters do. The docs now say that a Wayland stop during the library's setup can still let the source write into a pipe that the viewer closes unread.
3 tasks done
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.
When a human takes control to log in, the password or 2FA code is often in a password manager on the host. Takeover forwarded pointer and key input, but there was no way to paste.
While the human holds control, the native viewer's control bar now has a Paste button next to Return control. A click reads the host clipboard once and types the text into the session through the viewer's existing XTEST input path, including Unicode. A refused read shows one short note in the status pill: "Nothing to paste" (empty, not text, or control characters), "Too long to paste" (over 4096 characters), or "Paste unavailable". The thumbnail and the watch bar have no Paste, and there is no shortcut, because every key goes to the session during control.
The viewer reads the clipboard itself, so the text never crosses the host channel, and no host operation carries it. On an X11 host the viewer converts CLIPBOARD to UTF8_STRING on its own unmapped window, refuses INCR without starting it, and reads at most 16 KiB within one second. On a Wayland host it uses the data-control protocol through
wl-clipboard-rs0.9.5, with the same bounds; compositors without data-control, such as GNOME, show "Paste unavailable" (#426). The read runs on one worker thread at a time. A click applies a grant that expired since the last loop turn first, a read whose paste stopped starts no further step and its result is dropped, and a read that never answers blocks further reads instead of starting new ones.Typing goes 32 characters per event loop step, and every stroke checks the grant, so a revoke, an expired grant, Return control, collapse, close or session end stops it within one step and leaves no key held. Every missing character is bound before the first stroke, so a paste over the spare keycode budget types nothing. One trailing line break (
\n,\r\nor\r) is dropped, so a copied line does not submit a form. A held Control, Alt or Super is released for each character, Tab and line break, and a held Shift for each Tab and line break, so pasted text never triggers a shortcut.The text never enters logs, errors, protocol events or evidence records. Clipboard errors and the text type print no content, and the clipboard buffers are zeroed on drop; short-lived copies made for typing are not. The viewer owns no selection on the session display, so no session process can read the text from a clipboard. SECURITY.md describes the host display connection, the data-control dependency, the keycodes that stay bound, the copies a core dump can hold, and the Wayland case where a stop during setup lets the source write into a pipe that the viewer closes unread. The browser fallback cannot hold control, so it has no paste.
New Rust dependencies:
wl-clipboard-rs0.9.5 without default features (Rust Wayland backend, so the binary still runs on X11-only hosts) andzeroize. Cargo.lock only gains entries.Rollback: revert this PR. It changes no stored data, no host socket operation and no host protocol command or event, so an older viewer and host keep working together. The
wl-clipboard-rsandzeroizeentries leave Cargo.lock with the revert.Closes #366
app_tests.rs,control_xvfb.rs,02-control-bar.png,00-thumbnail.png,01-watch-bar.pngcontrol_xvfb.rs,03-pasted-unicode.png,clipboard.rstestsapp_tests.rs,control_xvfb.rs,09-after-lease-loss-mid-paste.pnginject_xvfb.rscontrol_xvfb.rs,test/security/security-native-control.test.ts,qa/session-clipboard.txtclipboard_xvfb.rs,clipboard_wayland.rs,qa/wayland/result.txt,result-r2.txt,04-06screenshotsSECURITY.md,crates/pickforge-viewer/PROTOCOL.mdRelease note for the next version: "During human control, the native viewer's Paste button types up to 4096 characters of host clipboard text into the session, without logging it or putting it on the session clipboard. (#366)"
QA ran on a private host Xvfb (
:366) withWAYLAND_DISPLAYunset, a temporaryPICKFORGE_HOME, a CLI-created session with xterm runningcat, andwatch; the Wayland reads ran on a headless sway with a private runtime directory. Scripts, logs and screenshots are in~/.pickforge/investigations/366/.Follow-ups: #426 paste on Wayland compositors without data-control, such as GNOME.
Council review, 3 rounds:
Round 1 fixed the expired grant check on click, the stop flag for a running read, one read worker at a time, lone
\r, thetext/plaintarget and Control held on characters. Round 2 fixed held modifiers on Tab and line breaks and the stop wording. Two residuals stay documented: a read stuck in the Wayland library holds one thread until it returns, becausewl-clipboard-rshas no timeout for its setup, and a stop during that setup can still let the source write into a pipe that the viewer closes unread. A separate note for the keycode limit was declined, so it shares "Paste unavailable". Round 3 had only wording nits, fixed in the last commit. Each code fix has a test that fails on the code before it.Checks on 929d2a5 (the last code change; later commits change comments and docs only):
cargo fmt --check, clippy with-D warnings,PICKFORGE_REQUIRE_XVFB=1 cargo test --workspace --locked(328 passed), and the full vitest coverage run with the desktop, window, wait, browser and viewer requirements on (191 files, 3419 passed, 4 skipped). PickCheck 0.4.0 against main is clean (129 checked). Logs are in~/.pickforge/investigations/366/full/.