Skip to content

Commit

Permalink
Simpler cookie policy (#1204)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston committed May 30, 2022
1 parent 83871fc commit 11bb055
Show file tree
Hide file tree
Showing 8 changed files with 162 additions and 30 deletions.
5 changes: 2 additions & 3 deletions integration-test/background/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,9 @@ describe('Storage blocking Tests', () => {
expect(jsCookie.expires).toBeGreaterThan(Date.now() / 1000)
})

it('does not block 3rd party JS cookies not on block list', () => {
it('does block 3rd party JS cookies not on block list', () => {
const jsCookie = cookies.find(({ name, domain }) => name === 'jsdata' && domain === thirdPartyDomain)
expect(jsCookie).toBeTruthy()
expect(jsCookie.expires).toBeGreaterThan(Date.now() / 1000)
expect(jsCookie).toBeUndefined()
})

it('blocks 3rd party JS cookies from trackers', () => {
Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"release": "grunt build",
"lint": "eslint '*.js' shared/js shared/data unit-test integration-test scripts",
"lint-fix": "npm run lint -- --fix",
"test": "grunt test --browser=chrome --type=dev",
"test": "npm run copy-modules; grunt test --browser=chrome --type=dev",
"test-debug": "grunt test --browser=chrome --type=dev --test-debug",
"test-int": "make setup-artifacts-dir && make dev browser=chrome type=dev && jasmine --config=integration-test/config.json",
"test-int-mv3": "make setup-artifacts-dir && make dev browser=chrome-mv3 type=dev && jasmine --config=integration-test/config-mv3.json",
Expand Down Expand Up @@ -70,7 +70,7 @@
},
"dependencies": {
"@duckduckgo/autofill": "github:duckduckgo/duckduckgo-autofill#4.5.0",
"@duckduckgo/content-scope-scripts": "github:duckduckgo/content-scope-scripts#1.3.0",
"@duckduckgo/content-scope-scripts": "github:duckduckgo/content-scope-scripts#2.0.1",
"@duckduckgo/jsbloom": "^1.0.2",
"@duckduckgo/privacy-grade": "1.1.0",
"bel": "6.0.0",
Expand Down
130 changes: 129 additions & 1 deletion shared/data/bundled/extension-config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"readme": "https://github.com/duckduckgo/privacy-configuration",
"version": 1653487115722,
"version": 1653680846662,
"features": {
"ampLinks": {
"exceptions": [
Expand Down Expand Up @@ -144,6 +144,134 @@
}
]
},
"cookie": {
"exceptions": [
{
"domain": "nespresso.com",
"reason": "login issues"
}
],
"state": "enabled",
"settings": {
"trackerCookie": "enabled",
"nonTrackerCookie": "enabled",
"excludedCookieDomains": [
{
"domain": "hangouts.google.com",
"reason": "Site breakage"
},
{
"domain": "docs.google.com",
"reason": "Site breakage"
},
{
"domain": "accounts.google.com",
"reason": "SSO which needs cookies for auth"
},
{
"domain": "googleapis.com",
"reason": "Site breakage"
},
{
"domain": "login.live.com",
"reason": "SSO which needs cookies for auth"
},
{
"domain": "apis.google.com",
"reason": "Site breakage"
},
{
"domain": "pay.google.com",
"reason": "Site breakage"
},
{
"domain": "payments.amazon.com",
"reason": "Site breakage"
},
{
"domain": "payments.amazon.de",
"reason": "Site breakage"
},
{
"domain": "atlassian.net",
"reason": "Site breakage"
},
{
"domain": "atlassian.com",
"reason": "Site breakage"
},
{
"domain": "paypal.com",
"reason": "Site breakage"
},
{
"domain": "paypal.com",
"reason": "site breakage"
},
{
"domain": "salesforce.com",
"reason": "Site breakage"
},
{
"domain": "salesforceliveagent.com",
"reason": "Site breakage"
},
{
"domain": "force.com",
"reason": "Site breakage"
},
{
"domain": "disqus.com",
"reason": "Site breakage"
},
{
"domain": "spotify.com",
"reason": "Site breakage"
},
{
"domain": "hangouts.google.com",
"reason": "site breakage"
},
{
"domain": "docs.google.com",
"reason": "site breakage"
},
{
"domain": "btsport-utils-prod.akamaized.net",
"reason": "broken videos"
}
],
"firstPartyTrackerCookiePolicy": {
"threshold": 86400,
"maxAge": 86400
}
}
},
"customUserAgent": {
"settings": {
"omitApplicationSites": [
{
"domain": "cvs.com",
"reason": "Site reports browser not supported"
},
{
"domain": "sovietgames.su",
"reason": "Wordpress plugin reports our browser as a bot"
},
{
"domain": "accounts.google.com",
"reason": "Site reports browser not supported"
},
{
"domain": "facebook.com",
"reason": "Site reports browser not supported"
}
],
"omitVersionSites": []
},
"exceptions": [],
"state": "disabled"
},
"fingerprintingAudio": {
"state": "disabled",
"exceptions": [
Expand Down
2 changes: 1 addition & 1 deletion shared/data/etags.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"config-etag":"W/\"09fa14b9e65122d55e9f024922140627\""}
{"config-etag":"W/\"31aa5ee26bd18ce87deda211ab2494f4\""}
33 changes: 17 additions & 16 deletions shared/js/background/helpers/arguments-object.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,8 @@ function getArgumentsObject (tabId, sender, documentUrl, sessionKey) {
// Clone site so we don't retain any site changes
const site = Object.assign({}, tab.site || {})
const referrer = tab?.referrer || ''
let cookie = {}

const firstPartyCookiePolicy = utils.getFeatureSettings('trackingCookies1p').firstPartyTrackerCookiePolicy || {
threshold: 864000, // 10 days
maxAge: 864000 // 10 days
}
const cookie = {
isThirdParty: false,
shouldBlock: false,
tabRegisteredDomain: null,
isTrackerFrame: false,
policy: firstPartyCookiePolicy
}
// Special case for iframes that are blank we check if it's also enabled
if (sender.url === 'about:blank') {
const aboutBlankEnabled = utils.getEnabledFeaturesAboutBlank(tab.url)
Expand All @@ -40,17 +30,28 @@ function getArgumentsObject (tabId, sender, documentUrl, sessionKey) {
}
}

// Extra contextual data required for 1p and 3p cookie protection - only send if at least one is enabled here
if (tab.site.isFeatureEnabled('trackingCookies3p') || tab.site.isFeatureEnabled('trackingCookies1p')) {
// Extra contextual data required for cookie protection only send if is enabled here
if (tab.site.isFeatureEnabled('cookie')) {
cookie = {
isThirdParty: false,
shouldBlock: false,
tabRegisteredDomain: null,
isTracker: false,
isFrame: false
}

// determine the register domain of the sending tab
const parsed = tldts.parse(tab.url)
cookie.tabRegisteredDomain = parsed.domain === null ? parsed.hostname : parsed.domain

if (sender.frameId !== 0) {
cookie.isFrame = true
}

if (trackerutils.hasTrackerListLoaded()) {
if (documentUrl &&
trackerutils.isTracker(documentUrl) &&
sender.frameId !== 0) {
cookie.isTrackerFrame = true
trackerutils.isTracker(documentUrl)) {
cookie.isTracker = true
}
cookie.isThirdParty = !trackerutils.isFirstPartyByEntity(documentUrl, tab.url)
}
Expand Down
3 changes: 2 additions & 1 deletion unit-test/background/reference-tests/3p-cookies-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const getArgumentsObject = require('../../../shared/js/background/helpers/argume

const jsdom = require('jsdom')

const trackingJsCookieProtection = require('../../../shared/content-scope-scripts/src/features/tracking-cookies-3p')
const trackingJsCookieProtection = require('../../../shared/content-scope-scripts/src/features/cookie')

const trackingConfigReference = require('../../data/reference-tests/block-third-party-tracking-cookies/config_reference.json')
const trackingBlocklistReference = require('../../data/reference-tests/block-third-party-tracking-cookies/tracker_radar_reference.json')
Expand Down Expand Up @@ -104,6 +104,7 @@ function runTestSuite (suiteType, testSet, jsCookieProtection, configReference,
// eslint-disable-next-line no-global-assign
globalThis = jsdomWindow

jsCookieProtection.load()
jsCookieProtection.init(args)

jsdomWindow.document.cookie = test.setDocumentCookie
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ const tabManager = require('../../../shared/js/background/tab-manager.es6')
const browserWrapper = require('../../../shared/js/background/wrapper.es6')
const getArgumentsObject = require('../../../shared/js/background/helpers/arguments-object')

const jsCookieProtection = require('../../../shared/content-scope-scripts/src/features/tracking-cookies-1p')

const configReference = require('../../data/reference-tests/expire-first-party-tracking-cookies/config_reference.json')
const blocklistReference = require('../../data/reference-tests/expire-first-party-tracking-cookies/tracker_radar_reference.json')
const testSets = require('../../data/reference-tests/expire-first-party-tracking-cookies/tests.json')
Expand Down Expand Up @@ -67,6 +65,11 @@ for (const setName of Object.keys(testSets)) {
// eslint-disable-next-line no-global-assign
globalThis = jsdomWindow

const utils = require('../../../shared/content-scope-scripts/src/utils')
utils.setGlobal(jsdomWindow)

const jsCookieProtection = require('../../../shared/content-scope-scripts/src/features/cookie')

jsCookieProtection.load({})
jsCookieProtection.init(args)

Expand Down

0 comments on commit 11bb055

Please sign in to comment.