fix: block custom window.open when nativeWindowOpen is true (#23188)

This commit is contained in:
Jeremy Apthorp 2020-04-22 10:48:54 -07:00 committed by GitHub
parent 3ac4fa85dd
commit c798a6e5d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View file

@ -219,6 +219,12 @@ const canAccessWindow = function (sender, target) {
// Routed window.open messages with raw options // Routed window.open messages with raw options
ipcMainInternal.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, url, frameName, features) => { ipcMainInternal.on('ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', (event, url, frameName, features) => {
// This should only be allowed for senders that have nativeWindowOpen: false
const webPreferences = event.sender.getLastWebPreferences();
if (webPreferences.nativeWindowOpen || webPreferences.sandbox) {
event.returnValue = null;
throw new Error('GUEST_WINDOW_MANAGER_WINDOW_OPEN denied: expected native window.open');
}
if (url == null || url === '') url = 'about:blank'; if (url == null || url === '') url = 'about:blank';
if (frameName == null) frameName = ''; if (frameName == null) frameName = '';
if (features == null) features = ''; if (features == null) features = '';

View file

@ -654,6 +654,34 @@ describe('chromium features', () => {
const [, window] = await emittedOnce(app, 'browser-window-created'); const [, window] = await emittedOnce(app, 'browser-window-created');
expect(window.getTitle()).to.equal('__proto__'); expect(window.getTitle()).to.equal('__proto__');
}); });
it('denies custom open when nativeWindowOpen: true', async () => {
const w = new BrowserWindow({
show: false,
webPreferences: {
contextIsolation: false,
nodeIntegration: true,
nativeWindowOpen: true
}
});
w.loadURL('about:blank');
const previousListeners = process.listeners('uncaughtException');
process.removeAllListeners('uncaughtException');
try {
const uncaughtException = new Promise<Error>(resolve => {
process.once('uncaughtException', resolve);
});
expect(await w.webContents.executeJavaScript(`(${function () {
const ipc = process.electronBinding('ipc').ipc;
return ipc.sendSync(true, 'ELECTRON_GUEST_WINDOW_MANAGER_WINDOW_OPEN', ['', '', ''])[0];
}})()`)).to.be.null();
const exception = await uncaughtException;
expect(exception.message).to.match(/denied: expected native window\.open/);
} finally {
previousListeners.forEach(l => process.on('uncaughtException', l));
}
});
}); });
describe('window.opener', () => { describe('window.opener', () => {