From 1d8bf9592665f45cefc68e11eb7eff7cb5f6ac00 Mon Sep 17 00:00:00 2001 From: kkapsner Date: Thu, 28 Mar 2024 16:53:01 +0100 Subject: [PATCH] Added protection for navigator.storage.estimate() Fixes #681 --- lib/modifiedNavigatorAPI.js | 37 +++++++++++++++++++++++++++++++++++-- lib/settingDefinitions.js | 1 + releaseNotes.txt | 1 + 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/lib/modifiedNavigatorAPI.js b/lib/modifiedNavigatorAPI.js index 43defe6..c19f89b 100644 --- a/lib/modifiedNavigatorAPI.js +++ b/lib/modifiedNavigatorAPI.js @@ -12,7 +12,7 @@ scope = require.register("./modifiedNavigatorAPI", {}); } - const {checkerWrapper, setGetterProperties, getStatusByFlag} = require("./modifiedAPIFunctions"); + const {checkerWrapper, setProperties, getStatusByFlag} = require("./modifiedAPIFunctions"); const extension = require("./extension"); const navigator = require("./navigator"); @@ -55,7 +55,40 @@ }; }); - setGetterProperties(scope.changedGetters, { + scope.changedFunctions = { + estimate: { + objectGetters: [function(window){return window.StorageManager && window.StorageManager.prototype;}], + fakeGenerator: function(checker){ + const quota = 10 * 1024 * 1024 * 1024; + return function estimate(){ + return checkerWrapper(checker, this, arguments, function(args, check){ + const {notify, original, window} = check; + const This = this; + return new window.Promise(async function(resolve, reject){ + try { + const originalValue = await original.call(This, ...args); + if (originalValue.quota !== quota){ + originalValue.usage = Math.min( + quota, + Math.max(0, quota - (originalValue.quota - originalValue.usage)) + ); + originalValue.quota = quota; + + notify("fakedNavigatorReadout"); + } + resolve(originalValue); + } + catch (error){ + reject(error); + } + }); + }); + }; + } + } + }; + + setProperties(scope.changedFunctions, scope.changedGetters, { type: "readout", getStatus: getStatusByFlag("protectNavigator"), api: "navigator" diff --git a/lib/settingDefinitions.js b/lib/settingDefinitions.js index 552a9a2..bcda724 100644 --- a/lib/settingDefinitions.js +++ b/lib/settingDefinitions.js @@ -146,6 +146,7 @@ "appName @ navigator", "appVersion @ navigator", "buildID @ navigator", + "estimate @ navigator", "oscpu @ navigator", "platform @ navigator", "product @ navigator", diff --git a/releaseNotes.txt b/releaseNotes.txt index 5452dae..fc73cb8 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -5,6 +5,7 @@ Version 1.10: new features: - added setting showPresetsOnInstallation to be able to not show the presets page upon installation - display version in page and browser action + - added protection for navigator.storage.estimate() fixes: - always protect about:blank