@duckduckgo/autoconsent 17.4.0 → 18.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +1 -0
- package/AGENTS.md +2 -0
- package/CHANGELOG.md +34 -0
- package/dist/addon-firefox/background.bundle.js +2 -0
- package/dist/addon-firefox/compact-rules.json +1 -1
- package/dist/addon-firefox/content.bundle.js +602 -53
- package/dist/addon-firefox/manifest.json +1 -1
- package/dist/addon-firefox/rule-index.json +1 -1
- package/dist/addon-firefox/rules.json +1 -1
- package/dist/addon-mv3/background.bundle.js +2 -0
- package/dist/addon-mv3/compact-rules.json +1 -1
- package/dist/addon-mv3/content.bundle.js +602 -53
- package/dist/addon-mv3/manifest.json +1 -1
- package/dist/addon-mv3/rule-index.json +1 -1
- package/dist/addon-mv3/rules.json +1 -1
- package/dist/autoconsent.cjs.js +608 -59
- package/dist/autoconsent.esm.js +608 -59
- package/dist/autoconsent.playwright.js +602 -53
- package/dist/autoconsent.standalone.js +609 -60
- package/dist/heuristics.cjs.js +621 -52
- package/dist/heuristics.mjs +609 -50
- package/dist/types/eval-snippets.d.ts +1 -0
- package/dist/types/heuristic-classify.d.ts +2 -6
- package/dist/types/heuristic-detect.d.ts +32 -0
- package/dist/types/heuristic-literals.d.ts +1 -0
- package/dist/types/heuristic-negatives.d.ts +25 -0
- package/dist/types/heuristic-patterns.d.ts +18 -2
- package/dist/types/heuristic-prefilter.d.ts +13 -0
- package/docs/heuristic-detection.md +78 -0
- package/docs/heuristic-prefilter.md +62 -0
- package/eslint.config.mjs +16 -1
- package/lib/eval-snippets.ts +2 -0
- package/lib/heuristic-classify.ts +4 -39
- package/lib/heuristic-detect.ts +209 -0
- package/lib/heuristic-literals.ts +207 -0
- package/lib/heuristic-negatives.ts +173 -0
- package/lib/heuristic-patterns.ts +104 -31
- package/lib/heuristic-prefilter.ts +40 -0
- package/lib/heuristics.ts +8 -4
- package/lib/web.ts +1 -1
- package/package.json +2 -1
- package/rules/autoconsent/binogi.json +32 -0
- package/rules/autoconsent/bokio.json +32 -0
- package/rules/autoconsent/botble-cookie-consent.json +16 -0
- package/rules/autoconsent/calcolo-tools.json +23 -0
- package/rules/autoconsent/consilium-europa-eu.json +35 -0
- package/rules/autoconsent/dtu-findit.json +47 -0
- package/rules/autoconsent/hikvision.com.json +18 -0
- package/rules/autoconsent/hurra-consent.json +16 -0
- package/rules/autoconsent/isidewith.com.json +38 -0
- package/rules/autoconsent/landgate.json +10 -0
- package/rules/autoconsent/pakamera.json +19 -0
- package/rules/autoconsent/purecookie-cosmetic.json +13 -0
- package/rules/autoconsent/random-org.json +41 -0
- package/rules/autoconsent/tallink.json +13 -0
- package/rules/autoconsent/tealium.json +4 -1
- package/rules/autoconsent/typo3-cookieconsent.json +9 -0
- package/rules/autoconsent/vinnies-org-au.json +29 -0
- package/rules/compact-rules.json +1 -1
- package/rules/rule-index.json +1 -1
- package/rules/rules.json +1 -1
- package/scripts/build-heuristic-literals.ts +24 -0
- package/scripts/required-literals.ts +177 -0
- package/tests/binogi.spec.ts +3 -0
- package/tests/bokio.spec.ts +6 -0
- package/tests/botble-cookie-consent.spec.ts +11 -0
- package/tests/calcolo-tools.spec.ts +3 -0
- package/tests/consilium-europa-eu.spec.ts +3 -0
- package/tests/dtu-findit.spec.ts +3 -0
- package/tests/hikvision.com.spec.ts +3 -0
- package/tests/hurra-consent.spec.ts +8 -0
- package/tests/isidewith.com.spec.ts +3 -0
- package/tests/landgate.spec.ts +3 -0
- package/tests/pakamera.spec.ts +5 -0
- package/tests/purecookie-cosmetic.spec.ts +8 -0
- package/tests/random-org.spec.ts +3 -0
- package/tests/tallink.spec.ts +3 -0
- package/tests/typo3-cookieconsent.spec.ts +10 -0
- package/tests/vinnies-org-au.spec.ts +3 -0
- package/tests-wtr/heuristics/heuristics-utils.test.ts +222 -8
- package/tests-wtr/heuristics/regex-syntax.test.ts +81 -0
- package/rules/generated/auto_NL_bonprix.nl_ovi.json +0 -40
- package/tests/generated/auto_NL_bonprix.nl_ovi.spec.ts +0 -2
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { expect } from '@esm-bundle/chai';
|
|
2
|
+
import {
|
|
3
|
+
ACCEPT_PATTERNS,
|
|
4
|
+
ACKNOWLEDGE_PATTERNS,
|
|
5
|
+
BUTTON_NEVER_MATCH_PATTERNS,
|
|
6
|
+
DETECT_CONTEXT_NEGATIVES,
|
|
7
|
+
DETECT_PATTERNS,
|
|
8
|
+
REJECT_PATTERNS,
|
|
9
|
+
SETTINGS_PATTERNS,
|
|
10
|
+
} from '../../lib/heuristic-classify';
|
|
11
|
+
import { patternOf } from '../../lib/heuristic-patterns';
|
|
12
|
+
import { alternatives, classEnd, groupEnd } from '../../scripts/required-literals';
|
|
13
|
+
|
|
14
|
+
const nonAsciiLetter = (c: string | undefined) => c !== undefined && c.charCodeAt(0) > 127 && /\p{L}/u.test(c);
|
|
15
|
+
|
|
16
|
+
/** The top-level alternatives of the group that opens at src[open], and where it closes. */
|
|
17
|
+
function groupAlternatives(src: string, open: number): { alts: string[]; close: number } {
|
|
18
|
+
const close = groupEnd(src, open);
|
|
19
|
+
const from = src.startsWith('(?:', open) ? open + 3 : open + 1;
|
|
20
|
+
return { alts: alternatives(src.slice(from, close)), close };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Places where a regex without the u flag has \b next to a non-ASCII letter, which it treats as a non-word character,
|
|
25
|
+
* so the boundary never matches between that letter and a space.
|
|
26
|
+
*/
|
|
27
|
+
function accentBoundaries(re: RegExp): string[] {
|
|
28
|
+
if (re.flags.includes('u')) {
|
|
29
|
+
return [];
|
|
30
|
+
}
|
|
31
|
+
const src = re.source;
|
|
32
|
+
const found: string[] = [];
|
|
33
|
+
const groupOpens = new Map<number, number>();
|
|
34
|
+
for (let i = 0; i < src.length; i++) {
|
|
35
|
+
if (src[i] === '\\') {
|
|
36
|
+
i++;
|
|
37
|
+
} else if (src[i] === '[') {
|
|
38
|
+
i = classEnd(src, i);
|
|
39
|
+
} else if (src[i] === '(') {
|
|
40
|
+
groupOpens.set(groupEnd(src, i), i);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
for (let i = 0; i < src.length - 1; i++) {
|
|
44
|
+
if (src[i] !== '\\') {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (src[i + 1] === 'b') {
|
|
48
|
+
const next = src[i + 2];
|
|
49
|
+
const after = next === '(' ? groupAlternatives(src, i + 2).alts.map((a) => a[0]) : [next];
|
|
50
|
+
const open = groupOpens.get(i - 1);
|
|
51
|
+
const before = open !== undefined ? groupAlternatives(src, open).alts.map((a) => a[a.length - 1]) : [src[i - 1]];
|
|
52
|
+
if ([...after, ...before].some(nonAsciiLetter)) {
|
|
53
|
+
found.push(src.slice(Math.max(0, i - 15), i + 17));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
i++;
|
|
57
|
+
}
|
|
58
|
+
return found;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
describe('heuristic regex syntax', () => {
|
|
62
|
+
const regexes: RegExp[] = [
|
|
63
|
+
...DETECT_PATTERNS.map(patternOf),
|
|
64
|
+
...DETECT_CONTEXT_NEGATIVES.flatMap((n) => [n.pattern, n.unless].filter((r): r is RegExp => r instanceof RegExp)),
|
|
65
|
+
...[REJECT_PATTERNS, SETTINGS_PATTERNS, ACCEPT_PATTERNS, ACKNOWLEDGE_PATTERNS, BUTTON_NEVER_MATCH_PATTERNS]
|
|
66
|
+
.flat()
|
|
67
|
+
.filter((p): p is RegExp => p instanceof RegExp),
|
|
68
|
+
];
|
|
69
|
+
|
|
70
|
+
it('finds the boundaries it checks for', () => {
|
|
71
|
+
expect(accentBoundaries(/\b(?:x|âge)\b/i)).to.have.length(1);
|
|
72
|
+
expect(accentBoundaries(/età\b/i)).to.have.length(1);
|
|
73
|
+
expect(accentBoundaries(/\bage\b/i)).to.have.length(0);
|
|
74
|
+
expect(accentBoundaries(/\bâge\b/iu)).to.have.length(0);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('has no \\b next to an accented letter', () => {
|
|
78
|
+
const bad = regexes.flatMap((re) => accentBoundaries(re).map((at) => `${String(re).slice(0, 60)}: …${at}…`));
|
|
79
|
+
expect(bad).to.deep.equal([]);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "auto_NL_bonprix.nl_ovi",
|
|
3
|
-
"cosmetic": false,
|
|
4
|
-
"_metadata": {
|
|
5
|
-
"vendorUrl": "http://www.bonprix.nl/"
|
|
6
|
-
},
|
|
7
|
-
"runContext": {
|
|
8
|
-
"main": true,
|
|
9
|
-
"frame": false,
|
|
10
|
-
"urlPattern": "^https?://(www\\.)?bonprix\\.nl/"
|
|
11
|
-
},
|
|
12
|
-
"prehideSelectors": [],
|
|
13
|
-
"detectCmp": [
|
|
14
|
-
{
|
|
15
|
-
"exists": "body > div#cookie-bar-2019 > div:nth-child(4):not([id]) > a#declineLink"
|
|
16
|
-
}
|
|
17
|
-
],
|
|
18
|
-
"detectPopup": [
|
|
19
|
-
{
|
|
20
|
-
"visible": "body > div#cookie-bar-2019 > div:nth-child(4):not([id]) > a#declineLink"
|
|
21
|
-
}
|
|
22
|
-
],
|
|
23
|
-
"optIn": [],
|
|
24
|
-
"optOut": [
|
|
25
|
-
{
|
|
26
|
-
"wait": 500
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
"waitForThenClick": "body > div#cookie-bar-2019 > div:nth-child(4):not([id]) > a#declineLink",
|
|
30
|
-
"comment": "hier weigeren"
|
|
31
|
-
}
|
|
32
|
-
],
|
|
33
|
-
"test": [
|
|
34
|
-
{
|
|
35
|
-
"waitForVisible": "body > div#cookie-bar-2019 > div:nth-child(4):not([id]) > a#declineLink",
|
|
36
|
-
"timeout": 1000,
|
|
37
|
-
"check": "none"
|
|
38
|
-
}
|
|
39
|
-
]
|
|
40
|
-
}
|