|
| 1 | +Make terminal OSC 52 copy reach the system clipboard |
| 2 | + |
| 3 | +Programs running in the integrated terminal (tmux, vim, Claude Code...) copy by |
| 4 | +emitting OSC 52. xterm's clipboard addon is always loaded and hands the payload |
| 5 | +to IClipboardService.writeText(text, 'clipboard') (see xtermTerminal.ts), but |
| 6 | +BrowserClipboardService files *any* typed write into an in-memory map and never |
| 7 | +touches navigator.clipboard, so on web the copy silently does nothing. |
| 8 | + |
| 9 | +'clipboard' is not an alternate clipboard, it is the system one, so let it fall |
| 10 | +through. 'selection' (OSC 52 's'/'p', the X11 primary selection) keeps the |
| 11 | +in-memory behaviour since browsers have no equivalent. |
| 12 | + |
| 13 | +Only the write path is changed. readText('clipboard') deliberately keeps |
| 14 | +returning the in-memory value, so an OSC 52 read query (ESC]52;c;? BEL) cannot |
| 15 | +be used by a remote program to exfiltrate the user's clipboard back into the |
| 16 | +terminal as input. |
| 17 | + |
| 18 | +This needs a secure context (HTTPS or localhost); without one |
| 19 | +navigator.clipboard is undefined and the execCommand fallback cannot run, |
| 20 | +because OSC 52 arrives asynchronously with no user gesture attached. |
| 21 | + |
| 22 | +To reproduce: open a terminal and run |
| 23 | + printf '\033]52;c;%s\a' "$(printf hello | base64)" |
| 24 | +then paste. Before this patch the clipboard is unchanged. |
| 25 | + |
| 26 | +Fixes the web half of https://github.com/microsoft/vscode/issues/318254 -- drop |
| 27 | +this patch once that lands upstream. |
| 28 | +Index: code-server/lib/vscode/src/vs/platform/clipboard/browser/clipboardService.ts |
| 29 | +=================================================================== |
| 30 | +--- code-server.orig/lib/vscode/src/vs/platform/clipboard/browser/clipboardService.ts |
| 31 | ++++ code-server/lib/vscode/src/vs/platform/clipboard/browser/clipboardService.ts |
| 32 | +@@ -124,8 +124,9 @@ export class BrowserClipboardService ext |
| 33 | + // Clear resources given we are writing text |
| 34 | + this.clearResourcesState(); |
| 35 | + |
| 36 | +- // With type: only in-memory is supported |
| 37 | +- if (type) { |
| 38 | ++ // With type: only in-memory is supported, except for 'clipboard' which |
| 39 | ++ // targets the system clipboard and is handled below. |
| 40 | ++ if (type && type !== 'clipboard') { |
| 41 | + this.mapTextToType.set(type, text); |
| 42 | + this.logService.trace('BrowserClipboardService#writeText'); |
| 43 | + return; |
0 commit comments