feat: enable sandbox for proxy auth window (#100907)

* feat: enable sandbox for proxy auth window

* webContents.send uses structured clone algorithm

* mv electron-browser/auth.* => electron-sandbox
This commit is contained in:
Robo
2020-07-09 09:27:31 -07:00
committed by GitHub
parent a1967ddf13
commit 9a220aa3b3
3 changed files with 66 additions and 49 deletions

View File

@@ -6,6 +6,7 @@
import { localize } from 'vs/nls';
import { Disposable } from 'vs/base/common/lifecycle';
import { Event } from 'vs/base/common/event';
import { URI } from 'vs/base/common/uri';
import { BrowserWindow, BrowserWindowConstructorOptions, app, AuthInfo, WebContents, Event as ElectronEvent } from 'electron';
type LoginEvent = {
@@ -58,10 +59,12 @@ export class ProxyAuthHandler extends Disposable {
show: true,
title: 'VS Code',
webPreferences: {
nodeIntegration: true,
preload: URI.parse(require.toUrl('vs/base/parts/sandbox/electron-browser/preload.js')).fsPath,
enableWebSQL: false,
sandbox: true,
devTools: false,
enableRemoteModule: false,
nativeWindowOpen: true
v8CacheOptions: 'bypassHeatCheck'
}
};
@@ -72,24 +75,27 @@ export class ProxyAuthHandler extends Disposable {
}
const win = new BrowserWindow(opts);
const config = {};
const baseUrl = require.toUrl('vs/code/electron-browser/proxy/auth.html');
const url = `${baseUrl}?config=${encodeURIComponent(JSON.stringify(config))}`;
const url = require.toUrl('vs/code/electron-sandbox/proxy/auth.html');
const proxyUrl = `${authInfo.host}:${authInfo.port}`;
const title = localize('authRequire', "Proxy Authentication Required");
const message = localize('proxyauth', "The proxy {0} requires authentication.", proxyUrl);
const data = { title, message };
const javascript = 'promptForCredentials(' + JSON.stringify(data) + ')';
const onWindowClose = () => cb('', '');
win.on('close', onWindowClose);
win.setMenu(null);
win.loadURL(url);
win.webContents.executeJavaScript(javascript, true).then(({ username, password }: Credentials) => {
cb(username, password);
win.webContents.on('did-finish-load', () => {
const data = { title, message };
win.webContents.send('vscode:openProxyAuthDialog', data);
});
win.webContents.on('ipc-message', (event, channel, credentials: Credentials) => {
if (channel === 'vscode:proxyAuthResponse') {
const { username, password } = credentials;
cb(username, password);
}
win.removeListener('close', onWindowClose);
win.close();
});
win.loadURL(url);
}
}