Skip to content

fix: let plugin frames read pictures from the clipboard - #1954

Open
Li-Lee wants to merge 1 commit into
Termix-SSH:dev-26.11.4from
Li-Lee:fix/frame-clipboard-read-images
Open

Li-Lee wants to merge 1 commit into
Termix-SSH:dev-26.11.4from
Li-Lee:fix/frame-clipboard-read-images

Conversation

@Li-Lee

@Li-Lee Li-Lee commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

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() (handleClipboardImage in SSH Terminal's Terminal.tsx). In a frame, navigator.clipboard is core's stand-in from src/ui/plugin-frame/shims.ts, which has only readText and writeText. With no read, 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

  • Shell (frame-connection.ts): a new frame call, clipboard.readItems.
    • It has the same rule as 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).
    • It calls navigator.clipboard.read() and, for each item, hands back only image/* and text/plain, as Blobs.
    • Other types, like 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.
  • Frame (shims.ts, frame-boot.tsx): the clipboard stand-in gets read(), which asks the shell for those items.
    • It returns real ClipboardItems where the frame has the constructor, and a small stand-in with types and getType where it doesn't.
    • Anything that isn't a Blob is dropped.
  • clipboard.read (readText) and clipboard.write don't change. Writing is still text only.
  • No new permission or capability. A frame could already read the clipboard's text right after a click; now it can also read pictures, under the same rule.
  • Hostile suite: a new probe, shell.clipboard-read-items: calling clipboard.readItems with no click must be refused.
  • Tests: new src/ui/tests/plugin-frame/shims.test.ts (3 tests), and frame-connection.test.ts covers the new call:
    • refused out of the blue,
    • refused after a click the frame only claims,
    • after a click it hands back the picture and plain text, and never reads the HTML.
  • A CHANGELOG line under 26.11.4, Fixed, and one line in PLUGIN-GUIDE.md on what navigator.clipboard has in a frame.

#1951 suggests adding clipboard-read to the frames' allow (FRAME_ALLOW in frame-allow.ts). On its own that wouldn't bring the button back, because the frame's navigator.clipboard is still the stand-in with no read(). 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 keeps allow as it is and has the shell do the read.

Testing

  • npm run format:check, npm run lint and npm run type-check pass.
  • 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 function in the frame, and no answer to clipboard.readItems from 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-items and shell.clipboard-write all refused, 3 passed, 0 failed.
  • End to end in Chromium (Playwright's headless shell, which keeps its own clipboard). I built 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:
Check b4a75bd This branch
typeof navigator.clipboard.read in SSH Terminal's terminal frame undefined function
Image > Paste image Nothing is sent POST /plugin-api/ssh-terminal/image-upload with the clipboard's PNG, 200. The PNG (64×48) is written to the host over SFTP and its path is typed at the prompt
read() in the terminal frame with no click in the last 5 s Rejected, "Not allowed now"
read() in SSH Terminal's other frame (the tab bar's Tools button) right after a click in the terminal frame Rejected, "Not allowed now"
Clipboard holding text/html, text/plain and image/png, read right after a click in the frame A ClipboardItem with text/plain and image/png. getType("text/html") rejects with NotFoundError
  • The PNG in the upload request is byte for byte what the shell's own navigator.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.
  • By hand, with the change backported to 26.11.2: Image > Paste image works in Chrome and Safari against a server, and in the macOS desktop app, whose main window already grants clipboard-read (CLIPBOARD_PERMISSIONS in electron/main.cjs). The picture lands on the host and its path is typed. Not tested in Firefox or on Windows.

🤖 Generated with Claude Code

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>
@termix-triage-bot

Copy link
Copy Markdown

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 /termix review to run it again.

@pinkfloydFR

Copy link
Copy Markdown

Tested on Windows desktop: it works.

Setup: v26.11.3 plus c09840a (only CHANGELOG.md conflicted), UI and frame rebuilt and put into a separate copy of the 26.11.3 Windows 11 x64 install (own data folder). I had to turn off the asar integrity fuse in the copy's Termix.exe, otherwise it crashes at start. SSH Terminal is the build of Plugin-SSH-Terminal#104.

Not tested: full dev-26.11.4, Ctrl+V with the change, macOS, Linux, web.

@ZacharyZcR ZacharyZcR left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Open PRs

Development

Successfully merging this pull request may close these issues.

3 participants