Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't force allowlisted URLs into Google Container #135

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 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,13 +182,25 @@ 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){
extensionSettings.whitelist = "";
extensionSettings.whitelist = "";
}
if (extensionSettings.allowlist === undefined){
extensionSettings.allowlist = "";
extensionSettings.allowlist = "";
}
if (extensionSettings.soft_allowlist === undefined){
extensionSettings.soft_allowlist = "";
}
}

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 @@ -343,7 +368,9 @@ function shouldContainInto (url, tab) {
return false;
}

let handleUrl = isGoogleURL(url) || (extensionSettings.allowlist.length!=0 && isAllowlistedURL(url));
let allowlistUrl = (extensionSettings.allowlist.length!=0 && isAllowlistedURL(url));
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 @@ -380,6 +407,11 @@ function shouldContainInto (url, tab) {
return false;
}

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

// Google-URL outside of Google Container Tab
// Should contain into Google Container
return googleCookieStoreId;
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.soft_allowlist, "#soft_allowlist");
fill_list_option(res.allowlist, "#allowlist");
});
}
Expand Down