Skip to content

Commit 7958dda

Browse files
Release build 7.6.0 [ci release]
1 parent 0502ed7 commit 7958dda

File tree

10 files changed

+206
-8
lines changed

10 files changed

+206
-8
lines changed

CHANGELOG.txt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
1-
- ntp: ensure cross-window sections collapse (#1387)
2-
- Revert "removed the restriction on config subscription"
3-
- removed the restriction on config subscription
4-
- ntp: support multiple release-note lists (#1385)
1+
- Support modifying cookies (#1384)
2+
- build(deps-dev): bump @duckduckgo/privacy-configuration (#1396)

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,6 +2422,9 @@
24222422
if (this.getFeatureSettingEnabled("modifyLocalStorage")) {
24232423
this.modifyLocalStorage();
24242424
}
2425+
if (this.getFeatureSettingEnabled("modifyCookies")) {
2426+
this.modifyCookies();
2427+
}
24252428
}
24262429
/** Shim Web Share API in Android WebView */
24272430
shimWebShare() {
@@ -2824,6 +2827,20 @@
28242827
}
28252828
});
28262829
}
2830+
/**
2831+
* Support for modifying cookies
2832+
*/
2833+
modifyCookies() {
2834+
const settings = this.getFeatureSetting("modifyCookies");
2835+
if (!settings || !settings.changes) return;
2836+
settings.changes.forEach((change) => {
2837+
if (change.action === "delete") {
2838+
const pathValue = change.path ? `; path=${change.path}` : "";
2839+
const domainValue = change.domain ? `; domain=${change.domain}` : "";
2840+
document.cookie = `${change.key}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${pathValue}${domainValue}`;
2841+
}
2842+
});
2843+
}
28272844
/**
28282845
* Support for proxying `window.webkit.messageHandlers`
28292846
*/

build/android/contentScope.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7285,6 +7285,10 @@
72857285
if (this.getFeatureSettingEnabled('modifyLocalStorage')) {
72867286
this.modifyLocalStorage();
72877287
}
7288+
7289+
if (this.getFeatureSettingEnabled('modifyCookies')) {
7290+
this.modifyCookies();
7291+
}
72887292
}
72897293

72907294
/** Shim Web Share API in Android WebView */
@@ -7746,6 +7750,24 @@
77467750
});
77477751
}
77487752

7753+
/**
7754+
* Support for modifying cookies
7755+
*/
7756+
modifyCookies() {
7757+
/** @type {import('@duckduckgo/privacy-configuration/schema/features/webcompat').WebCompatSettings['modifyCookies']} */
7758+
const settings = this.getFeatureSetting('modifyCookies');
7759+
7760+
if (!settings || !settings.changes) return;
7761+
7762+
settings.changes.forEach((change) => {
7763+
if (change.action === 'delete') {
7764+
const pathValue = change.path ? `; path=${change.path}` : '';
7765+
const domainValue = change.domain ? `; domain=${change.domain}` : '';
7766+
document.cookie = `${change.key}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${pathValue}${domainValue}`;
7767+
}
7768+
});
7769+
}
7770+
77497771
/**
77507772
* Support for proxying `window.webkit.messageHandlers`
77517773
*/

build/integration/contentScope.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14168,6 +14168,10 @@
1416814168
if (this.getFeatureSettingEnabled('modifyLocalStorage')) {
1416914169
this.modifyLocalStorage();
1417014170
}
14171+
14172+
if (this.getFeatureSettingEnabled('modifyCookies')) {
14173+
this.modifyCookies();
14174+
}
1417114175
}
1417214176

1417314177
/** Shim Web Share API in Android WebView */
@@ -14625,6 +14629,24 @@
1462514629
});
1462614630
}
1462714631

14632+
/**
14633+
* Support for modifying cookies
14634+
*/
14635+
modifyCookies() {
14636+
/** @type {import('@duckduckgo/privacy-configuration/schema/features/webcompat').WebCompatSettings['modifyCookies']} */
14637+
const settings = this.getFeatureSetting('modifyCookies');
14638+
14639+
if (!settings || !settings.changes) return;
14640+
14641+
settings.changes.forEach((change) => {
14642+
if (change.action === 'delete') {
14643+
const pathValue = change.path ? `; path=${change.path}` : '';
14644+
const domainValue = change.domain ? `; domain=${change.domain}` : '';
14645+
document.cookie = `${change.key}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${pathValue}${domainValue}`;
14646+
}
14647+
});
14648+
}
14649+
1462814650
/**
1462914651
* Support for proxying `window.webkit.messageHandlers`
1463014652
*/

injected/integration-test/pages.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,14 @@ test.describe('Test integration pages', () => {
5656
`./integration-test/test-pages/webcompat/config/modify-localstorage.json`,
5757
);
5858
});
59+
60+
test('Properly modifies cookies', async ({ page }, testInfo) => {
61+
// prettier-ignore
62+
await testPage(
63+
page,
64+
testInfo,
65+
'webcompat/pages/modify-cookies.html',
66+
`./integration-test/test-pages/webcompat/config/modify-cookies.json`,
67+
);
68+
});
5969
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
{
2+
"unprotectedTemporary": [],
3+
"features": {
4+
"webCompat": {
5+
"exceptions": [],
6+
"state": "enabled",
7+
"settings": {
8+
"modifyCookies": {
9+
"state": "enabled",
10+
"changes": []
11+
},
12+
"domains": [
13+
{
14+
"domain": ["localhost", "privacy-test-pages.site"],
15+
"patchSettings": [
16+
{
17+
"op": "add",
18+
"path": "/modifyCookies/changes/-",
19+
"value": {
20+
"key": "keyToBeDeleted",
21+
"action": "delete"
22+
}
23+
},
24+
{
25+
"op": "add",
26+
"path": "/modifyCookies/changes/-",
27+
"value": {
28+
"key": "pathCookie",
29+
"action": "delete"
30+
}
31+
},
32+
{
33+
"op": "add",
34+
"path": "/modifyCookies/changes/-",
35+
"value": {
36+
"key": "pathCookieWithPath",
37+
"path": "/webcompat/pages/",
38+
"action": "delete"
39+
}
40+
},
41+
{
42+
"op": "add",
43+
"path": "/modifyCookies/changes/-",
44+
"value": {
45+
"key": "nonexistentKey",
46+
"action": "delete"
47+
}
48+
}
49+
]
50+
}
51+
]
52+
}
53+
}
54+
}
55+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Modify Cookies</title>
7+
<link rel="stylesheet" href="../../shared/style.css">
8+
<script>
9+
// Current file path
10+
let path = '/webcompat/pages/'
11+
document.cookie = 'keyToBeDeleted="valueToBeDeleted"'
12+
document.cookie = 'pathCookie="valueToBeDeleted"; path=' + path
13+
document.cookie = 'pathCookieWithPath="valueToBeDeleted"; path=' + path
14+
document.cookie = 'otherKey="valueToRemain"'
15+
</script>
16+
</head>
17+
<body>
18+
<script src="../../shared/utils.js"></script>
19+
<p><a href="../index.html">[WebCompat]</a></p>
20+
21+
<p>This page verifies that cookie modifications work properly given the <a href="../config/modify-cookies.json">config</a>. At this time, only deletion is supported.</p>
22+
23+
<script>
24+
// Copy from: https://stackoverflow.com/a/2144404
25+
function hasCookie(name){
26+
return document.cookie.split(';').some(c => {
27+
return c.trim().startsWith(name + '=');
28+
});
29+
}
30+
31+
// eslint-disable-next-line no-undef
32+
test('Only specified cookies should be removed', async () => {
33+
const specifiedKey = hasCookie('keyToBeDeleted')
34+
const pathKey = hasCookie('pathCookie')
35+
const pathKey2 = hasCookie('pathCookie2')
36+
const pathKey3 = hasCookie('pathCookieWithPath')
37+
const nonexistentKey = hasCookie('nonexistentKey')
38+
const otherKey = hasCookie('otherKey')
39+
40+
return [
41+
{ name: 'specified cookie entry deleted', result: specifiedKey, expected: false },
42+
{ name: 'specified cookie entry with path not deleted', result: pathKey, expected: true },
43+
{ name: `specified cookie entry with correct path (${path}) deleted`, result: pathKey3, expected: false },
44+
{ name: 'specified cookie entry that is not present on page load', result: nonexistentKey, expected: false },
45+
{ name: 'other cookie entry untouched', result: otherKey, expected: true }
46+
];
47+
});
48+
49+
// eslint-disable-next-line no-undef
50+
renderResults();
51+
</script>
52+
</body>
53+
</html>

injected/src/features/web-compat.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ export class WebCompat extends ContentFeature {
122122
if (this.getFeatureSettingEnabled('modifyLocalStorage')) {
123123
this.modifyLocalStorage();
124124
}
125+
126+
if (this.getFeatureSettingEnabled('modifyCookies')) {
127+
this.modifyCookies();
128+
}
125129
}
126130

127131
/** Shim Web Share API in Android WebView */
@@ -583,6 +587,24 @@ export class WebCompat extends ContentFeature {
583587
});
584588
}
585589

590+
/**
591+
* Support for modifying cookies
592+
*/
593+
modifyCookies() {
594+
/** @type {import('@duckduckgo/privacy-configuration/schema/features/webcompat').WebCompatSettings['modifyCookies']} */
595+
const settings = this.getFeatureSetting('modifyCookies');
596+
597+
if (!settings || !settings.changes) return;
598+
599+
settings.changes.forEach((change) => {
600+
if (change.action === 'delete') {
601+
const pathValue = change.path ? `; path=${change.path}` : '';
602+
const domainValue = change.domain ? `; domain=${change.domain}` : '';
603+
document.cookie = `${change.key}=; expires=Thu, 01 Jan 1970 00:00:00 GMT${pathValue}${domainValue}`;
604+
}
605+
});
606+
}
607+
586608
/**
587609
* Support for proxying `window.webkit.messageHandlers`
588610
*/

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
"playwright.config.js",
3030
"injected",
3131
"injected/src/globals.d.ts",
32-
"injected/src/features/duckplayer/duckplayer-settings.ts",
3332
"typedoc.js",
3433
".github/scripts"
3534
],

0 commit comments

Comments
 (0)