Repository navigation
fix(desktop): require user consent for preview actions #37866
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1ab13ce
c1b9ba3
e1ed9a7
cc5a9c8
37fe132
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,6 @@ export type BrowserSessionPartitionNamespace = "profile"; | |
| // Electron's clipboard API uses clipboard-sanitized-write and checks both permission handlers. | ||
| const ALLOWED_PREVIEW_PERMISSIONS: ReadonlySet<string> = new Set([ | ||
| "clipboard-sanitized-write", | ||
| "geolocation", | ||
| // DesktopWindow confines HTML fullscreen to the guest's webview. | ||
| "fullscreen", | ||
| "pointerLock", | ||
|
|
@@ -301,7 +300,7 @@ export const make = Effect.gen(function* BrowserSessionMake() { | |
| message: prompt.message, | ||
| ...(prompt.detail === undefined ? {} : { detail: prompt.detail }), | ||
| }, | ||
| previewHostWindow(requester), | ||
| platform === "win32" ? undefined : previewHostWindow(requester), | ||
| ) | ||
| .pipe( | ||
| Effect.map(({ response }): boolean | undefined => response === 0), | ||
|
|
@@ -607,19 +606,25 @@ export const make = Effect.gen(function* BrowserSessionMake() { | |
| return Effect.try({ | ||
| try: () => { | ||
| const browserSession = session.fromPartition(partition); | ||
| // Like Chrome, clipboard reads ask once per origin; both answers last for the session. | ||
| const clipboardReadDecisions = new Map<string, boolean>(); | ||
| const confirmClipboardRead = ( | ||
| // Location and clipboard decisions are remembered separately for each origin. | ||
| const permissionDecisions = { | ||
| "clipboard-read": new Map<string, boolean>(), | ||
| geolocation: new Map<string, boolean>(), | ||
| }; | ||
| const confirmOriginPermission = ( | ||
| requester: WebContents, | ||
| permission: keyof typeof permissionDecisions, | ||
| rawUrl: string | undefined, | ||
| callback: (granted: boolean) => void, | ||
| ): void => { | ||
| const origin = permissionOrigin(rawUrl); | ||
| if (origin === null) { | ||
| // A frame URL such as about:srcdoc cannot establish whether its origin is inherited or opaque. | ||
| callback(false); | ||
| return; | ||
| } | ||
| const remembered = clipboardReadDecisions.get(origin); | ||
| const decisions = permissionDecisions[permission]; | ||
| const remembered = decisions.get(origin); | ||
| if (remembered !== undefined) { | ||
| callback(remembered); | ||
| return; | ||
|
|
@@ -631,12 +636,17 @@ export const make = Effect.gen(function* BrowserSessionMake() { | |
| m(msg("Allow", { $context: "button, grants a site permission" })), | ||
| m(msg("Block", { $context: "button, denies a site permission" })), | ||
| ], | ||
| message: m(msg("{origin} wants to see text and images copied to the clipboard"), { | ||
| origin: truncateForPrompt(origin), | ||
| }), | ||
| message: | ||
| permission === "geolocation" | ||
| ? m(msg("{origin} wants to know your location"), { | ||
| origin: truncateForPrompt(origin), | ||
| }) | ||
| : m(msg("{origin} wants to see text and images copied to the clipboard"), { | ||
| origin: truncateForPrompt(origin), | ||
| }), | ||
| }, | ||
| (answer) => { | ||
| if (answer !== undefined) clipboardReadDecisions.set(origin, answer); | ||
| if (answer !== undefined) decisions.set(origin, answer); | ||
| callback(answer === true); | ||
| }, | ||
| ); | ||
|
|
@@ -652,9 +662,10 @@ export const make = Effect.gen(function* BrowserSessionMake() { | |
| ); | ||
| return; | ||
| } | ||
| if (permission === "clipboard-read") { | ||
| confirmClipboardRead( | ||
| if (permission === "clipboard-read" || permission === "geolocation") { | ||
| confirmOriginPermission( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Geolocation prompt on Windows can block mouse input. On Windows, Apply the same Windows owner exception to the permission prompt, or otherwise confirm that the owner is safe on Windows. Because
|
||
| webContents, | ||
| permission, | ||
| "requestingUrl" in details ? details.requestingUrl : undefined, | ||
| callback, | ||
| ); | ||
|
|
@@ -664,8 +675,9 @@ export const make = Effect.gen(function* BrowserSessionMake() { | |
| }, | ||
| ); | ||
| browserSession.setPermissionCheckHandler((_webContents, permission, requestingOrigin) => | ||
| permission === "clipboard-read" | ||
| ? clipboardReadDecisions.get(permissionOrigin(requestingOrigin) ?? "") === true | ||
| permission === "clipboard-read" || permission === "geolocation" | ||
| ? permissionDecisions[permission].get(permissionOrigin(requestingOrigin) ?? "") === | ||
| true | ||
| : ALLOWED_PREVIEW_PERMISSIONS.has(permission), | ||
| ); | ||
| browserSession.webRequest.onBeforeSendHeaders( | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.