Skip to content

Commit

Permalink
cleanup badger firstparties list obj and avoid false positives when l…
Browse files Browse the repository at this point in the history
…ooking through it
  • Loading branch information
ablanathtanalba committed May 3, 2021
1 parent 825d69e commit 63c7f3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 5 additions & 1 deletion src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ function Badger() {
for (let contentScriptObj of manifestJson.content_scripts) {
// only include parts from content scripts that have firstparties entries
if (contentScriptObj.js[0].includes("/firstparties/")) {
firstParties.push(contentScriptObj.matches);
let extractedUrls = [];
for (let match of contentScriptObj.matches) {
extractedUrls.push(window.extractHostFromURL(match));
}
firstParties.push(extractedUrls);
}
}
// set list of firstparty url schemes onto badger object
Expand Down
12 changes: 4 additions & 8 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,15 +453,11 @@ function isThirdPartyDomain(domain1, domain2) {
* @return {Boolean} true if the domains are third party
*/
function firstPartyProtectionsEnabled(domain, firstPartiesList) {
// trim www from tab_host if need be
if (domain.startsWith('www.')) {
domain = domain.slice(4);
}
// trim trailing wildcard

for (let url_pattern of firstPartiesList) {
// if given domain is matched in our firstparties list, return true
if (url_pattern.includes(domain)) {
// account for wildcards in entries on firstPartiesList & avoid false positives
if (url_pattern.startsWith("*") && url_pattern.endsWith(domain)) {

This comment has been minimized.

Copy link
@ghostwords

ghostwords May 4, 2021

Member

I don't think url_pattern.endsWith(domain) is right. "Does '*.facebook.com' end with 'www.facebook.com'?"

Could you add a unit test assertion that covers this code branch?

return true;
} else if (url_pattern == domain) {
return true;
}
}
Expand Down

0 comments on commit 63c7f3d

Please sign in to comment.