Skip to content

Commit

Permalink
Wildcard subdomains - prevent duplicate wildcard mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenfra committed May 16, 2022
1 parent 6ab8da3 commit 8f5a7e6
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/js/background/assignManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 8f5a7e6

Please sign in to comment.