Skip to content

Clipboard: host image bridge for SELinux and SSH, fix text copy/paste regression - #93

Merged
guimou merged 2 commits into
mainfrom
clipboard-selinux-bridge
Nov 19, 2026
Merged

guimou merged 2 commits into
mainfrom
clipboard-selinux-bridge

Conversation

@guimou

@guimou guimou commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

Problem

Follow-up to #92, which did not make image pasting work and broke text select/copy and middle-click paste in containers.

  • With SELinux enforcing, a confined container is denied any connection to the Wayland compositor (or X server). The mounted display socket is dead: wl-paste / wl-copy fail with Permission denied. On a permissive host the same connection is only logged, which is why it worked there.
  • ccbox: fall back to wayland-0 socket and warn when clipboard is unwirable #92 made the launcher export WAYLAND_DISPLAY even from shells that lacked it (Herdr, SSH). Claude Code switches from the terminal clipboard (OSC 52) to wl-copy / wl-paste as soon as that variable is set, and those fail.

Changes

  • No dead socket: when SELinux is enforcing, the display socket is no longer mounted. Permissive and non-SELinux hosts keep the direct socket.
  • Host bridge: the launcher starts a small helper on the host; a shim mounted as /usr/local/bin/wl-paste and /usr/local/bin/wl-copy asks it through a FIFO and files in a per-session directory ($XDG_RUNTIME_DIR/codebox-clipboard/<container>, removed with the session). The container gets no display access; WAYLAND_DISPLAY is set to a name that is not a socket, only so harnesses use the two commands. It carries:
    • clipboard images (CTRL+V), read-only;
    • the selection: text selected in the harness is written to the host clipboard and primary selection, and the primary selection can be read back (middle-click paste, which Claude Code's fullscreen mode does with wl-paste --primary);
    • not the text of the regular clipboard: refused.
    • Files exchanged with the container are never opened through a link it could plant (answers are renamed in, copy text is read with O_NOFOLLOW).
  • Images over SSH: the helper first asks a clipboard socket forwarded over SSH from the machine the user is typing on, then falls back to the host's own wl-paste / xclip. The source is chosen per paste. integrations/clipboard-ssh/ holds the server for the local machine (script + systemd user socket-activated units).
  • Docs: docs/usage.md Clipboard Support updated, new "Pasting Images over SSH" section (server install, RemoteForward, StreamLocalBindUnlink); AGENTS.md.

Tests

  • New golden scenarios clipboard-wayland and clipboard-selinux; existing goldens unchanged.
  • New tests/clipboard-bridge-test.sh: shim → helper → forwarded socket → server against stub clipboards, selection copy and primary read, clipboard-text refusal, malformed requests, planted symlinks, fallback after disconnect. Added to CI along with shellcheck for the new scripts.

Verification

Verified by hand on an SELinux-enforcing Wayland laptop, local session inside Herdr: select + middle-click paste, and CTRL+V of an image.

Not verified yet: the SSH path end to end (forwarded socket, RemoteForward honoured by the terminal's SSH connections). It is only covered by the stub-based test.

Host requirements: wl-clipboard (or xclip) for the local source, python3 for the SSH source. No image rebuild is needed.

🤖 Generated with Claude Code

guimou and others added 2 commits November 19, 2026 10:54
…display socket

With SELinux enforcing, a confined container is denied any connection to the
Wayland compositor or X server: the mounted display socket is dead. Since
PR #92 exports WAYLAND_DISPLAY even from shells that lacked it, harnesses
switched from the terminal clipboard (OSC 52) to wl-copy/wl-paste, which
fail: image pasting still did not work, and text select/copy and
middle-click paste broke.

- add_clipboard_mounts() no longer mounts the display socket or exports
  WAYLAND_DISPLAY/DISPLAY when SELinux is enforcing (selinux_enforcing):
  text goes through the terminal again. Permissive and non-SELinux hosts
  keep the direct socket.
- Clipboard image bridge (clipboard_bridge_*): a host helper started by the
  launcher answers requests from a wl-paste shim mounted in the container,
  through a FIFO and files in a per-session directory under
  $XDG_RUNTIME_DIR. Image types only; the container gets no display access.
- The helper asks an SSH-forwarded clipboard socket first
  ($XDG_RUNTIME_DIR/codebox-clipboard-ssh.sock), then the host's own
  wl-paste/xclip, chosen per paste, so sessions used over SSH paste the
  images of the machine the user is typing on. integrations/clipboard-ssh/
  holds the server for that machine (script + systemd user socket units).
- tests: clipboard-wayland / clipboard-selinux golden scenarios, and
  tests/clipboard-bridge-test.sh (shim -> helper -> socket -> server
  against stub clipboards), run in CI.
- docs: usage.md Clipboard Support, new "Pasting Images over SSH" section;
  AGENTS.md.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Select + middle-click paste did not work through the bridge. In fullscreen
mode Claude Code handles the middle click itself by running
`wl-paste --primary`, and publishes its own selection with `wl-copy` /
`wl-copy --primary` when WAYLAND_DISPLAY is set; none of that could reach
the host, and the shim refused it.

- The shim is now also mounted as /usr/local/bin/wl-copy, and
  WAYLAND_DISPLAY is set to a name that is not a socket so harnesses use
  the two commands.
- New requests: "copy clipboard|primary" (text selected in the harness,
  written to the host selections and kept as the session's last selection)
  and "primary" (host primary selection, else that last selection).
- The text to copy is read with O_NOFOLLOW: a link planted by the
  container would otherwise let it read a host file back through the
  primary selection.
- Reading the regular clipboard as text is still refused. Selection text
  never uses the SSH-forwarded socket (images only).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@guimou
guimou merged commit aa4bce5 into main Nov 19, 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.

1 participant