Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable node in webviews when disabled in parent window #5244

Merged
merged 2 commits into from
Apr 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/browser/guest-view-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ var attachGuest = function (embedder, elementInstanceId, guestInstanceId, params
webSecurity: !params.disablewebsecurity,
blinkFeatures: params.blinkfeatures
}

if (embedder.getWebPreferences().nodeIntegration === false) {
webPreferences.nodeIntegration = false
}

if (params.preload) {
webPreferences.preloadURL = params.preload
}
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/module/answer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var ipcRenderer = require('electron').ipcRenderer
window.answer = function (answer) {
ipcRenderer.send('answer', answer)
}
13 changes: 13 additions & 0 deletions spec/fixtures/pages/web-view-log-process.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>test</title>
<script>
console.log(typeof process)
</script>
</head>
<body>
test?
</body>
</html>
23 changes: 23 additions & 0 deletions spec/fixtures/pages/webview-no-node-integration-on-window.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html>
<head>
<script>
document.addEventListener('DOMContentLoaded', function () {
var windowUrl = decodeURIComponent(window.location.search.substring(3))

var wv = new WebView()
wv.setAttribute('nodeintegration', 'yes')
wv.setAttribute('src', windowUrl)
wv.setAttribute('style', 'display:inline-block; width:200px; height:200px')

wv.addEventListener('console-message', function(e) {
window.answer(e.message)
})

document.body.appendChild(wv)
})
</script>
</head>
<body>
</body>
</html>
33 changes: 33 additions & 0 deletions spec/webview-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,39 @@ describe('<webview> tag', function () {
document.body.appendChild(webview)
})

it('disables node integration when disabled on the parent BrowserWindow', function (done) {
var b = undefined

ipcMain.once('answer', function (event, typeofProcess) {
try {
assert.equal(typeofProcess, 'undefined')
done()
} finally {
b.close()
}
})

var windowUrl = require('url').format({
pathname: `${fixtures}/pages/webview-no-node-integration-on-window.html`,
protocol: 'file',
query: {
p: `${fixtures}/pages/web-view-log-process.html`
},
slashes: true
})
var preload = path.join(fixtures, 'module', 'answer.js')

b = new BrowserWindow({
height: 400,
width: 400,
show: false,
webPreferences: {
preload: preload,
nodeIntegration: false,
}
})
b.loadURL(windowUrl)
})

it('disables node integration on child windows when it is disabled on the webview', function (done) {
app.once('browser-window-created', function (event, window) {
Expand Down