chore: disable the remote module in devtools / chrome extension background scripts (#16866)

* cache isRemoteModuleEnabled

* chore: disable the remote module in devtools / chrome extension background scripts
This commit is contained in:
Milan Burda 2019-02-11 21:42:37 +01:00 committed by John Kleinschmidt
parent a3cdf46fb6
commit d8ba1278d1
6 changed files with 20 additions and 17 deletions

View file

@ -264,10 +264,20 @@ const callFunction = function (event, contextId, func, caller, args) {
}
}
const isRemoteModuleEnabledCache = new WeakMap()
const isRemoteModuleEnabled = function (contents) {
if (!isRemoteModuleEnabledCache.has(contents)) {
isRemoteModuleEnabledCache.set(contents, contents._isRemoteModuleEnabled())
}
return isRemoteModuleEnabledCache.get(contents)
}
const handleRemoteCommand = function (channel, handler) {
ipcMainInternal.on(channel, (event, contextId, ...args) => {
let returnValue
if (!event.sender._isRemoteModuleEnabled()) {
if (!isRemoteModuleEnabled(event.sender)) {
event.returnValue = null
return
}
@ -506,7 +516,7 @@ ipcMainInternal.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) {
event.returnValue = {
preloadScripts: preloadPaths.map(path => getPreloadScript(path)),
isRemoteModuleEnabled: event.sender._isRemoteModuleEnabled(),
isRemoteModuleEnabled: isRemoteModuleEnabled(event.sender),
isWebViewTagEnabled: guestViewManager.isWebViewTagEnabled(event.sender),
process: {
arch: process.arch,