fix: validate sender for replies in ipcMainInternalUtils.invokeInWebContents() (#17416)
This commit is contained in:
parent
95df531b33
commit
cbd884060e
1 changed files with 11 additions and 3 deletions
|
@ -29,9 +29,17 @@ let nextId = 0
|
||||||
export function invokeInWebContents<T> (sender: Electron.WebContentsInternal, command: string, ...args: any[]) {
|
export function invokeInWebContents<T> (sender: Electron.WebContentsInternal, command: string, ...args: any[]) {
|
||||||
return new Promise<T>((resolve, reject) => {
|
return new Promise<T>((resolve, reject) => {
|
||||||
const requestId = ++nextId
|
const requestId = ++nextId
|
||||||
ipcMainInternal.once(`${command}_RESPONSE_${requestId}`, (
|
const channel = `${command}_RESPONSE_${requestId}`
|
||||||
_event, error: Electron.SerializedError, result: any
|
ipcMainInternal.on(channel, function handler (
|
||||||
) => {
|
event, error: Electron.SerializedError, result: any
|
||||||
|
) {
|
||||||
|
if (event.sender !== sender) {
|
||||||
|
console.error(`Reply to ${command} sent by unexpected WebContents (${event.sender.id})`)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
ipcMainInternal.removeListener(channel, handler)
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(errorUtils.deserialize(error))
|
reject(errorUtils.deserialize(error))
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue