Skip to content

macos: defer OSC52 clipboard read confirmations until focused - #13744

Merged
mitchellh merged 1 commit into
mainfrom
macos-osc52
Aug 11, 2026
Merged

mitchellh merged 1 commit into
mainfrom
macos-osc52

Conversation

@mitchellh

Copy link
Copy Markdown
Contributor

Fixes #10077

Clipboard read confirmations would immediately show a sheet which grabbed focus. This could be used for a bunch of dumb reasons, including DoS attacks. But, it also caused focus/sheet loops for programs that did OSC52 on focus changes (which was seen via some Neovim configs!).

Now, if a surface is unfocused, we bell the surface and show the confirmation request on next focus. If the surface is not focused or another request comes in, we cancel the prior one.

This also fixes some memory management issues around clipboard requests that were likely small leaks (didn't verify the old bug, but verified the new code, and eyeballed the old).

To implement this, I decided to reorient the whole clipboard confirmation thing around state on SurfaceView (which simplifies memory management) and using Combine on BaseTerminalController to get notified.

@mitchellh mitchellh added this to the 1.4.0 milestone Aug 11, 2026
@mitchellh
mitchellh requested a review from a team as a code owner August 11, 2026 03:48
@ghostty-bot ghostty-bot Bot added the os/macos label Aug 11, 2026

@bo2themax bo2themax 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.

I'm thinking we can move the confirmation to an overlay of the surface, so we don't need to check them in the window controller. But I haven't tried it yet, will open a follow up pr if it works better.

@bo2themax bo2themax 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.

I tried a script that repeated request clipboard write/read, it still steals focus from another tab

Screen.Recording.2026-08-11.at.2.31.49.PM.Fast.1080p30.mp4

@mitchellh

Copy link
Copy Markdown
Contributor Author

Oh strange, I had a similar script and it did not. let me try again.

@mitchellh

Copy link
Copy Markdown
Contributor Author

Oh its because this only protected OSC52 read, but we should probably just do this for all clipboard ops that require confirmation. I started with OSC52 due to the linked discussion.

Fixes #10077

Clipboard read confirmations would immediately show a sheet which
grabbed focus. This could be used for a bunch of dumb reasons, including 
DoS attacks. But, it also caused focus/sheet loops for programs that did
OSC52 on focus changes (which was seen via some Neovim configs!).

Now, if a surface is unfocused, we bell the surface and show the confirmation
request on next focus. If the surface is not focused or another request
comes in, we cancel the prior one.

This also fixes some memory management issues around clipboard requests
that were likely small leaks (didn't verify the old bug, but verified
the new code, and eyeballed the old).
@mitchellh

Copy link
Copy Markdown
Contributor Author

Fixed, pushed.

@mitchellh
mitchellh requested a review from bo2themax August 11, 2026 13:44
@mitchellh
mitchellh merged commit 046b8fc into main Aug 11, 2026
192 checks passed
@mitchellh
mitchellh deleted the macos-osc52 branch August 11, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants