diff --git a/lib/browser/guest-window-manager.js b/lib/browser/guest-window-manager.js index e2ec4a96a8c9..c895266466d6 100644 --- a/lib/browser/guest-window-manager.js +++ b/lib/browser/guest-window-manager.js @@ -13,6 +13,7 @@ const inheritedWebPreferences = new Map([ ['javascript', false], ['nativeWindowOpen', true], ['nodeIntegration', false], + ['sandbox', true], ['webviewTag', false] ]) diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index 67cf4f62e937..3bae23b5f8e5 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -1066,6 +1066,24 @@ describe('BrowserWindow module', function () { }) }) + it('should inherit the sandbox setting in opened windows', function (done) { + w.destroy() + w = new BrowserWindow({ + show: false, + webPreferences: { + sandbox: true + } + }) + + const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js') + ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath) + ipcMain.once('answer', (event, args) => { + assert.equal(args.includes('--enable-sandbox'), true) + done() + }) + w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`) + }) + it('should open windows with the options configured via new-window event listeners', function (done) { w.destroy() w = new BrowserWindow({ @@ -1077,10 +1095,10 @@ describe('BrowserWindow module', function () { const preloadPath = path.join(fixtures, 'api', 'new-window-preload.js') ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'preload', preloadPath) - ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'sandbox', true) - ipcMain.once('answer', (event, args) => { - assert.ok(args.includes('--enable-sandbox')) - assert.ok(args.includes(`--preload=${path.join(fixtures, 'api', 'new-window-preload.js')}`)) + ipcRenderer.send('set-web-preferences-on-next-new-window', w.webContents.id, 'foo', 'bar') + ipcMain.once('answer', (event, args, webPreferences) => { + assert.equal(args.includes('--enable-sandbox'), true) + assert.equal(webPreferences.foo, 'bar') done() }) w.loadURL(`file://${path.join(fixtures, 'api', 'new-window.html')}`) diff --git a/spec/fixtures/api/new-window-preload.js b/spec/fixtures/api/new-window-preload.js index 2676a785ea2a..0364593734e6 100644 --- a/spec/fixtures/api/new-window-preload.js +++ b/spec/fixtures/api/new-window-preload.js @@ -1,4 +1,4 @@ -const {ipcRenderer} = require('electron') +const {ipcRenderer, remote} = require('electron') -ipcRenderer.send('answer', process.argv) +ipcRenderer.send('answer', process.argv, remote.getCurrentWindow().webContents.getWebPreferences()) window.close()