Added protection for navigator.storage.estimate()

Fixes #681
This commit is contained in:
kkapsner 2024-03-28 16:53:01 +01:00
parent c6cf48c489
commit 1d8bf95926
3 changed files with 37 additions and 2 deletions

View File

@ -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"

View File

@ -146,6 +146,7 @@
"appName @ navigator",
"appVersion @ navigator",
"buildID @ navigator",
"estimate @ navigator",
"oscpu @ navigator",
"platform @ navigator",
"product @ navigator",

View File

@ -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