prevent duplicate wildcard mappings

This commit is contained in:
BPower0036 2022-05-05 04:20:07 +00:00 committed by GitHub
parent f6348fbd3b
commit bbb18c6ac2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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));