From 621106ffbf2f875c484ccbbb35a43d1b3b45c3fd Mon Sep 17 00:00:00 2001 From: kkapsner Date: Wed, 29 May 2019 00:37:33 +0200 Subject: [PATCH] Persistent rng is no longer shared between containers (different cookieStoreId) Fixes #350 --- lib/frame.js | 5 +++++ lib/main.js | 2 ++ lib/randomSupplies.js | 14 +++++++++++++- manifest.json | 3 ++- releaseNotes.txt | 1 + 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/lib/frame.js b/lib/frame.js index 583c518..6d7df56 100644 --- a/lib/frame.js +++ b/lib/frame.js @@ -85,6 +85,11 @@ notice("my tab id is", data.tabId); tabId = data.tabId; } + if (data.hasOwnProperty("cookieStoreId")){ + notice("my tab cookie store id is", data.cookieStoreId); + const {persistent: persistentRnd} = require("./randomSupplies"); + persistentRnd.setCookieStoreId(data.cookieStoreId); + } const persistentRndName = "persistent" + (extension.inIncognitoContext? "Incognito": "") + "Rnd"; if (data.hasOwnProperty(persistentRndName)){ const persistentRndValue = data[persistentRndName]; diff --git a/lib/main.js b/lib/main.js index 2c96935..a90186a 100644 --- a/lib/main.js +++ b/lib/main.js @@ -57,9 +57,11 @@ return; } verbose("send back the tab id", port.sender.tab.id); + verbose("send back the tab cookie store id", port.sender.tab.cookieStoreId); verbose("send back the persistent random seeds", persistentRndStorage.persistentRnd); port.postMessage({ tabId: port.sender.tab.id, + cookieStoreId: port.sender.tab.cookieStoreId, persistentRnd: persistentRndStorage.persistentRnd, persistentIncognitoRnd: persistentRndStorage.persistentIncognitoRnd }); diff --git a/lib/randomSupplies.js b/lib/randomSupplies.js index 7658541..a627b48 100644 --- a/lib/randomSupplies.js +++ b/lib/randomSupplies.js @@ -81,6 +81,7 @@ } var persistentRnd = Object.create(null); + let cookieStoreId = ""; settings.onloaded(function(){ try { let storedData = JSON.parse( @@ -120,7 +121,7 @@ }); return function getPersistentRnd(window){ - var domain = getDomain(window); + var domain = cookieStoreId + getDomain(window); if (!persistentRnd[domain]){ // create the (sub-)domains random numbers if not existing persistentRnd[domain] = new Uint8Array(128); @@ -142,6 +143,17 @@ scope.persistent.setDomainRnd = function(domain, rnd){ persistentRnd[domain] = new Uint8Array(rnd); }; + scope.persistent.setCookieStoreId = function(newCookieStoreId){ + if ( + typeof newCookieStoreId === "string" && + newCookieStoreId !== "firefox-default" + ){ + cookieStoreId = ( + newCookieStoreId !== "" && + newCookieStoreId !== "firefox-default" + )? newCookieStoreId + "@": ""; + } + }; scope.persistent.getRng = function(length, window){ var bitSet = new Uint32Array(getPersistentRnd(window).buffer); var bitSetLength = bitSet.length; diff --git a/manifest.json b/manifest.json index 2e64411..ecf7e10 100644 --- a/manifest.json +++ b/manifest.json @@ -85,7 +85,8 @@ "tabs", "activeTab", "webRequest", - "webRequestBlocking" + "webRequestBlocking", + "cookies" ], "applications": { diff --git a/releaseNotes.txt b/releaseNotes.txt index d2dfdd6..4e1c429 100644 --- a/releaseNotes.txt +++ b/releaseNotes.txt @@ -4,6 +4,7 @@ Version 0.5.10: new features: - added date and time to the settings export file + - persistent rng is no longer shared between containers (different cookieStoreId) fixes: - setter for innerHTML broke pages