fix(desktop): grant clipboard permissions in preview browser#3739
fix(desktop): grant clipboard permissions in preview browser#3739nsxdavid wants to merge 3 commits into
Conversation
The preview browser session allowed "clipboard-write", but the Chromium permission actually requested by navigator.clipboard.writeText is "clipboard-sanitized-write", so clipboard writes from previewed pages were silently denied. Electron also consults the synchronous permission check handler for clipboard APIs, and none was installed. Add "clipboard-sanitized-write" to the request allowlist and install a matching permission check handler.
Add setPermissionCheckHandler to the mocked Electron session so getSession paths keep working, and assert both permission handlers grant clipboard access and deny unrelated permissions.
…tants Share one base allowlist between the request and check handlers, with the legacy "clipboard-write" name added only where the request handler can receive it, so the intentional difference between the two lists is explicit. Set lookup also avoids rebuilding an array on every permission check, which Chromium invokes synchronously.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
ApprovabilityVerdict: Needs human review This change modifies permission handling for the preview browser, granting clipboard permissions to previewed content. Permission-related changes are security-adjacent and warrant human review, especially from someone familiar with the preview browser security model. You can customize Macroscope's approvability policy. Learn more. |
Fixes #3738
What Changed
Why
The preview browser's permission handler allows "clipboard-write", but the permission Chromium actually requests for navigator.clipboard.writeText() is "clipboard-sanitized-write". The grant never matches, and since Electron shows no permission prompts, every clipboard write from a previewed page is silently denied. Copy buttons in previewed apps fail with:
The same pages work in Chrome, which prompts the user and remembers the grant.
Validation
Checklist
Note
Low Risk
Scoped to desktop preview session permission handlers; no auth or data-path changes, with unit test coverage for grant/deny behavior.
Overview
Fixes preview pages where
navigator.clipboard.writeText()was denied because Chromium requestsclipboard-sanitized-write, while the preview Electron session only allowed the legacyclipboard-writename on the async request handler.BrowserSessionnow centralizes permission allowlists and registers bothsetPermissionRequestHandler(includes legacyclipboard-write) and a newsetPermissionCheckHandler(the sync path Electron uses for clipboard APIs), grantingclipboard-read,clipboard-sanitized-write, plus existingnotifications/geolocation, while denying unrelated permissions. Tests assert both handlers grant clipboard permissions and reject others.Reviewed by Cursor Bugbot for commit 3063928. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Grant clipboard permissions in the preview browser session
PERMISSION_REQUEST_ALLOWLISTandPERMISSION_CHECK_ALLOWLISTconstants inBrowserSession.tsto centralize permission decisions.setPermissionCheckHandleron sessions created viaBrowserSession.make, allowingclipboard-read,clipboard-sanitized-write,notifications, andgeolocation.clipboard-writeis allowed on permission requests but not on permission checks; all other permissions (e.g.midi) are denied in both handlers.Macroscope summarized 3063928.