Skip to content

Commit

Permalink
Add a soft-allowlist for URLs allowed in or out of GC
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronkollasch committed May 23, 2022
1 parent b724eb6 commit 50673f7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 4 deletions.
32 changes: 29 additions & 3 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const googleHostREs = [];
const youtubeHostREs = [];
const whitelistedHostREs = [];
const allowlistedHostREs = [];
const softAllowlistedHostREs = [];

async function isMACAddonEnabled () {
try {
Expand Down Expand Up @@ -181,6 +182,15 @@ function generateAllowlistedHostREs () {
}
}

function generateSoftAllowlistedHostREs () {
if (softAllowlistedHostREs.length != 0) {return;}
const matchOperatorsRegex = /[|\\{}()[\]^$+*?.-]/g;
for (let allowlistedDomain of extensionSettings.soft_allowlist) {
allowlistedDomain = allowlistedDomain.replace(matchOperatorsRegex, '\\$&');
softAllowlistedHostREs.push(new RegExp(`(^|\\.)${allowlistedDomain}$`));
}
}

async function loadExtensionSettings () {
extensionSettings = await browser.storage.sync.get();
if (extensionSettings.whitelist === undefined){
Expand All @@ -189,6 +199,9 @@ async function loadExtensionSettings () {
if (extensionSettings.allowlist === undefined){
extensionSettings.allowlist = "";
}
if (extensionSettings.soft_allowlist === undefined){
extensionSettings.soft_allowlist = "";
}
}

async function clearGoogleCookies () {
Expand Down Expand Up @@ -312,6 +325,18 @@ function isAllowlistedURL (url) {
return false;
}

function isSoftAllowlistedURL (url) {
generateSoftAllowlistedHostREs();
const parsedUrl = new URL(url);
for (let allowlistedHostRE of softAllowlistedHostREs) {
if (allowlistedHostRE.test(parsedUrl.hostname)) {
return true;
}
}
return false;
}


function isSearchPageURL (url) {
const parsedUrl = new URL(url);
return parsedUrl.pathname.startsWith('/search');
Expand Down Expand Up @@ -344,7 +369,8 @@ function shouldContainInto (url, tab) {
}

let allowlistUrl = (extensionSettings.allowlist.length!=0 && isAllowlistedURL(url));
let handleUrl = isGoogleURL(url) || allowlistUrl;
let softAllowlistUrl = (extensionSettings.soft_allowlist.length!=0 && isSoftAllowlistedURL(url));
let handleUrl = isGoogleURL(url) || allowlistUrl || softAllowlistUrl;

if (handleUrl && extensionSettings.whitelist.length!=0 && isWhitelistedURL(url)) {
handleUrl = false;
Expand Down Expand Up @@ -381,8 +407,8 @@ function shouldContainInto (url, tab) {
return false;
}

if (allowlistUrl) {
// Don't force an allowlisted URL to be in the Google Container
if (softAllowlistUrl) {
// Don't force an soft-allowlisted URL to be in the Google Container
return false;
}

Expand Down
12 changes: 11 additions & 1 deletion options.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,17 @@ <h1>Settings</h1>
</textarea>
<br>
Include additional urls in Google Container<br>
<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>
<em>(Means always use Google Container on these additional urls, e.g. for "Log in with Google". Use one url per line.)</em>
</label>
</p>

<p>
<label>
<textarea id="soft_allowlist" value="" cols="80">
</textarea>
<br>
Allow urls in Google Container<br>
<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>
</label>
</p>

Expand Down
2 changes: 2 additions & 0 deletions options.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ function onOptionsPageSave(e)
"ignore_flights": document.querySelector("#ignore_flights").checked,
"dont_override_containers": document.querySelector("#dont_override_containers").checked,
"whitelist": validate_list("#whitelist"),
"soft_allowlist": validate_list("#soft_allowlist"),
"allowlist": validate_list("#allowlist")
});

Expand All @@ -51,6 +52,7 @@ function onOptionsPageLoaded()
document.querySelector("#ignore_flights").checked = res.ignore_flights || false;
document.querySelector("#dont_override_containers").checked = res.dont_override_containers || false;
fill_list_option(res.whitelist, "#whitelist");
fill_list_option(res.whitelist, "#soft_allowlist");
fill_list_option(res.allowlist, "#allowlist");
});
}
Expand Down

0 comments on commit 50673f7

Please sign in to comment.