diff --git a/lib/browser/api/web-contents.js b/lib/browser/api/web-contents.js index 685d0eb59fce0..8ee1d48fc1e16 100644 --- a/lib/browser/api/web-contents.js +++ b/lib/browser/api/web-contents.js @@ -321,6 +321,17 @@ WebContents.prototype.findInPage = function (text, options = {}) { return this._findInPage(text, options) } +const safeProtocols = new Set([ + 'chrome-devtools:', + 'chrome-extension:' +]) + +const isWebContentsTrusted = function (contents) { + const pageURL = contents._getURL() + const { protocol } = url.parse(pageURL) + return safeProtocols.has(protocol) +} + // Add JavaScript wrappers for WebContents class. WebContents.prototype._init = function () { // The navigation controller. @@ -380,7 +391,9 @@ WebContents.prototype._init = function () { for (const eventName of forwardedEvents) { this.on(eventName, (event, ...args) => { - app.emit(eventName, event, this, ...args) + if (!isWebContentsTrusted(event.sender)) { + app.emit(eventName, event, this, ...args) + } }) }