fix: execute session preload scripts in sandboxed renderers (#16538)
This commit is contained in:
parent
a25f82c91f
commit
fa5442f211
5 changed files with 47 additions and 33 deletions
|
@ -534,8 +534,7 @@ ipcMain.on('ELECTRON_BROWSER_CLIPBOARD_WRITE_FIND_TEXT', function (event, text)
|
|||
setReturnValue(event, () => electron.clipboard.writeFindText(text))
|
||||
})
|
||||
|
||||
ipcMain.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) {
|
||||
const preloadPath = event.sender._getPreloadPath()
|
||||
const getPreloadScript = function (preloadPath) {
|
||||
let preloadSrc = null
|
||||
let preloadError = null
|
||||
if (preloadPath) {
|
||||
|
@ -545,10 +544,17 @@ ipcMain.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) {
|
|||
preloadError = errorUtils.serialize(err)
|
||||
}
|
||||
}
|
||||
return { preloadPath, preloadSrc, preloadError }
|
||||
}
|
||||
|
||||
ipcMain.on('ELECTRON_BROWSER_SANDBOX_LOAD', function (event) {
|
||||
const preloadPaths = [
|
||||
...(event.sender.session ? event.sender.session.getPreloads() : []),
|
||||
event.sender._getPreloadPath()
|
||||
]
|
||||
|
||||
event.returnValue = {
|
||||
preloadPath,
|
||||
preloadSrc,
|
||||
preloadError,
|
||||
preloadScripts: preloadPaths.map(path => getPreloadScript(path)),
|
||||
isRemoteModuleEnabled: event.sender._isRemoteModuleEnabled(),
|
||||
isWebViewTagEnabled: guestViewManager.isWebViewTagEnabled(event.sender),
|
||||
process: {
|
||||
|
|
|
@ -29,7 +29,7 @@ Object.setPrototypeOf(process, EventEmitter.prototype)
|
|||
const ipcRenderer = require('@electron/internal/renderer/ipc-renderer-internal')
|
||||
|
||||
const {
|
||||
preloadPath, preloadSrc, preloadError, isRemoteModuleEnabled, isWebViewTagEnabled, process: processProps
|
||||
preloadScripts, isRemoteModuleEnabled, isWebViewTagEnabled, process: processProps
|
||||
} = ipcRenderer.sendSync('ELECTRON_BROWSER_SANDBOX_LOAD')
|
||||
|
||||
process.isRemoteModuleEnabled = isRemoteModuleEnabled
|
||||
|
@ -151,17 +151,19 @@ function runPreloadScript (preloadSrc) {
|
|||
preloadFn(preloadRequire, preloadProcess, Buffer, global, setImmediate, clearImmediate)
|
||||
}
|
||||
|
||||
try {
|
||||
if (preloadSrc) {
|
||||
runPreloadScript(preloadSrc)
|
||||
} else if (preloadError) {
|
||||
throw errorUtils.deserialize(preloadError)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Unable to load preload script: ${preloadPath}`)
|
||||
console.error(`${error}`)
|
||||
for (const { preloadPath, preloadSrc, preloadError } of preloadScripts) {
|
||||
try {
|
||||
if (preloadSrc) {
|
||||
runPreloadScript(preloadSrc)
|
||||
} else if (preloadError) {
|
||||
throw errorUtils.deserialize(preloadError)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`Unable to load preload script: ${preloadPath}`)
|
||||
console.error(`${error}`)
|
||||
|
||||
ipcRenderer.send('ELECTRON_BROWSER_PRELOAD_ERROR', preloadPath, errorUtils.serialize(error))
|
||||
ipcRenderer.send('ELECTRON_BROWSER_PRELOAD_ERROR', preloadPath, errorUtils.serialize(error))
|
||||
}
|
||||
}
|
||||
|
||||
// Warn about security issues
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue