Skip to content

Commit

Permalink
Do not strip subdomains when referrer trimming (duckduckgo#2053)
Browse files Browse the repository at this point in the history
* Do not strip subdomains when referrer trimming

* Update test specs

* Bump reference-tests
  • Loading branch information
sammacbeth authored Jun 23, 2023
1 parent 625e1cb commit 6be3e70
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
18 changes: 8 additions & 10 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions shared/js/background/tracker-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,9 @@ export function truncateReferrer (referrer, target) {
return undefined
}

let modifiedReferrer = referrer
if (isTracker(target) || (fromCname && isTracker(finalURL))) {
modifiedReferrer = utils.extractLimitedDomainFromURL(referrer, { keepSubdomains: false })
} else {
modifiedReferrer = utils.extractLimitedDomainFromURL(referrer, { keepSubdomains: true })
}
// If extractLimitedDomainFromURL fails (for instance, invalid referrer URL), it
// returns undefined, (in practice, don't modify the referrer), so sometimes this value could be undefined.
return modifiedReferrer
return utils.extractLimitedDomainFromURL(referrer, { keepSubdomains: true })
}

/**
Expand Down
4 changes: 2 additions & 2 deletions unit-test/background/tracker-utils-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ describe('Tracker Utilities', () => {
name: 'target is a tracker, and referrer has a subdomain',
referrer: 'http://subdomain.siteA.com/article/1',
target: 'https://google-analytics.com/some/path',
expectedReferrer: 'http://sitea.com/'
expectedReferrer: 'http://subdomain.sitea.com/'
},
{
name: 'target is not a tracker, referrer should keep subdomain',
Expand Down Expand Up @@ -244,7 +244,7 @@ describe('Tracker Utilities', () => {
name: 'target is a tracker, referrer contains port',
referrer: 'http://subdomain.siteA.com:4000/article/1',
target: 'https://google-analytics.com/some/path',
expectedReferrer: 'http://sitea.com:4000/'
expectedReferrer: 'http://subdomain.sitea.com:4000/'
},
{
name: 'target is a tracker, referrer is localhost',
Expand Down

0 comments on commit 6be3e70

Please sign in to comment.