Repository navigation
Conversation
In a plugin frame, navigator.clipboard only had readText and writeText, so SSH Terminal's Image > Paste image found no read() and did nothing. The frame's clipboard now has read(): like readText, the shell reads the clipboard only right after a click in that frame, and it hands back only pictures and plain text. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
AI review | Looks safe to merge Adds clipboard image reading to plugin frames by proxying through the shell, filtering to plain text and images, and enforcing recent user activation. No security or stability risks found. Reviewed c09840a. AI can be wrong, a maintainer still decides. Comment |
|
Tested on Windows desktop: it works. Setup:
Not tested: full |
ZacharyZcR
left a comment
There was a problem hiding this comment.
Looks good. It keeps the shell's recently-used check, hands over only pictures and plain text (never HTML), and adds a hostile-suite probe. I agree that adding clipboard-read to the frame's allow would be the weaker fix.
Fixes #1951
Thanks to @pinkfloydFR for the report and for narrowing it down to the plugin frames.
Problem
In a plugin frame, Image > Paste image in SSH Terminal's toolbar does nothing. Cmd+V with the same picture works, and so do dropping it and Image > Upload image.
The menu item reads the clipboard with
navigator.clipboard.read()(handleClipboardImagein SSH Terminal'sTerminal.tsx). In a frame,navigator.clipboardis core's stand-in fromsrc/ui/plugin-frame/shims.ts, which has onlyreadTextandwriteText. With noread, SSH Terminal shows "This browser cannot read images from the clipboard". That toast doesn't show from a frame either, so the button looks dead. Cmd+V works because the picture comes with the paste event, and nothing has to read the clipboard.It's the same on 26.11.2, 26.11.3 and
dev-26.11.4.Change
frame-connection.ts): a new frame call,clipboard.readItems.clipboard.read: it works only right after the person used that frame (recentlyUsed: the frame's own pointer or key event in the last 5 s, and the shell window's user activation).navigator.clipboard.read()and, for each item, hands back onlyimage/*andtext/plain, as Blobs.text/html, stay in the shell. HTML can hold more than the person copied and sees, such as hidden markup, source links or local file paths.shims.ts,frame-boot.tsx): the clipboard stand-in getsread(), which asks the shell for those items.ClipboardItems where the frame has the constructor, and a small stand-in withtypesandgetTypewhere it doesn't.clipboard.read(readText) andclipboard.writedon't change. Writing is still text only.shell.clipboard-read-items: callingclipboard.readItemswith no click must be refused.src/ui/tests/plugin-frame/shims.test.ts(3 tests), andframe-connection.test.tscovers the new call:PLUGIN-GUIDE.mdon whatnavigator.clipboardhas in a frame.#1951 suggests adding
clipboard-readto the frames'allow(FRAME_ALLOWinframe-allow.ts). On its own that wouldn't bring the button back, because the frame'snavigator.clipboardis still the stand-in with noread(). It would also change what a frame can do by itself: today, leaving that permission out is what stops a plugin frame from calling the browser's own clipboard read. With it, a frame could read the whole clipboard, HTML included, whenever it has focus, without the shell's check that the person just used that frame. So this keepsallowas it is and has the shell do the read.Testing
npm run format:check,npm run lintandnpm run type-checkpass.vitest run --project frontend --project scripts: 287 files, 2039 tests pass. The 4 new tests fail without the fix:navigator.clipboard.read is not a functionin the frame, and no answer toclipboard.readItemsfrom the shell.node scripts/hostile/run.mjs --local --only clipboard(built backend,npm run hostile:ui, Classic Layout and Themes staged):shell.clipboard-read,shell.clipboard-read-itemsandshell.clipboard-writeall refused, 3 passed, 0 failed.dev-26.11.4(b4a75bd) twice, without and with this change, and ran it in web mode with the bundled standard plugins. SSH Terminal 1.5.0 as bundled answers every upload with 503 (Image paste and drop fail under the 26.11.2 plugin sandbox: sharp can't load (503 IMAGE_PROCESSING_UNAVAILABLE) Plugin-SSH-Terminal#98), so in both builds I swapped in SSH Terminal from fix: convert pasted and dropped images without sharp Plugin-SSH-Terminal#104. It was connected to a small ssh2 server on 127.0.0.1 with a fake shell. The test put a PNG on the clipboard and clicked Image > Paste image with real clicks:typeof navigator.clipboard.readin SSH Terminal's terminal frameundefinedfunctionPOST /plugin-api/ssh-terminal/image-uploadwith the clipboard's PNG,200. The PNG (64×48) is written to the host over SFTP and its path is typed at the promptread()in the terminal frame with no click in the last 5 sread()in SSH Terminal's other frame (the tab bar's Tools button) right after a click in the terminal frametext/html,text/plainandimage/png, read right after a click in the frameClipboardItemwithtext/plainandimage/png.getType("text/html")rejects withNotFoundErrornavigator.clipboard.read()returns (same SHA-256, 257 bytes). Chromium re-encodes a clipboard picture when it is read, which is why both differ from the 264-byte PNG the test wrote.clipboard-read(CLIPBOARD_PERMISSIONSinelectron/main.cjs). The picture lands on the host and its path is typed. Not tested in Firefox or on Windows.🤖 Generated with Claude Code