Skip to content

The agent that grows with you

fix(bot-screen): Xvnc stops broadcasting the screen clipboard to watchers

teknium1c4b304e7ea8c
diff --git a/tests/tools/test_bot_desktop_launcher_xvnc.py b/tests/tools/test_bot_desktop_launcher_xvnc.py
new file mode 100644
index 00000000000..c2861796c24
--- /dev/null
+++ b/tests/tools/test_bot_desktop_launcher_xvnc.py
@@ -0,0 +1,41 @@
+"""The Bot Desktop's Xvnc is started with the RFB options the lease design relies on."""
+
+from __future__ import annotations
+
+import os
+import shutil
+import subprocess
+from pathlib import Path
+
+import pytest
+
+LAUNCHER = Path(__file__).resolve().parents[2] / "tools" / "bot_desktop" / "launcher.sh"
+pytestmark = pytest.mark.linux_only
+
+
+def test_xvnc_never_sends_the_holders_clipboard_to_watchers(tmp_path):
+ """Whoever holds control may paste INTO the screen (AcceptCutText), but the screen's clipboard must
+ not be pushed to every connected viewer (SendCutText off): watchers are not the holder."""
+ bindir = tmp_path / "bin"
+ bindir.mkdir()
+ argv_log = tmp_path / "xvnc-argv"
+ (bindir / "Xvnc").write_text(f'#!/bin/sh\nprintf "%s\\n" "$@" > "{argv_log}"\nexec sleep 3\n', encoding="utf-8")
+ for stub in ("xdpyinfo", "setxkbmap", "xsetroot", "xset", "dbus-run-session"):
+ (bindir / stub).write_text("#!/bin/sh\nexit 0\n", encoding="utf-8")
+ for exe in bindir.iterdir():
+ exe.chmod(0o755)
+ for tool in ("mkdir", "sed", "cat", "printf", "dirname", "bash", "sh", "rm", "ln", "touch", "chmod", "xauth", "od", "tr", "awk", "seq", "sleep", "kill"):
+ real = shutil.which(tool)
+ if real and not (bindir / tool).exists():
+ (bindir / tool).symlink_to(real)
+ env = {
+ "PATH": str(bindir), "HOME": str(tmp_path),
+ "HERMES_BD_PROFILE": "t", "HERMES_BD_DISPLAY_NUM": "99",
+ "HERMES_BD_SOCKET": str(tmp_path / "rfb.sock"), "HERMES_BD_XAUTH": str(tmp_path / "Xauthority"),
+ "HERMES_BD_ENV_FILE": str(tmp_path / "env"), "HERMES_BD_CONFIG_HOME": str(tmp_path / "xdg"),
+ }
+ subprocess.run(["bash", str(LAUNCHER)], env=env, check=True, stdin=subprocess.DEVNULL, capture_output=True, timeout=30)
+ argv = argv_log.read_text(encoding="utf-8").split("\n")
+ assert "-SendCutText=0" in argv, argv
+ assert not any(a.startswith("-AcceptCutText") for a in argv), "paste into the screen must keep working"
+ assert not os.path.exists(tmp_path / "rfb.sock") # stub never bound it; nothing leaked
diff --git a/tools/bot_desktop/launcher.sh b/tools/bot_desktop/launcher.sh
index 842a2582f53..9eb106b1ed7 100755
--- a/tools/bot_desktop/launcher.sh
+++ b/tools/bot_desktop/launcher.sh
@@ -222,10 +222,13 @@ done
# ---- X server + RFB (TigerVNC Xvnc), Unix socket only ----
# SecurityTypes None is safe ONLY because -rfbport -1 disables TCP and the 0600 socket is reachable
-# solely by the gateway process, whose WebSocket bridge performs the real authentication.
+# only by processes running as this user (the gateway's WebSocket bridge does the real authentication;
+# same-UID processes, the bot's own terminal tool included, are inside that boundary by design).
+# -SendCutText=0: watchers must never receive the holder's clipboard; -AcceptCutText stays on so
+# paste INTO the screen keeps working.
Xvnc "$DISPLAY" -geometry "$GEOM" -depth "$DEPTH" -dpi 96 \
-rfbport -1 -rfbunixpath "$HERMES_BD_SOCKET" -rfbunixmode 0600 \
- -SecurityTypes None -AlwaysShared -AcceptSetDesktopSize -FrameRate 30 \
+ -SecurityTypes None -AlwaysShared -AcceptSetDesktopSize -FrameRate 30 -SendCutText=0 \
-desktop "hermes:$HERMES_BD_PROFILE" -auth "$XAUTHORITY" -nolisten tcp \
-Log '*:stderr:30' &
XVNC_PID=$!