Limit periodical rnd clearing

Periodical persistent rnd clearing does not clear in active tabs.

Fixes #518
This commit is contained in:
kkapsner 2021-02-21 11:49:29 +01:00
parent 28dd7f6819
commit ee87773ce2
5 changed files with 24 additions and 9 deletions

View File

@ -90,7 +90,7 @@
} }
} }
if (data["canvasBlocker-clear-domain-rnd"]){ if (data["canvasBlocker-clear-domain-rnd"]){
persistentRndStorage.clear(); persistentRndStorage.clear(data["canvasBlocker-clear-domain-rnd"] === "force");
if (keys.length === 1){ if (keys.length === 1){
return; return;
} }

View File

@ -123,14 +123,14 @@
scope.persistentIncognitoRnd = Object.create(null); scope.persistentIncognitoRnd = Object.create(null);
settings.persistentIncognitoRndStorage = JSON.stringify(scope.persistentIncognitoRnd); settings.persistentIncognitoRndStorage = JSON.stringify(scope.persistentIncognitoRnd);
} }
function clear(){ function clear(force = false){
logging.verbose("domain rnd cleared"); logging.verbose("domain rnd cleared");
scope.persistentRnd = Object.create(null); scope.persistentRnd = Object.create(null);
settings.persistentRndStorage = JSON.stringify(scope.persistentRnd); settings.persistentRndStorage = JSON.stringify(scope.persistentRnd);
settings.lastPersistentRndClearing = Date.now(); settings.lastPersistentRndClearing = Date.now();
clearIncognito(); clearIncognito();
registerTimeout(); registerTimeout();
broadcast({"canvasBlocker-clear-domain-rnd": true}); broadcast({"canvasBlocker-clear-domain-rnd": force? "force": true});
} }
function setDomainData(domain, incognito, rnd){ function setDomainData(domain, incognito, rnd){
logging.verbose("got new domain rnd for ", domain, " (incognito:", incognito, "):", rnd); logging.verbose("got new domain rnd for ", domain, " (incognito:", incognito, "):", rnd);

View File

@ -82,6 +82,12 @@
let persistentRnd = Object.create(null); let persistentRnd = Object.create(null);
let cookieStoreId = false; let cookieStoreId = false;
function getCookieStoreId(){
while (cookieStoreId === false){
extension.waitSync("to wait for cookie store id");
}
return cookieStoreId;
}
settings.onloaded(function(){ settings.onloaded(function(){
try { try {
let storedData = JSON.parse( let storedData = JSON.parse(
@ -116,15 +122,24 @@
} }
} }
if (data["canvasBlocker-clear-domain-rnd"]){ if (data["canvasBlocker-clear-domain-rnd"]){
const domain = getCookieStoreId() + getDomain(window);
let ownPersistendRnd = data["canvasBlocker-clear-domain-rnd"] !== "force"? persistentRnd[domain]: false;
persistentRnd = Object.create(null); persistentRnd = Object.create(null);
if (ownPersistendRnd){
persistentRnd[domain] = ownPersistendRnd;
extension.message.send({
"canvasBlocker-new-domain-rnd": {
domain,
incognito: extension.inIncognitoContext,
rnd: Array.from(persistentRnd[domain])
}
});
}
} }
}); });
return function getPersistentRnd(window){ return function getPersistentRnd(window){
while (cookieStoreId === false){ const domain = getCookieStoreId() + getDomain(window);
extension.waitSync("to wait for cookie store id");
}
const domain = cookieStoreId + getDomain(window);
if (!persistentRnd[domain]){ if (!persistentRnd[domain]){
// create the (sub-)domains random numbers if not existing // create the (sub-)domains random numbers if not existing
persistentRnd[domain] = new Uint8Array(128); persistentRnd[domain] = new Uint8Array(128);

View File

@ -36,7 +36,7 @@
logging.notice("empty storage"); logging.notice("empty storage");
settings.persistentRndStorage = ""; settings.persistentRndStorage = "";
logging.notice("send message to main script"); logging.notice("send message to main script");
extension.message.send({"canvasBlocker-clear-domain-rnd": true}); extension.message.send({"canvasBlocker-clear-domain-rnd": "force"});
}, },
clearPersistentRndForContainer: async function(){ clearPersistentRndForContainer: async function(){
const identities = await browser.contextualIdentities.query({}); const identities = await browser.contextualIdentities.query({});

View File

@ -1,6 +1,6 @@
Version 1.6: Version 1.6:
changes: changes:
- - periodical persistent rnd clearing does not clear in active tabs
new features: new features:
- try to not break tabs when updating - try to not break tabs when updating