Skip to content

Commit 50673f7

Browse files
committed
Add a soft-allowlist for URLs allowed in or out of GC
1 parent b724eb6 commit 50673f7

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

background.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ const googleHostREs = [];
5555
const youtubeHostREs = [];
5656
const whitelistedHostREs = [];
5757
const allowlistedHostREs = [];
58+
const softAllowlistedHostREs = [];
5859

5960
async function isMACAddonEnabled () {
6061
try {
@@ -181,6 +182,15 @@ function generateAllowlistedHostREs () {
181182
}
182183
}
183184

185+
function generateSoftAllowlistedHostREs () {
186+
if (softAllowlistedHostREs.length != 0) {return;}
187+
const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
188+
for (let allowlistedDomain of extensionSettings.soft_allowlist) {
189+
allowlistedDomain = allowlistedDomain.replace(matchOperatorsRegex, '\\$&');
190+
softAllowlistedHostREs.push(new RegExp(`(^|\\.)${allowlistedDomain}$`));
191+
}
192+
}
193+
184194
async function loadExtensionSettings () {
185195
extensionSettings = await browser.storage.sync.get();
186196
if (extensionSettings.whitelist === undefined){
@@ -189,6 +199,9 @@ async function loadExtensionSettings () {
189199
if (extensionSettings.allowlist === undefined){
190200
extensionSettings.allowlist = "";
191201
}
202+
if (extensionSettings.soft_allowlist === undefined){
203+
extensionSettings.soft_allowlist = "";
204+
}
192205
}
193206

194207
async function clearGoogleCookies () {
@@ -312,6 +325,18 @@ function isAllowlistedURL (url) {
312325
return false;
313326
}
314327

328+
function isSoftAllowlistedURL (url) {
329+
generateSoftAllowlistedHostREs();
330+
const parsedUrl = new URL(url);
331+
for (let allowlistedHostRE of softAllowlistedHostREs) {
332+
if (allowlistedHostRE.test(parsedUrl.hostname)) {
333+
return true;
334+
}
335+
}
336+
return false;
337+
}
338+
339+
315340
function isSearchPageURL (url) {
316341
const parsedUrl = new URL(url);
317342
return parsedUrl.pathname.startsWith('/search');
@@ -344,7 +369,8 @@ function shouldContainInto (url, tab) {
344369
}
345370

346371
let allowlistUrl = (extensionSettings.allowlist.length!=0 && isAllowlistedURL(url));
347-
let handleUrl = isGoogleURL(url) || allowlistUrl;
372+
let softAllowlistUrl = (extensionSettings.soft_allowlist.length!=0 && isSoftAllowlistedURL(url));
373+
let handleUrl = isGoogleURL(url) || allowlistUrl || softAllowlistUrl;
348374

349375
if (handleUrl && extensionSettings.whitelist.length!=0 && isWhitelistedURL(url)) {
350376
handleUrl = false;
@@ -381,8 +407,8 @@ function shouldContainInto (url, tab) {
381407
return false;
382408
}
383409

384-
if (allowlistUrl) {
385-
// Don't force an allowlisted URL to be in the Google Container
410+
if (softAllowlistUrl) {
411+
// Don't force an soft-allowlisted URL to be in the Google Container
386412
return false;
387413
}
388414

options.html

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,17 @@ <h1>Settings</h1>
6868
</textarea>
6969
<br>
7070
Include additional urls in Google Container<br>
71-
<em>(Means use Google Container on these additional urls, e.g. for third party SSO or "Log in with Google". Use one url per line.)</em>
71+
<em>(Means always use Google Container on these additional urls, e.g. for "Log in with Google". Use one url per line.)</em>
72+
</label>
73+
</p>
74+
75+
<p>
76+
<label>
77+
<textarea id="soft_allowlist" value="" cols="80">
78+
</textarea>
79+
<br>
80+
Allow urls in Google Container<br>
81+
<em>(Means allow, but do not force, these urls into the Google Container, e.g. for third party SSO. Use one url per line.)</em>
7282
</label>
7383
</p>
7484

options.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function onOptionsPageSave(e)
3232
"ignore_flights": document.querySelector("#ignore_flights").checked,
3333
"dont_override_containers": document.querySelector("#dont_override_containers").checked,
3434
"whitelist": validate_list("#whitelist"),
35+
"soft_allowlist": validate_list("#soft_allowlist"),
3536
"allowlist": validate_list("#allowlist")
3637
});
3738

@@ -51,6 +52,7 @@ function onOptionsPageLoaded()
5152
document.querySelector("#ignore_flights").checked = res.ignore_flights || false;
5253
document.querySelector("#dont_override_containers").checked = res.dont_override_containers || false;
5354
fill_list_option(res.whitelist, "#whitelist");
55+
fill_list_option(res.whitelist, "#soft_allowlist");
5456
fill_list_option(res.allowlist, "#allowlist");
5557
});
5658
}

0 commit comments

Comments
 (0)