From a95fae3de804a0340b4d0f82855e8e5a4eec2caa Mon Sep 17 00:00:00 2001 From: kkapsner Date: Fri, 16 Aug 2019 17:34:16 +0200 Subject: [PATCH] Future proof: getters my be values in other browsers Example: window.opener is a value property in Chrome. --- lib/intercept.js | 33 +++++++++++++++++++++++++++++++++ lib/modifiedWindowAPI.js | 6 ++++++ 2 files changed, 39 insertions(+) diff --git a/lib/intercept.js b/lib/intercept.js index faa4d0a..2455410 100644 --- a/lib/intercept.js +++ b/lib/intercept.js @@ -349,6 +349,39 @@ Object.defineProperty(object, name, descriptor); } + else if ( + changedGetter.valueGenerator && + descriptor && descriptor.hasOwnProperty("value") + ){ + const protectedAPIFeatures = prefs("protectedAPIFeatures"); + if ( + functionStatus.active && + ( + !protectedAPIFeatures.hasOwnProperty(name) || + protectedAPIFeatures[name] + ) + ){ + switch (functionStatus.mode){ + case "ask": case "block": case "fake": + descriptor.value = changedGetter.valueGenerator({ + mode: functionStatus.mode, + original: descriptor.value, + notify: function notifyCallback(messageId){ + notify({ + url: getURL(window), + errorStack: (new Error()).stack, + messageId, + timestamp: new Date(), + functionName: name, + api: changedGetter.api + }); + } + }); + Object.defineProperty(object, name, descriptor); + break; + } + } + } else { logging.error("Try to fake non getter property:", changedGetter); } diff --git a/lib/modifiedWindowAPI.js b/lib/modifiedWindowAPI.js index e9d94d6..7cc6533 100644 --- a/lib/modifiedWindowAPI.js +++ b/lib/modifiedWindowAPI.js @@ -36,6 +36,12 @@ } }; return Object.getOwnPropertyDescriptor(temp, "opener").get; + }, + valueGenerator: function({original, notify}){ + if (original !== null){ + notify("fakedWindowReadout"); + } + return null; } }, {