Skip to content

fix(coding-agent): handle clipboard helper failures - #1252

Open
sethkarten wants to merge 5 commits into
mainfrom
sethkarten/security-clipboard
Open

fix(coding-agent): handle clipboard helper failures#1252
sethkarten wants to merge 5 commits into
mainfrom
sethkarten/security-clipboard

Conversation

@sethkarten

@sethkarten sethkarten commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • replace shell-string clipboard calls with fixed argument vectors and shell: false, while keeping clipboard text on stdin
  • treat platform helper exit status as authoritative and preserve the Linux fallback order
  • await wl-copy success, detach it from the CLI lifetime, and force a bounded failure result even if a killed child never emits close
  • retain late error handling while preventing post-settlement writes or duplicate completion

Behavior

Clipboard text already traveled through stdin, so this is not an injection fix. The change removes unnecessary shell parsing and fixes lifecycle/error ownership: failed, signaled, or hung Wayland helpers now fall back to X11 or OSC 52 instead of being assumed successful or holding the CLI open.

Validation

  • npx tsx ../../node_modules/vitest/dist/cli.js --run test/clipboard.test.ts from packages/coding-agent — 10 passed
  • npm run check
  • git diff --check

Behavioral coverage includes native and synchronous helper success, fixed argv/stdin X11 fallback, Wayland launch failure, clean success, nonzero exit fallback, child unref ownership, and a timeout that settles without any close event.

Provenance

Extracted from independently authored commits a3ba5dba6e8c280caa20cdca88f057810c35bb1a and 16f5e83cc04bfdb465494f82f0e82006aa829c2c in #1159. Kernel/RLM cancellation remains separate.

Review focus

Please verify fixed argv/stdin data flow, child and timer ownership, late-event safety, and fallback ordering across Wayland, X11, and OSC 52.


Note

Medium Risk
Touches process spawning for clipboard helpers (including auth URL copy). Safer argv/stdin usage, but Wayland copies now wait up to 5s and may fall back more often.

Overview
Stops treating a launched wl-copy as a successful copy. Failed, signaled, or hung Wayland helpers now time out (5s), get killed, and fall back to X11 (xclip/xsel) or OSC 52 instead of holding the CLI open or reporting a false success.

Platform clipboard tools (pbcopy, clip, termux-clipboard-set, xclip, xsel) now run via spawnSync with shell: false and stdin-only payload, and success is based on exit status rather than “did not throw”.

Reviewed by Cursor Bugbot for commit ef97087. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix copyToClipboard to handle unresponsive or failing Wayland clipboard helper

  • copyToWaylandClipboard now spawns wl-copy with shell disabled, writes text via stdin, and waits for a clean exit (code 0, null signal) before reporting success.
  • A 5-second timeout kills the process and resolves false if wl-copy is unresponsive, preventing a silent false-positive.
  • On Wayland, failed wl-copy attempts now fall back to X11 tools (xclip/xsel) or OSC 52, instead of continuing as if the copy succeeded.
  • All platform clipboard tool invocations (pbcopy, clip, termux-clipboard-set, xclip, xsel) are switched from execSync to spawnSync with shell: false and stdin-only input.
  • Behavioral Change: clipboard operations that previously reported success on wl-copy launch (without waiting for completion) will now wait up to 5s and may fall back to X11 or OSC 52.

Macroscope summarized ef97087.

Extracts the clipboard-specific changes from:
- a3ba5db
- 16f5e83

This keeps clipboard process handling independent from kernel/RLM host
cancellation while preserving the original implementation provenance.
Comment thread packages/coding-agent/src/utils/clipboard.ts Outdated
@sethkarten
sethkarten requested a review from Apocrathia August 11, 2026 21:45
@Apocrathia

Copy link
Copy Markdown
Contributor

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 64744d9975

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@Apocrathia Apocrathia left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

no injection to fix here, text always went through stdin. retitle and add a changelog?

Comment thread packages/coding-agent/src/utils/clipboard.ts
Comment thread packages/coding-agent/src/utils/clipboard.ts Outdated

@jonaowen jonaowen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The exact-head change closes both unsafe shell interpolation and the unowned wl-copy lifecycle: fixed argv with shell:false, bounded synchronous fallbacks, async spawn/error/stdin/exit observation, forced timeout kill, and success only after terminal status. The tests gate hostile stdin, async launch failure, nonzero exit, timeout kill, and fallback ordering. I found no blocker at 64744d9975a6e4174f20b8e644b7cecc3cf8478e.

Address PR #1252 review by detaching wl-copy, settling at the timeout even when close never arrives, and retaining late error listeners. Add behavioral coverage for success, child lifetime release, timeout fallback, and stdin-only fallbacks.
@sethkarten sethkarten changed the title fix(security): bound Wayland clipboard fallback fix(coding-agent): handle clipboard helper failures Aug 13, 2026
@sethkarten
sethkarten requested a review from Apocrathia August 13, 2026 23:43

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit ef97087. Configure here.

);
}

function copyToWaylandClipboard(text: string, timeoutMs = 5000): Promise<boolean> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Ceremonial timeout parameter never varies

Low Severity

copyToWaylandClipboard takes timeoutMs with a default of 5000, but its only call site never passes a timeout, so that parameter has a single legal value. That is ceremony rather than configuration.

Fix in Cursor Fix in Web

Triggered by project rule: Review rules

Reviewed by Cursor Bugbot for commit ef97087. Configure here.

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.

4 participants