Skip to content

Commit

Permalink
fix wildcard url matching firstparty detection and add test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ablanathtanalba committed May 6, 2021
1 parent 0c098a1 commit cad1393
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,11 @@ function isThirdPartyDomain(domain1, domain2) {
function firstPartyProtectionsEnabled(domain, firstPartiesList) {
for (let url_pattern of firstPartiesList) {
// account for wildcards in entries on firstPartiesList & avoid false positives
if (url_pattern.startsWith("*") && url_pattern.endsWith(domain)) {
return true;
if (url_pattern.startsWith("*")) {
// compare against pattern without '*.' and the domain without 'www.'
if (url_pattern.slice(2) == domain.slice(4)) {
return true;
}
} else if (url_pattern == domain) {
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions src/tests/tests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -584,6 +584,12 @@ QUnit.test("firstPartyProtectionsEnabled", assert => {
"determines that a url not in the firstparties list is not protected by a firstparty script"
);

assert.equal(
utils.firstPartyProtectionsEnabled("www.messenger.com", badger.firstPartiesList),
true,
"accurately IDs a site with firstparty protections covered by a wildcard url match"
);

});

})();

0 comments on commit cad1393

Please sign in to comment.