Skip to content

Commit

Permalink
chore: make nodeIntegration / webviewTag defaults false
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Jan 2, 2019
1 parent 2d8ac7b commit 3977d2f
Show file tree
Hide file tree
Showing 21 changed files with 254 additions and 136 deletions.
5 changes: 2 additions & 3 deletions atom/browser/web_contents_preferences.cc
Expand Up @@ -99,9 +99,9 @@ WebContentsPreferences::WebContentsPreferences(
// Set WebPreferences defaults onto the JS object
SetDefaultBoolIfUndefined(options::kPlugins, false);
SetDefaultBoolIfUndefined(options::kExperimentalFeatures, false);
bool node = SetDefaultBoolIfUndefined(options::kNodeIntegration, true);
SetDefaultBoolIfUndefined(options::kNodeIntegration, false);
SetDefaultBoolIfUndefined(options::kNodeIntegrationInWorker, false);
SetDefaultBoolIfUndefined(options::kWebviewTag, node);
SetDefaultBoolIfUndefined(options::kWebviewTag, false);
SetDefaultBoolIfUndefined(options::kSandbox, false);
SetDefaultBoolIfUndefined(options::kNativeWindowOpen, false);
SetDefaultBoolIfUndefined(options::kContextIsolation, false);
Expand Down Expand Up @@ -236,7 +236,6 @@ void WebContentsPreferences::AppendCommandLineSwitches(
command_line->AppendSwitch(switches::kNodeIntegrationInWorker);

// Check if webview tag creation is enabled, default to nodeIntegration value.
// TODO(kevinsawicki): Default to false in 2.0
if (IsEnabled(options::kWebviewTag))
command_line->AppendSwitch(switches::kWebviewTag);

Expand Down
3 changes: 1 addition & 2 deletions lib/browser/guest-view-manager.js
Expand Up @@ -202,7 +202,7 @@ const attachGuest = function (event, embedderFrameId, elementInstanceId, guestIn

const webPreferences = {
guestInstanceId: guestInstanceId,
nodeIntegration: params.nodeintegration != null ? params.nodeintegration : false,
nodeIntegration: params.nodeintegration,
enableRemoteModule: params.enableremotemodule,
plugins: params.plugins,
zoomFactor: embedder._getZoomFactor(),
Expand Down Expand Up @@ -237,7 +237,6 @@ const attachGuest = function (event, embedderFrameId, elementInstanceId, guestIn
['contextIsolation', true],
['javascript', false],
['nativeWindowOpen', true],
['nodeIntegration', false],
['enableRemoteModule', false],
['sandbox', true]
])
Expand Down
4 changes: 1 addition & 3 deletions lib/browser/guest-window-manager.js
Expand Up @@ -13,10 +13,8 @@ const inheritedWebPreferences = new Map([
['contextIsolation', true],
['javascript', false],
['nativeWindowOpen', true],
['nodeIntegration', false],
['enableRemoteModule', false],
['sandbox', true],
['webviewTag', false]
['sandbox', true]
])

// Copy attribute of |parent| to |child| if it is not defined in |child|.
Expand Down
5 changes: 1 addition & 4 deletions lib/renderer/init.js
Expand Up @@ -34,7 +34,7 @@ require('@electron/internal/renderer/web-frame-init')()
const { hasSwitch, getSwitchValue } = require('@electron/internal/renderer/command-line')

const contextIsolation = hasSwitch('context-isolation')
let nodeIntegration = hasSwitch('node-integration')
const nodeIntegration = hasSwitch('node-integration')
const webviewTag = hasSwitch('webview-tag')
const isHiddenPage = hasSwitch('hidden-page')
const isBackgroundPage = hasSwitch('background-page')
Expand All @@ -60,14 +60,11 @@ if (contextIsolation) {
if (window.location.protocol === 'chrome-devtools:') {
// Override some inspector APIs.
require('@electron/internal/renderer/inspector')
nodeIntegration = false
} else if (window.location.protocol === 'chrome-extension:') {
// Add implementations of chrome API.
require('@electron/internal/renderer/chrome-api').injectTo(window.location.hostname, isBackgroundPage, window)
nodeIntegration = false
} else if (window.location.protocol === 'chrome:') {
// Disable node integration for chrome UI scheme.
nodeIntegration = false
} else {
// Override default web functions.
require('@electron/internal/renderer/window-setup')(ipcRenderer, guestInstanceId, openerId, isHiddenPage, usesNativeWindowOpen)
Expand Down
34 changes: 29 additions & 5 deletions spec/api-app-spec.js
Expand Up @@ -32,7 +32,10 @@ describe('electron module', () => {
window = new BrowserWindow({
show: false,
width: 400,
height: 400
height: 400,
webPreferences: {
nodeIntegration: true
}
})
})

Expand Down Expand Up @@ -298,7 +301,12 @@ describe('app module', () => {
password: 'electron'
}

w = new BrowserWindow({ show: false })
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})

w.webContents.on('did-finish-load', () => {
expect(w.webContents.getTitle()).to.equal('authorized')
Expand Down Expand Up @@ -375,7 +383,12 @@ describe('app module', () => {
expect(webContents).to.equal(w.webContents)
done()
})
w = new BrowserWindow({ show: false })
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
w.loadURL('about:blank')
w.webContents.executeJavaScript(`require('electron').desktopCapturer.getSources({ types: ['screen'] }, () => {})`)
})
Expand All @@ -386,7 +399,12 @@ describe('app module', () => {
expect(moduleName).to.equal('test')
done()
})
w = new BrowserWindow({ show: false })
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
w.loadURL('about:blank')
w.webContents.executeJavaScript(`require('electron').remote.require('test')`)
})
Expand All @@ -397,7 +415,12 @@ describe('app module', () => {
expect(globalName).to.equal('test')
done()
})
w = new BrowserWindow({ show: false })
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true
}
})
w.loadURL('about:blank')
w.webContents.executeJavaScript(`require('electron').remote.getGlobal('test')`)
})
Expand Down Expand Up @@ -590,6 +613,7 @@ describe('app module', () => {
w = new BrowserWindow({
show: false,
webPreferences: {
nodeIntegration: true,
partition: 'empty-certificate'
}
})
Expand Down

0 comments on commit 3977d2f

Please sign in to comment.