fix: restrict sendToFrame to same-process frames by default (#26875)

This commit is contained in:
Jeremy Rose 2020-12-09 12:48:16 -08:00 committed by GitHub
parent 76f721474e
commit 07a1c2a3e5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 89 additions and 36 deletions

View file

@ -148,23 +148,23 @@ WebContents.prototype._sendInternal = function (channel, ...args) {
return this._send(true /* internal */, channel, args);
};
WebContents.prototype.sendToFrame = function (frameId, channel, ...args) {
WebContents.prototype.sendToFrame = function (frame, channel, ...args) {
if (typeof channel !== 'string') {
throw new Error('Missing required channel argument');
} else if (typeof frameId !== 'number') {
throw new Error('Missing required frameId argument');
} else if (!(typeof frame === 'number' || Array.isArray(frame))) {
throw new Error('Missing required frame argument (must be number or array)');
}
return this._sendToFrame(false /* internal */, frameId, channel, args);
return this._sendToFrame(false /* internal */, frame, channel, args);
};
WebContents.prototype._sendToFrameInternal = function (frameId, channel, ...args) {
WebContents.prototype._sendToFrameInternal = function (frame, channel, ...args) {
if (typeof channel !== 'string') {
throw new Error('Missing required channel argument');
} else if (typeof frameId !== 'number') {
throw new Error('Missing required frameId argument');
} else if (!(typeof frame === 'number' || Array.isArray(frame))) {
throw new Error('Missing required frame argument (must be number or array)');
}
return this._sendToFrame(true /* internal */, frameId, channel, args);
return this._sendToFrame(true /* internal */, frame, channel, args);
};
// Following methods are mapped to webFrame.
@ -456,8 +456,9 @@ WebContents.prototype._callWindowOpenHandler = function (event: any, url: string
};
const addReplyToEvent = (event: any) => {
const { processId, frameId } = event;
event.reply = (...args: any[]) => {
event.sender.sendToFrame(event.frameId, ...args);
event.sender.sendToFrame([processId, frameId], ...args);
};
};