Merge pull request #5244 from electron/disable-node-in-web-view-when-disabled-in-parent
Disable node in webviews when disabled in parent window
This commit is contained in:
commit
08e18d46ea
5 changed files with 78 additions and 0 deletions
|
@ -182,6 +182,11 @@ var attachGuest = function (embedder, elementInstanceId, guestInstanceId, params
|
||||||
webSecurity: !params.disablewebsecurity,
|
webSecurity: !params.disablewebsecurity,
|
||||||
blinkFeatures: params.blinkfeatures
|
blinkFeatures: params.blinkfeatures
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (embedder.getWebPreferences().nodeIntegration === false) {
|
||||||
|
webPreferences.nodeIntegration = false
|
||||||
|
}
|
||||||
|
|
||||||
if (params.preload) {
|
if (params.preload) {
|
||||||
webPreferences.preloadURL = params.preload
|
webPreferences.preloadURL = params.preload
|
||||||
}
|
}
|
||||||
|
|
4
spec/fixtures/module/answer.js
vendored
Normal file
4
spec/fixtures/module/answer.js
vendored
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
var ipcRenderer = require('electron').ipcRenderer
|
||||||
|
window.answer = function (answer) {
|
||||||
|
ipcRenderer.send('answer', answer)
|
||||||
|
}
|
13
spec/fixtures/pages/web-view-log-process.html
vendored
Normal file
13
spec/fixtures/pages/web-view-log-process.html
vendored
Normal file
|
@ -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
spec/fixtures/pages/webview-no-node-integration-on-window.html
vendored
Normal file
23
spec/fixtures/pages/webview-no-node-integration-on-window.html
vendored
Normal file
|
@ -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>
|
|
@ -84,6 +84,39 @@ describe('<webview> tag', function () {
|
||||||
document.body.appendChild(webview)
|
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) {
|
it('disables node integration on child windows when it is disabled on the webview', function (done) {
|
||||||
app.once('browser-window-created', function (event, window) {
|
app.once('browser-window-created', function (event, window) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue