1
0
mirror of https://github.com/kkapsner/CanvasBlocker synced 2024-12-22 12:50:36 +01:00

separate persistent random numbers for incognito windows

This commit is contained in:
kkapsner 2018-07-28 14:13:14 +02:00
parent 7f1fe0ed1c
commit 9b18631768
6 changed files with 61 additions and 18 deletions

View File

@ -56,12 +56,14 @@
notice("my tab id is", data.tabId);
tabId = data.tabId;
}
if (data.hasOwnProperty("persistentRnd")){
notice("got persistent random data", data.persistentRnd);
const persistentRndName = "persistent" + (browser.extension.inIncognitoContext? "Incognito": "") + "Rnd";
if (data.hasOwnProperty(persistentRndName)){
const persistentRndValue = data[persistentRndName];
notice("got persistent random data", persistentRndValue);
const {persistent: persistentRnd} = require("./randomSupplies.js");
Object.keys(data.persistentRnd).forEach(function(domain){
verbose("random data for", domain, data.persistentRnd[domain]);
persistentRnd.setDomainRnd(domain, data.persistentRnd[domain]);
Object.keys(persistentRndValue).forEach(function(domain){
verbose("random data for", domain, persistentRndValue[domain]);
persistentRnd.setDomainRnd(domain, persistentRndValue[domain]);
});
}
});

View File

@ -28,6 +28,7 @@
if (data["canvasBlocker-new-domain-rnd"]){
persistentRndStorage.setDomainData(
data["canvasBlocker-new-domain-rnd"].domain,
data["canvasBlocker-new-domain-rnd"].incognito,
data["canvasBlocker-new-domain-rnd"].rnd
);
if (keys.length === 1){
@ -55,7 +56,8 @@
verbose("send back the persistent random seeds", persistentRndStorage.persistentRnd);
port.postMessage({
tabId: port.sender.tab.id,
persistentRnd: persistentRndStorage.persistentRnd
persistentRnd: persistentRndStorage.persistentRnd,
persistentIncognitoRnd: persistentRndStorage.persistentIncognitoRnd
});
var url = new URL(port.sender.url);
port.onMessage.addListener(function(data){

View File

@ -12,12 +12,13 @@
scope = {};
window.scope.persistentRndStorage = scope;
}
const settings = require("./settings");
const logging = require("./logging");
scope.persistentRnd = Object.create(null);
scope.persistentIncognitoRnd = Object.create(null);
scope.init = function init(){
logging.message("initializing persistent rng storage");
@ -74,6 +75,16 @@
return settings.persistentRndClearIntervalValue * units[settings.persistentRndClearIntervalUnit] || 0;
};
}();
browser.windows.onRemoved.addListener(function(){
browser.windows.getAll().then(function(windows){
if (windows.every(function(window){
return !window.incognito;
})){
clearIncognito();
}
});
});
let clearTimeout;
function registerTimeout(){
@ -98,19 +109,30 @@
});
});
}
function clearIncognito(){
scope.persistentIncognitoRnd = Object.create(null);
settings.persistentIncognitoRndStorage = JSON.stringify(scope.persistentIncognitoRnd);
}
function clear(){
logging.verbose("domain rnd cleared");
scope.persistentRnd = Object.create(null);
settings.persistentRndStorage = JSON.stringify(scope.persistentRnd);
settings.lastPersistentRndClearing = Date.now();
clearIncognito();
registerTimeout();
broadcast({"canvasBlocker-clear-domain-rnd": true});
}
function setDomainData(domain, rnd){
logging.verbose("got new domain rnd for ", domain, ":", rnd);
scope.persistentRnd[domain] = rnd;
settings.persistentRndStorage = JSON.stringify(scope.persistentRnd);
broadcast({"canvasBlocker-set-domain-rnd": {domain, rnd}});
function setDomainData(domain, incognito, rnd){
logging.verbose("got new domain rnd for ", domain, " (incognito:", incognito, "):", rnd);
if (incognito){
scope.persistentIncognitoRnd[domain] = rnd;
settings.persistentIncognitoRndStorage = JSON.stringify(scope.persistentIncognitoRnd);
}
else {
scope.persistentRnd[domain] = rnd;
settings.persistentRndStorage = JSON.stringify(scope.persistentRnd);
}
broadcast({"canvasBlocker-set-domain-rnd": {domain, incognito, rnd}});
}
scope.clear = clear;

View File

@ -80,7 +80,11 @@
var persistentRnd = Object.create(null);
settings.onloaded(function(){
try {
let storedData = JSON.parse(settings.persistentRndStorage);
let storedData = JSON.parse(
browser.extension.inIncognitoContext?
settings.persistentIncognitoRndStorage:
settings.persistentRndStorage
);
for (var domain in storedData){
var value = storedData[domain];
if (
@ -102,8 +106,10 @@
browser.runtime.onMessage.addListener(function(data){
if (data["canvasBlocker-set-domain-rnd"]){
var {domain, rnd} = data["canvasBlocker-set-domain-rnd"];
persistentRnd[domain] = new Uint8Array(rnd);
var {domain, incognito, rnd} = data["canvasBlocker-set-domain-rnd"];
if (incognito === browser.extension.inIncognitoContext){
persistentRnd[domain] = new Uint8Array(rnd);
}
}
if (data["canvasBlocker-clear-domain-rnd"]){
persistentRnd = Object.create(null);
@ -117,7 +123,11 @@
persistentRnd[domain] = new Uint8Array(128);
window.crypto.getRandomValues(persistentRnd[domain]);
browser.runtime.sendMessage({
"canvasBlocker-new-domain-rnd": {domain, rnd: Array.from(persistentRnd[domain])}
"canvasBlocker-new-domain-rnd": {
domain,
incognito: browser.extension.inIncognitoContext,
rnd: Array.from(persistentRnd[domain])
}
});
}
return persistentRnd[domain];

View File

@ -113,6 +113,11 @@
name: "persistentRndStorage",
defaultValue: ""
},
{
name: "persistentIncognitoRndStorage",
resetOnStartup: true,
defaultValue: ""
},
{
name: "storePersistentRnd",
defaultValue: false

View File

@ -3,11 +3,13 @@ Version 0.5.2:
-
new features:
-
- separate persistent random numbers for incognito windows
(resets when closing all incognito windows - like cookies do)
fixes:
- optimized CSP
- in Firefox ESR (52) iFrames with a blob-URL cannot be protected -> they have to be blocked there as well
- broken when using with Random Agent Spoofer
known issues:
- if a data URL is blocked the page action button does not appear