From 4f65b914448897ecb5b5ca29003b469c54668504 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Sun, 28 Jun 2020 12:12:38 +0200 Subject: [PATCH] electron - disable remote module in all windows (#101224) --- src/vs/code/electron-main/app.ts | 6 +++++- src/vs/code/electron-main/auth.ts | 2 +- src/vs/code/electron-main/sharedProcess.ts | 1 + src/vs/code/electron-main/window.ts | 4 +--- src/vs/platform/driver/electron-browser/driver.ts | 6 ++---- src/vs/platform/electron/common/electron.ts | 1 + .../platform/electron/electron-main/electronMainService.ts | 7 +++++++ src/vs/platform/issue/electron-main/issueMainService.ts | 2 ++ .../browser/suggestEnabledInput/suggestEnabledInput.ts | 1 - .../test/electron-browser/workbenchTestServices.ts | 1 + test/unit/electron/index.js | 1 + 11 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/vs/code/electron-main/app.ts b/src/vs/code/electron-main/app.ts index b350f458358..8b726400b97 100644 --- a/src/vs/code/electron-main/app.ts +++ b/src/vs/code/electron-main/app.ts @@ -134,7 +134,11 @@ export class CodeApplication extends Disposable { // // !!! DO NOT CHANGE without consulting the documentation !!! // - // app.on('remote-get-guest-web-contents', event => event.preventDefault()); // TODO@Matt revisit this need for + app.on('remote-get-guest-web-contents', event => { + this.logService.trace('App#on(remote-get-guest-web-contents): prevented'); + + event.preventDefault(); + }); app.on('remote-require', (event, sender, module) => { this.logService.trace('App#on(remote-require): prevented'); diff --git a/src/vs/code/electron-main/auth.ts b/src/vs/code/electron-main/auth.ts index b32f73c9a2f..1d2f732c33e 100644 --- a/src/vs/code/electron-main/auth.ts +++ b/src/vs/code/electron-main/auth.ts @@ -59,8 +59,8 @@ export class ProxyAuthHandler extends Disposable { title: 'VS Code', webPreferences: { nodeIntegration: true, - webviewTag: true, enableWebSQL: false, + enableRemoteModule: false, nativeWindowOpen: true } }; diff --git a/src/vs/code/electron-main/sharedProcess.ts b/src/vs/code/electron-main/sharedProcess.ts index b6e38cc4238..92027912edc 100644 --- a/src/vs/code/electron-main/sharedProcess.ts +++ b/src/vs/code/electron-main/sharedProcess.ts @@ -47,6 +47,7 @@ export class SharedProcess implements ISharedProcess { nodeIntegration: true, webgl: false, enableWebSQL: false, + enableRemoteModule: false, nativeWindowOpen: true, disableBlinkFeatures: 'Auxclick' // do NOT change, allows us to identify this window as shared-process in the process explorer } diff --git a/src/vs/code/electron-main/window.ts b/src/vs/code/electron-main/window.ts index 33aa067807a..45064b77ecf 100644 --- a/src/vs/code/electron-main/window.ts +++ b/src/vs/code/electron-main/window.ts @@ -36,8 +36,6 @@ import { ILifecycleMainService } from 'vs/platform/lifecycle/electron-main/lifec import { IStorageMainService } from 'vs/platform/storage/node/storageMainService'; import { IFileService } from 'vs/platform/files/common/files'; -const RUN_TEXTMATE_IN_WORKER = false; - export interface IWindowCreationOptions { state: IWindowState; extensionDevelopmentPath?: string[]; @@ -168,9 +166,9 @@ export class CodeWindow extends Disposable implements ICodeWindow { webPreferences: { preload: URI.parse(this.doGetPreloadUrl()).fsPath, nodeIntegration: true, - nodeIntegrationInWorker: RUN_TEXTMATE_IN_WORKER, webviewTag: true, enableWebSQL: false, + enableRemoteModule: false, nativeWindowOpen: true } }; diff --git a/src/vs/platform/driver/electron-browser/driver.ts b/src/vs/platform/driver/electron-browser/driver.ts index 9e39b4d6eb0..f0d350d392e 100644 --- a/src/vs/platform/driver/electron-browser/driver.ts +++ b/src/vs/platform/driver/electron-browser/driver.ts @@ -7,7 +7,6 @@ import { IDisposable, toDisposable } from 'vs/base/common/lifecycle'; import { WindowDriverChannel, WindowDriverRegistryChannelClient } from 'vs/platform/driver/node/driver'; import { IInstantiationService, ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; import { IMainProcessService } from 'vs/platform/ipc/electron-sandbox/mainProcessService'; -import { remote } from 'electron'; import { timeout } from 'vs/base/common/async'; import { BaseWindowDriver } from 'vs/platform/driver/browser/baseDriver'; import { IElectronService } from 'vs/platform/electron/electron-sandbox/electron'; @@ -32,11 +31,10 @@ class WindowDriver extends BaseWindowDriver { private async _click(selector: string, clickCount: number, offset?: { x: number, y: number }): Promise { const { x, y } = await this._getElementXY(selector, offset); - const webContents = remote.getCurrentWebContents(); - webContents.sendInputEvent({ type: 'mouseDown', x, y, button: 'left', clickCount } as any); + await this.electronService.sendInputEvent({ type: 'mouseDown', x, y, button: 'left', clickCount } as any); await timeout(10); - webContents.sendInputEvent({ type: 'mouseUp', x, y, button: 'left', clickCount } as any); + await this.electronService.sendInputEvent({ type: 'mouseUp', x, y, button: 'left', clickCount } as any); await timeout(100); } diff --git a/src/vs/platform/electron/common/electron.ts b/src/vs/platform/electron/common/electron.ts index 5d8f4aa73db..44de5413c42 100644 --- a/src/vs/platform/electron/common/electron.ts +++ b/src/vs/platform/electron/common/electron.ts @@ -94,6 +94,7 @@ export interface ICommonElectronService { openDevTools(options?: OpenDevToolsOptions): Promise; toggleDevTools(): Promise; startCrashReporter(options: CrashReporterStartOptions): Promise; + sendInputEvent(event: { type: 'mouseDown' | 'mouseUp'; x: number; y: number; clickCount: number; }): Promise; // Connectivity resolveProxy(url: string): Promise; diff --git a/src/vs/platform/electron/electron-main/electronMainService.ts b/src/vs/platform/electron/electron-main/electronMainService.ts index 94fe6f13968..7cb2c91fb0e 100644 --- a/src/vs/platform/electron/electron-main/electronMainService.ts +++ b/src/vs/platform/electron/electron-main/electronMainService.ts @@ -459,6 +459,13 @@ export class ElectronMainService implements IElectronMainService { crashReporter.start(options); } + async sendInputEvent(windowId: number | undefined, event: { type: 'mouseDown' | 'mouseUp'; x: number; y: number; clickCount: number; }): Promise { + const window = this.windowById(windowId); + if (window && (event.type === 'mouseDown' || event.type === 'mouseUp')) { + window.win.webContents.sendInputEvent(event); + } + } + //#endregion private windowById(windowId: number | undefined): ICodeWindow | undefined { diff --git a/src/vs/platform/issue/electron-main/issueMainService.ts b/src/vs/platform/issue/electron-main/issueMainService.ts index 2d0030b498f..087307e1862 100644 --- a/src/vs/platform/issue/electron-main/issueMainService.ts +++ b/src/vs/platform/issue/electron-main/issueMainService.ts @@ -197,6 +197,7 @@ export class IssueMainService implements ICommonIssueService { preload: URI.parse(require.toUrl('vs/base/parts/sandbox/electron-browser/preload.js')).fsPath, nodeIntegration: true, enableWebSQL: false, + enableRemoteModule: false, nativeWindowOpen: true } }); @@ -249,6 +250,7 @@ export class IssueMainService implements ICommonIssueService { preload: URI.parse(require.toUrl('vs/base/parts/sandbox/electron-browser/preload.js')).fsPath, nodeIntegration: true, enableWebSQL: false, + enableRemoteModule: false, nativeWindowOpen: true } }); diff --git a/src/vs/workbench/contrib/codeEditor/browser/suggestEnabledInput/suggestEnabledInput.ts b/src/vs/workbench/contrib/codeEditor/browser/suggestEnabledInput/suggestEnabledInput.ts index dc87d2f8a21..5e809ac197e 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/suggestEnabledInput/suggestEnabledInput.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/suggestEnabledInput/suggestEnabledInput.ts @@ -314,7 +314,6 @@ function getSuggestEnabledInputOptions(ariaLabel?: string): IEditorOptions { cursorWidth: 1, fontFamily: DEFAULT_FONT_FAMILY, ariaLabel: ariaLabel || '', - snippetSuggestions: 'none', suggest: { filterGraceful: false, showIcons: false }, autoClosingBrackets: 'never' diff --git a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts index 88a4c3b2a72..210769dcc06 100644 --- a/src/vs/workbench/test/electron-browser/workbenchTestServices.ts +++ b/src/vs/workbench/test/electron-browser/workbenchTestServices.ts @@ -232,6 +232,7 @@ export class TestElectronService implements IElectronService { async writeClipboardBuffer(format: string, buffer: Uint8Array, type?: 'selection' | 'clipboard' | undefined): Promise { } async readClipboardBuffer(format: string): Promise { return Uint8Array.from([]); } async hasClipboard(format: string, type?: 'selection' | 'clipboard' | undefined): Promise { return false; } + async sendInputEvent(event: { type: 'mouseDown' | 'mouseUp'; x: number; y: number; clickCount: number; }): Promise { } } export function workbenchInstantiationService(): ITestInstantiationService { diff --git a/test/unit/electron/index.js b/test/unit/electron/index.js index c96cd1ee5a4..6d1c7653799 100644 --- a/test/unit/electron/index.js +++ b/test/unit/electron/index.js @@ -118,6 +118,7 @@ app.on('ready', () => { webviewTag: true, preload: path.join(__dirname, '..', '..', '..', 'src', 'vs', 'base', 'parts', 'sandbox', 'electron-browser', 'preload.js'), // ensure similar environment as VSCode as tests may depend on this enableWebSQL: false, + enableRemoteModule: false, nativeWindowOpen: true } });