Skip to content

Commit 8f5a7e6

Browse files
committed
Wildcard subdomains - prevent duplicate wildcard mappings
1 parent 6ab8da3 commit 8f5a7e6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/js/background/assignManager.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ window.assignManager = {
112112
this.setExempted(pageUrlorUrlKey, tabId);
113113
});
114114
}
115+
if (data.wildcardHostname) {
116+
await this.removeDuplicateWildcardHostname(data.wildcardHostname, siteStoreKey);
117+
}
115118
await this.removeWildcardLookup(siteStoreKey);
116119
// eslint-disable-next-line require-atomic-updates
117120
data.identityMacAddonUUID =
@@ -157,6 +160,24 @@ window.assignManager = {
157160
}
158161
},
159162

163+
// Must not set the same wildcardHostname property on multiple sites.
164+
// E.g. 'google.com' on both 'www.google.com' and 'mail.google.com'.
165+
//
166+
// Necessary because the stored wildcardLookup map is 1-to-1, i.e. either
167+
// 'google.com' => 'www.google.com', or
168+
// 'google.com' => 'mail.google.com', but not both!
169+
async removeDuplicateWildcardHostname(wildcardHostname, expectedSiteStoreKey) {
170+
const wildcardStoreKey = this.getWildcardStoreKey(wildcardHostname);
171+
const siteStoreKey = await this.getByUrlKey(wildcardStoreKey);
172+
if (siteStoreKey && siteStoreKey !== expectedSiteStoreKey) {
173+
const siteSettings = await this.getByUrlKey(siteStoreKey);
174+
if (siteSettings && siteSettings.wildcardHostname === wildcardHostname) {
175+
delete siteSettings.wildcardHostname;
176+
await this.set(siteStoreKey, siteSettings); // Will cause wildcard mapping to be cleared
177+
}
178+
}
179+
},
180+
160181
async deleteContainer(userContextId) {
161182
const sitesByContainer = await this.getAssignedSites(userContextId);
162183
this.area.remove(Object.keys(sitesByContainer));

0 commit comments

Comments
 (0)