From 8f5a7e6d396334cb9875b4080e3f44cee3086b3e Mon Sep 17 00:00:00 2001 From: Francis McKenzie Date: Wed, 4 May 2022 18:57:40 +0200 Subject: [PATCH] Wildcard subdomains - prevent duplicate wildcard mappings --- src/js/background/assignManager.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/js/background/assignManager.js b/src/js/background/assignManager.js index 9b4891f..d8ff37c 100644 --- a/src/js/background/assignManager.js +++ b/src/js/background/assignManager.js @@ -112,6 +112,9 @@ window.assignManager = { this.setExempted(pageUrlorUrlKey, tabId); }); } + if (data.wildcardHostname) { + await this.removeDuplicateWildcardHostname(data.wildcardHostname, siteStoreKey); + } await this.removeWildcardLookup(siteStoreKey); // eslint-disable-next-line require-atomic-updates data.identityMacAddonUUID = @@ -157,6 +160,24 @@ window.assignManager = { } }, + // Must not set the same wildcardHostname property on multiple sites. + // E.g. 'google.com' on both 'www.google.com' and 'mail.google.com'. + // + // Necessary because the stored wildcardLookup map is 1-to-1, i.e. either + // 'google.com' => 'www.google.com', or + // 'google.com' => 'mail.google.com', but not both! + async removeDuplicateWildcardHostname(wildcardHostname, expectedSiteStoreKey) { + const wildcardStoreKey = this.getWildcardStoreKey(wildcardHostname); + const siteStoreKey = await this.getByUrlKey(wildcardStoreKey); + if (siteStoreKey && siteStoreKey !== expectedSiteStoreKey) { + const siteSettings = await this.getByUrlKey(siteStoreKey); + if (siteSettings && siteSettings.wildcardHostname === wildcardHostname) { + delete siteSettings.wildcardHostname; + await this.set(siteStoreKey, siteSettings); // Will cause wildcard mapping to be cleared + } + } + }, + async deleteContainer(userContextId) { const sitesByContainer = await this.getAssignedSites(userContextId); this.area.remove(Object.keys(sitesByContainer));