Skip to content

feat(viewer): paste host clipboard text during human control - #427

Merged
ElbertePlinio merged 5 commits into
mainfrom
feat/366-paste-host-text
Oct 29, 2026
Merged

ElbertePlinio merged 5 commits into
mainfrom
feat/366-paste-host-text

Conversation

@ElbertePlinio

Copy link
Copy Markdown
Member

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-rs 0.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\n or \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-rs 0.9.5 without default features (Rust Wayland backend, so the binary still runs on X11-only hosts) and zeroize. 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-rs and zeroize entries leave Cargo.lock with the revert.

Closes #366

Requirement Verified by Scenario and edge cases Result Evidence
Viewer action, host clipboard read only after it App and live viewer tests, QA Control bar vs watch bar and thumbnail; click without control, after an expired grant, while a read runs or hangs; X11 and headless sway Paste only in the control bar; no read without a live grant; one read at a time app_tests.rs, control_xvfb.rs, 02-control-bar.png, 00-thumbnail.png, 01-watch-bar.png
Typed into the selected session only, including Unicode Live viewer test, QA "Olá ß € ação", tab, trailing line break, CRLF, lone CR Text arrives exactly, trailing break dropped control_xvfb.rs, 03-pasted-unicode.png, clipboard.rs tests
Typing stops if the lease ends App tests, live test, QA Revoke between steps, lease-lost mid-paste, collapse, new lease, late and stale reads Stops within one 32-character step, no key held app_tests.rs, control_xvfb.rs, 09-after-lease-loss-mid-paste.png
Pasted text is never a shortcut Injector test on Xvfb Control held with "a\tb\nc"; Shift held with Tab Plain keys; modifiers held again afterwards inject_xvfb.rs
No logs, evidence or session clipboard Live test, security test, QA Marker string in viewer stdout and stderr, temp home, evidence runs; CLIPBOARD and PRIMARY owners on the session display; paste-shaped host operations Not found anywhere; no owner; operations unknown; evidence keys allowlisted control_xvfb.rs, test/security/security-native-control.test.ts, qa/session-clipboard.txt
Non-text refused, size bounded X11 owner tests, Wayland checks No owner, image/png only, invalid UTF-8, over 4096 characters, 64 KiB property, INCR, silent owner, text/plain only, stopped read Refused with the right note; one bounded request; INCR never started clipboard_xvfb.rs, clipboard_wayland.rs, qa/wayland/result.txt, result-r2.txt, 04-06 screenshots
SECURITY.md and docs Review Protocol, viewer README, README takeover and watch sections Updated SECURITY.md, crates/pickforge-viewer/PROTOCOL.md
Release note Pending Notes for this batch go in one docs change Tracked in #416 this PR

Release 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) with WAYLAND_DISPLAY unset, a temporary PICKFORGE_HOME, a CLI-created session with xterm running cat, and watch; 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:

Delegate Round 1 Round 2 Round 3
GPT-6.1 Sol 6/10 6/10 9/10
Fable 5.1 8/10 8/10 9/10
Kimi K3.1 Pro 5/10 10/10 not run

Round 1 fixed the expired grant check on click, the stop flag for a running read, one read worker at a time, lone \r, the text/plain target 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, because wl-clipboard-rs has 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/.

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.
@ElbertePlinio
ElbertePlinio merged commit ccab319 into main Oct 29, 2026
10 checks passed
@ElbertePlinio
ElbertePlinio deleted the feat/366-paste-host-text branch October 29, 2026 00:07
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.

takeover: paste text from the host during human control

1 participant