@duckduckgo/autoconsent 17.4.0 → 18.1.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.
Files changed (102) hide show
  1. package/.github/workflows/ddg-release.yml +6 -3
  2. package/.prettierignore +1 -0
  3. package/AGENTS.md +2 -0
  4. package/CHANGELOG.md +57 -0
  5. package/dist/addon-firefox/background.bundle.js +4 -1
  6. package/dist/addon-firefox/compact-rules.json +1 -1
  7. package/dist/addon-firefox/content.bundle.js +608 -61
  8. package/dist/addon-firefox/manifest.json +1 -1
  9. package/dist/addon-firefox/rule-index.json +1 -1
  10. package/dist/addon-firefox/rules.json +1 -1
  11. package/dist/addon-mv3/background.bundle.js +4 -1
  12. package/dist/addon-mv3/compact-rules.json +1 -1
  13. package/dist/addon-mv3/content.bundle.js +608 -61
  14. package/dist/addon-mv3/manifest.json +1 -1
  15. package/dist/addon-mv3/rule-index.json +1 -1
  16. package/dist/addon-mv3/rules.json +1 -1
  17. package/dist/autoconsent.cjs.js +614 -67
  18. package/dist/autoconsent.esm.js +614 -67
  19. package/dist/autoconsent.playwright.js +608 -61
  20. package/dist/autoconsent.standalone.js +615 -68
  21. package/dist/heuristics.cjs.js +621 -52
  22. package/dist/heuristics.mjs +609 -50
  23. package/dist/types/cmps/tiktok.d.ts +0 -2
  24. package/dist/types/eval-snippets.d.ts +2 -0
  25. package/dist/types/heuristic-classify.d.ts +2 -6
  26. package/dist/types/heuristic-detect.d.ts +32 -0
  27. package/dist/types/heuristic-literals.d.ts +1 -0
  28. package/dist/types/heuristic-negatives.d.ts +25 -0
  29. package/dist/types/heuristic-patterns.d.ts +18 -2
  30. package/dist/types/heuristic-prefilter.d.ts +13 -0
  31. package/docs/heuristic-detection.md +78 -0
  32. package/docs/heuristic-prefilter.md +62 -0
  33. package/eslint.config.mjs +16 -1
  34. package/lib/cmps/evidon.ts +5 -4
  35. package/lib/cmps/tiktok.ts +0 -5
  36. package/lib/eval-snippets.ts +3 -0
  37. package/lib/heuristic-classify.ts +4 -39
  38. package/lib/heuristic-detect.ts +209 -0
  39. package/lib/heuristic-literals.ts +207 -0
  40. package/lib/heuristic-negatives.ts +173 -0
  41. package/lib/heuristic-patterns.ts +104 -31
  42. package/lib/heuristic-prefilter.ts +40 -0
  43. package/lib/heuristics.ts +8 -4
  44. package/lib/web.ts +1 -1
  45. package/package.json +2 -1
  46. package/rules/autoconsent/binogi.json +32 -0
  47. package/rules/autoconsent/bokio.json +32 -0
  48. package/rules/autoconsent/botble-cookie-consent.json +16 -0
  49. package/rules/autoconsent/calcolo-tools.json +23 -0
  50. package/rules/autoconsent/consilium-europa-eu.json +35 -0
  51. package/rules/autoconsent/dtu-findit.json +47 -0
  52. package/rules/autoconsent/hikvision.com.json +18 -0
  53. package/rules/autoconsent/hmgroup-turbocookie.json +18 -0
  54. package/rules/autoconsent/hmrc-tracking-consent.json +40 -0
  55. package/rules/autoconsent/hurra-consent.json +16 -0
  56. package/rules/autoconsent/isidewith.com.json +38 -0
  57. package/rules/autoconsent/landgate.json +10 -0
  58. package/rules/autoconsent/meta-cookie-dialog-v2.json +40 -0
  59. package/rules/autoconsent/pakamera.json +19 -0
  60. package/rules/autoconsent/purecookie-cosmetic.json +13 -0
  61. package/rules/autoconsent/random-org.json +41 -0
  62. package/rules/autoconsent/reverb-gdpr-nag.json +18 -0
  63. package/rules/autoconsent/reverb.json +24 -0
  64. package/rules/autoconsent/tallink.json +13 -0
  65. package/rules/autoconsent/tealium.json +4 -1
  66. package/rules/autoconsent/typo3-cookieconsent.json +9 -0
  67. package/rules/autoconsent/vinnies-org-au.json +29 -0
  68. package/rules/autoconsent/zoho.json +23 -0
  69. package/rules/compact-rules.json +1 -1
  70. package/rules/rule-index.json +1 -1
  71. package/rules/rules.json +1 -1
  72. package/scripts/build-heuristic-literals.ts +24 -0
  73. package/scripts/required-literals.ts +177 -0
  74. package/tests/binogi.spec.ts +3 -0
  75. package/tests/bokio.spec.ts +6 -0
  76. package/tests/botble-cookie-consent.spec.ts +11 -0
  77. package/tests/calcolo-tools.spec.ts +3 -0
  78. package/tests/consilium-europa-eu.spec.ts +3 -0
  79. package/tests/dtu-findit.spec.ts +3 -0
  80. package/tests/evidon.spec.ts +2 -1
  81. package/tests/hikvision.com.spec.ts +3 -0
  82. package/tests/hmgroup-turbocookie.spec.ts +7 -0
  83. package/tests/hmrc-tracking-consent.spec.ts +7 -0
  84. package/tests/hurra-consent.spec.ts +8 -0
  85. package/tests/isidewith.com.spec.ts +3 -0
  86. package/tests/landgate.spec.ts +3 -0
  87. package/tests/meta-cookie-dialog-v2.spec.ts +10 -0
  88. package/tests/pakamera.spec.ts +5 -0
  89. package/tests/purecookie-cosmetic.spec.ts +8 -0
  90. package/tests/random-org.spec.ts +3 -0
  91. package/tests/reverb.spec.ts +7 -0
  92. package/tests/tallink.spec.ts +3 -0
  93. package/tests/tiktok.spec.ts +2 -2
  94. package/tests/typo3-cookieconsent.spec.ts +10 -0
  95. package/tests/vinnies-org-au.spec.ts +3 -0
  96. package/tests/zoho.spec.ts +5 -0
  97. package/tests-wtr/heuristics/heuristics-utils.test.ts +222 -8
  98. package/tests-wtr/heuristics/regex-syntax.test.ts +81 -0
  99. package/rules/generated/auto_GB_capcut.com_0.json +0 -28
  100. package/rules/generated/auto_NL_bonprix.nl_ovi.json +0 -40
  101. package/tests/generated/auto_GB_capcut.com_0.spec.ts +0 -2
  102. package/tests/generated/auto_NL_bonprix.nl_ovi.spec.ts +0 -2
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Matching heuristic detect patterns against a text: input scopes, the required-literal prefilter and context negatives.
3
+ * Text only, no DOM APIs. See docs/heuristic-detection.md.
4
+ */
5
+ import { DETECT_PATTERNS, DetectPattern, HeuristicInput, patternOf } from './heuristic-patterns';
6
+ import { ContextNegative, DETECT_CONTEXT_NEGATIVES, TextTest } from './heuristic-negatives';
7
+ import { DETECT_PATTERN_LITERALS } from './heuristic-literals';
8
+ import { literalIndex } from './heuristic-prefilter';
9
+
10
+ const TEXT_LIMIT = 100000;
11
+ const DEFAULT_WINDOW = 150;
12
+
13
+ type CompiledNegative = ContextNegative & { hits: (context: string) => boolean; applies: Set<string> | null };
14
+ type CompiledPattern = { id: string; pattern: RegExp; global: RegExp; input?: HeuristicInput; literals: string[] };
15
+
16
+ // Prefilter literals of the built-in patterns, by regex, from the generated table in DETECT_PATTERNS order. A table of
17
+ // another length (stale) is ignored: no pattern is skipped. A pattern without an entry, such as a custom one, never is.
18
+ let builtinLiterals: Map<RegExp, string[]> | undefined;
19
+ function literalsOf(pattern: RegExp): string[] {
20
+ if (!builtinLiterals) {
21
+ const fresh = DETECT_PATTERN_LITERALS.length === DETECT_PATTERNS.length;
22
+ builtinLiterals = new Map(fresh ? DETECT_PATTERNS.map((p, i) => [patternOf(p), DETECT_PATTERN_LITERALS[i]]) : []);
23
+ }
24
+ return builtinLiterals.get(pattern) ?? [];
25
+ }
26
+ // every pattern's literals come from the built-in table, so its index covers custom lists too
27
+ let index: ReturnType<typeof literalIndex> | undefined;
28
+ const literalsIn = (lower: string) => (index ??= literalIndex(DETECT_PATTERN_LITERALS.flat())).present(lower);
29
+
30
+ const truncate = (text: string) => (text || '').slice(0, TEXT_LIMIT);
31
+ // whether a pattern or negative applies to this input
32
+ const forInput = (scoped: { input?: HeuristicInput }, input?: HeuristicInput) => !scoped.input || scoped.input === input;
33
+ // a regex without the global and sticky flags, so `test` keeps no state between calls
34
+ const stateless = (re: RegExp) => new RegExp(re.source, re.flags.replace(/[gy]/g, ''));
35
+ // a TextTest as a predicate
36
+ function toPredicate(test: TextTest): (text: string) => boolean {
37
+ if (typeof test === 'function') {
38
+ return test;
39
+ }
40
+ const re = stateless(test);
41
+ return (text) => re.test(text);
42
+ }
43
+
44
+ const compiledPatterns = new WeakMap<DetectPattern[], CompiledPattern[]>();
45
+ const compiledNegatives = new WeakMap<ContextNegative[], CompiledNegative[]>();
46
+
47
+ function compilePatterns(detectPatterns: DetectPattern[]): CompiledPattern[] {
48
+ let compiled = compiledPatterns.get(detectPatterns);
49
+ if (!compiled) {
50
+ compiled = detectPatterns.map((p) => {
51
+ const pattern = patternOf(p);
52
+ const input = p instanceof RegExp ? undefined : p.input;
53
+ const global = pattern.flags.includes('g') ? pattern : new RegExp(pattern.source, `${pattern.flags}g`);
54
+ return { id: pattern.toString(), pattern, global, input, literals: literalsOf(pattern) };
55
+ });
56
+ compiledPatterns.set(detectPatterns, compiled);
57
+ }
58
+ return compiled;
59
+ }
60
+
61
+ function compileNegatives(negatives: ContextNegative[]): CompiledNegative[] {
62
+ let compiled = compiledNegatives.get(negatives);
63
+ if (!compiled) {
64
+ compiled = negatives.map((n) => {
65
+ const pattern = n.pattern ? stateless(n.pattern) : null;
66
+ const unless = n.unless ? toPredicate(n.unless) : null;
67
+ return {
68
+ ...n,
69
+ hits: (context: string) => (!pattern || pattern.test(context)) && !(unless && unless(context)),
70
+ applies: n.appliesTo ? new Set(n.appliesTo.map(String)) : null,
71
+ };
72
+ });
73
+ compiledNegatives.set(negatives, compiled);
74
+ }
75
+ return compiled;
76
+ }
77
+
78
+ /** The text around a match that a context negative is tested on. */
79
+ export function negativeContext(text: string, start: number, end: number, negative: ContextNegative): string {
80
+ if (negative.whole) {
81
+ return text;
82
+ }
83
+ if (negative.lines === undefined) {
84
+ const w = negative.window ?? DEFAULT_WINDOW;
85
+ return text.slice(Math.max(0, start - w), end + w);
86
+ }
87
+ const lineEnd = (i: number) => {
88
+ const next = text.indexOf('\n', i);
89
+ return next === -1 ? text.length : next;
90
+ };
91
+ const [before, after] = Array.isArray(negative.lines) ? negative.lines : [negative.lines, negative.lines];
92
+ let from = start > 0 ? text.lastIndexOf('\n', start - 1) + 1 : 0;
93
+ let to = lineEnd(end);
94
+ for (let i = 0; i < before; i++) {
95
+ from = from >= 2 ? text.lastIndexOf('\n', from - 2) + 1 : 0;
96
+ }
97
+ for (let i = 0; i < after; i++) {
98
+ to = to < text.length ? lineEnd(to + 1) : to;
99
+ }
100
+ return text.slice(from, to);
101
+ }
102
+
103
+ /**
104
+ * Matches the detect patterns against a text. `input` says what the text is: a popup element's text or a whole page's;
105
+ * patterns and context negatives scoped to the other input are skipped (without it, only unscoped ones apply). A
106
+ * pattern counts if one of its matches survives the context negatives; `suppressed` lists those that didn't.
107
+ * `patterns` and `negatives` replace the built-in lists.
108
+ */
109
+ export function checkHeuristicPatterns(allText: string, input?: HeuristicInput, options: HeuristicPatternOptions = {}) {
110
+ return matchHeuristicPatterns(allText, input, options, false);
111
+ }
112
+
113
+ // same result as checking checkHeuristicPatterns() for patterns, but stops at the first match
114
+ export function hasHeuristicPatterns(allText: string, input?: HeuristicInput, options: HeuristicPatternOptions = {}): boolean {
115
+ return matchHeuristicPatterns(allText, input, options, true).patterns.length > 0;
116
+ }
117
+
118
+ export type HeuristicPatternOptions = { patterns?: DetectPattern[]; negatives?: ContextNegative[] };
119
+
120
+ function matchHeuristicPatterns(
121
+ allText: string,
122
+ input: HeuristicInput | undefined,
123
+ { patterns: detectPatterns = DETECT_PATTERNS, negatives = DETECT_CONTEXT_NEGATIVES }: HeuristicPatternOptions,
124
+ firstOnly: boolean,
125
+ ) {
126
+ // the second argument used to be a pattern list: fail loudly rather than silently use the built-in patterns
127
+ if (input !== undefined && input !== 'popup' && input !== 'page') {
128
+ const got = Array.isArray(input) ? 'a pattern list (pass it as the `patterns` option)' : JSON.stringify(input);
129
+ throw new TypeError(`heuristic input must be 'popup', 'page' or undefined, got ${got}`);
130
+ }
131
+ allText = truncate(allText);
132
+ const patterns = [];
133
+ const snippets = [];
134
+ const suppressed: { pattern: string; negative: string }[] = [];
135
+ const applicable = compileNegatives(negatives).filter((n) => forInput(n, input));
136
+ let present: Set<string> | undefined;
137
+ // a whole-text negative gives the same answer for every match, so it is tested once
138
+ const wholeHits = new Map<CompiledNegative, boolean>();
139
+ const hitsAt = (n: CompiledNegative, start: number, end: number) => {
140
+ if (!n.whole) {
141
+ return n.hits(negativeContext(allText, start, end, n));
142
+ }
143
+ let hit = wholeHits.get(n);
144
+ if (hit === undefined) {
145
+ hit = n.hits(allText);
146
+ wholeHits.set(n, hit);
147
+ }
148
+ return hit;
149
+ };
150
+
151
+ for (const d of compilePatterns(detectPatterns)) {
152
+ if (!forInput(d, input)) {
153
+ continue;
154
+ }
155
+ if (d.literals.length) {
156
+ const inText = (present ??= literalsIn(allText.toLowerCase()));
157
+ if (!d.literals.some((l) => inText.has(l))) {
158
+ continue;
159
+ }
160
+ }
161
+ const own = applicable.filter((n) => !n.applies || n.applies.has(d.id));
162
+ const matched: string[] = [];
163
+ const dropped = new Set<string>();
164
+ let found = false;
165
+ let kept = own.length === 0;
166
+ // one pass: negatives are tested until a match survives them; matchAll clones the regex, so the shared global
167
+ // copy keeps no state
168
+ for (const m of allText.matchAll(d.global)) {
169
+ found = true;
170
+ if (!kept) {
171
+ const start = m.index ?? 0;
172
+ const hit = own.find((n) => hitsAt(n, start, start + m[0].length));
173
+ if (hit) {
174
+ dropped.add(hit.name);
175
+ } else {
176
+ kept = true;
177
+ }
178
+ }
179
+ if (kept && firstOnly) {
180
+ break;
181
+ }
182
+ matched.push(m[0].substring(0, 200));
183
+ }
184
+ if (!found) {
185
+ continue;
186
+ }
187
+ if (!kept) {
188
+ dropped.forEach((negative) => suppressed.push({ pattern: d.id, negative }));
189
+ continue;
190
+ }
191
+ patterns.push(d.id);
192
+ if (firstOnly) {
193
+ break;
194
+ }
195
+ snippets.push(...matched);
196
+ }
197
+ return { patterns, snippets, suppressed };
198
+ }
199
+
200
+ /**
201
+ * Names of the whole-text context negatives that exclude a text as this input, whether or not detect patterns match it:
202
+ * why a popup is not a consent popup.
203
+ */
204
+ export function excludedBy(text: string, input?: HeuristicInput, negatives: ContextNegative[] = DETECT_CONTEXT_NEGATIVES): string[] {
205
+ const truncated = truncate(text);
206
+ return compileNegatives(negatives)
207
+ .filter((n) => n.whole && forInput(n, input) && n.hits(truncated))
208
+ .map((n) => n.name);
209
+ }
@@ -0,0 +1,207 @@
1
+ // Generated by `npm run build-heuristic-literals` from DETECT_PATTERNS. Do not edit.
2
+ // Entry i holds the literals DETECT_PATTERNS[i] needs to match (see docs/heuristic-prefilter.md).
3
+ export const DETECT_PATTERN_LITERALS: string[][] = [
4
+ ["accept cookies"],
5
+ ["accept all"],
6
+ ["reject all"],
7
+ ["only necessary cookies"],
8
+ [],
9
+ [],
10
+ [" cookies"],
11
+ ["we are using cookies"],
12
+ ["use of cookies"],
13
+ ["website uses cookies to enhance your browsing experience"],
14
+ ["cookies"],
15
+ [" technologies"],
16
+ ["such as cookies"],
17
+ ["read more about"],
18
+ ["consent to"],
19
+ ["we and our partners"],
20
+ ["information"],
21
+ ["store and/or access information"],
22
+ ["personalised ads and content, ad and content measurement"],
23
+ [" and/or access"],
24
+ ["and our partners ask for your consent"],
25
+ ["we and "],
26
+ ["partners","partnern","partner","partenaires","socios","vendors","fornitori"],
27
+ ["partner"],
28
+ ["technolog"],
29
+ ["cookies"],
30
+ ["cookies"],
31
+ ["optional","additional","non-essential"],
32
+ ["storing of cookies","placed cookies"],
33
+ [" on your device","access and store "],
34
+ ["we use "],
35
+ ["out of "],
36
+ ["out of the sale"],
37
+ ["this website or its third"],
38
+ ["information"],
39
+ ["rights with regard to the sale"],
40
+ ["we use technologies "],
41
+ ["continue reading with advertising"," tracking"],
42
+ ["consent and continue"],
43
+ ["store or retrieve information on your browser","stockées dans votre navigateur ou récupérées"],
44
+ ["utilisons"],
45
+ ["cookies"],
46
+ ["consentement"],
47
+ ["partenaires"],
48
+ ["publicités"],
49
+ ["utilise"],
50
+ ["utilisent"],
51
+ ["stocker"],
52
+ ["consentement"],
53
+ ["consentement"],
54
+ ["accepter"],
55
+ ["utilisation"],
56
+ ["technologies"],
57
+ ["utilisation"],
58
+ ["continuer sans accepter"],
59
+ ["tout refuser"],
60
+ [" tous les cookies"],
61
+ ["je refuse"],
62
+ ["refuser et continuer"],
63
+ ["refuser les cookies"],
64
+ ["seulement nécessaires"],
65
+ ["je désactive les finalités non essentielles"],
66
+ ["cookies essentiels uniquement"],
67
+ ["nécessaires uniquement"],
68
+ ["stocker","stockons"],
69
+ ["nos partenaires demandent votre consentement"],
70
+ ["consentez à l"," cookies"],
71
+ ["les cookies nous permettent","nos partenaires et nous"],
72
+ ["accepter "],
73
+ ["verwenden"],
74
+ ["partner"],
75
+ ["zugriff auf informationen auf"],
76
+ ["werbeleistung"],
77
+ ["cookies"],
78
+ ["verwendung"],
79
+ ["cookies"],
80
+ ["verwendet"],
81
+ ["auswahl"],
82
+ ["technologien"],
83
+ ["verwenden"],
84
+ ["ablehnen"],
85
+ ["zusätzliche","essenzielle","funktionale","notwendige","erforderliche"],
86
+ ["einwilligung","zustimmung","cookies"],
87
+ ["ablehnen"],
88
+ ["nur funktionale cookies akzeptieren"],
89
+ ["optionale ablehnen"],
90
+ ["zustimmung verweigern"],
91
+ ["speichern und/oder "],
92
+ ["unsere partner bitten um ihre zustimmung"],
93
+ [" cookies"],
94
+ ["cookies "],
95
+ [" zum einsatz","einsatz von cookies"],
96
+ ["einverstanden","einverstanden"],
97
+ ["akzeptieren","zulassen","erlauben","zustimmen"],
98
+ ["zustimmen und weiter"," ohne zu "],
99
+ ["einwilligung","zustimmung","zustimmung","einwilligung"],
100
+ ["tracking-technologien"],
101
+ ["verwendung "],
102
+ ["mit werbetracking weiterlesen","weiter mit werbung","con tracking e annunci"],
103
+ ["gebruik"],
104
+ ["gebruiken"],
105
+ ["vergelijkbare"],
106
+ ["afwijzen","weigeren","verwerpen"],
107
+ ["noodzakelijk"],
108
+ ["cookies weigeren"],
109
+ ["weiger"],
110
+ ["doorgaan zonder "],
111
+ ["optionele","functionele","functioneel","noodzakelijke","essentiële"],
112
+ ["wijs alles af"],
113
+ [],
114
+ ["onze partners vragen om "],
115
+ ["wij en onze "],
116
+ [" cookies"],
117
+ ["accepteer "],
118
+ ["analytische","functionele","essentiële","noodzakelijke"],
119
+ [" contin"],
120
+ ["cookie"],
121
+ [" uso de cookies"],
122
+ ["usa cookies de google"],
123
+ [" uso de cookies"],
124
+ ["al utilizar nuestro sitio web"],
125
+ ["almacenar la información en un dispositivo y"],
126
+ [" utiliza"],
127
+ ["cookies propias y de"],
128
+ ["son necesarias"],
129
+ [" cookie"],
130
+ ["navegando"],
131
+ ["nosotros y nuestros"],
132
+ ["recopilamos y almacenamos datos de usted y de su dispositivo"],
133
+ ["utilizamos tecnolog"],
134
+ ["almacenar","almacenamos"],
135
+ ["nuestros socios solicitan su consentimiento"],
136
+ ["tanto nosotros como","nosotros y"],
137
+ ["aceptar","rechazar","continuar sin aceptar","solo las necesarias"],
138
+ ["uso de "],
139
+ ["cookies "],
140
+ ["las cookies nos "],
141
+ ["instalamos","empleamos"],
142
+ ["cookies","necesitamos usar cookies"],
143
+ [" cookie"],
144
+ ["używać","używamy"],
145
+ ["cele przetwarzania twoich danych przez zaufanych partnerów iab"],
146
+ ["dzięki "],
147
+ [" plików cookie"],
148
+ ["korzystamy z technologii, takich jak pliki cookie"],
149
+ ["korzystamy"],
150
+ ["niektóre pliki cookies"],
151
+ ["pliki cookies i pokrewne im technologie umożliwiają poprawne działanie strony i pomagają nam dostosować ofertę do twoich potrzeb"],
152
+ ["przechowywanie informacji na urządzeniu lub dostęp do nich"],
153
+ ["przechowywanie plików cookie na swoim urządzeniu"],
154
+ ["przechowywać i uzyskiwać dostęp do informacji na twoich urządzeniach"],
155
+ ["przetwarzamy"],
156
+ [" używa "],
157
+ ["ta strona korzysta z ciasteczek"],
158
+ ["uzyskujemy dostęp i przechowujemy informacje na urządzeniu"],
159
+ ["używa plik"],
160
+ ["używamy plików"],
161
+ ["wykorzystują "],
162
+ ["za pomocą plików cookies"],
163
+ ["zgodą my i nasi partnerzy możemy wykorzystywać precyzyjne dane geolokalizacyjne i identyfikację"],
164
+ ["cookies pròpies i de tercers"],
165
+ ["utilitzem galetes"],
166
+ ["únicament utilitza galetes pròpies amb finalitat tècnica"],
167
+ ["este lloc web utilitza només cookies tècniques necessàries per al seu funcionament"],
168
+ ["de personalització i anàlisi"],
169
+ ["utilitzem cookies i altres tecnologies"],
170
+ ["cookies","galetes"],
171
+ ["cookie propio eta hirugarrenenak helburu teknikoarekin erabiltzen ditu"],
172
+ ["cookie propioak eta hirugarrenen cookieak erabiltzen ditugu"],
173
+ ["cookie propioak eta hirugarrenenak helburu teknikoarekin erabiltzen ditu"],
174
+ ["ak erabiltzen ditu"],
175
+ ["cookieak erabiltzen ditu"],
176
+ [" bazkideek cookieak eta identifikadoreak erabiltzen ditugu"],
177
+ ["norberaren eta hirugarrenen cookie"],
178
+ ["web orri honek cookieak erabiltzen ditu"],
179
+ ["webgune honek cookie propioak eta hirugarrenen cookie-fitxategiak erabiltzen ditu"],
180
+ ["empregamos cookies propias"],
181
+ ["este portal emprega cookies propias ou de terceiros con fins analíticos"],
182
+ ["использу"],
183
+ ["использу"],
184
+ ["cookie","куки"],
185
+ ["технологи"],
186
+ ["cookie","куки"],
187
+ [],
188
+ ["usiamo","utilizziamo"],
189
+ ["cookie"],
190
+ ["noi e i nostri"],
191
+ [" cookie"],
192
+ [" cookie"],
193
+ ["tecnici","di profilazione","di terze parti","analitici","statistici","di marketing"],
194
+ ["acconsent","accett"],
195
+ [" navigazione"],
196
+ ["accetta","accetto","accettare","rifiuta","rifiuto","rifiutare"],
197
+ [" senza accettare"],
198
+ ["rifiuta e abbonati"],
199
+ ["consenso "],
200
+ [" nostri "],
201
+ ["terze parti selezionate"],
202
+ ["archiviare","archiviamo","memorizzare","memorizziamo"],
203
+ ["använder"],
204
+ ["cookie","クッキー"],
205
+ ["bruger cookies"],
206
+ ["informasjonskapsler","cookies"],
207
+ ];
@@ -0,0 +1,173 @@
1
+ /**
2
+ * Context negatives for heuristic detect patterns: wording that shows a match, or a whole popup, isn't a consent notice.
3
+ * The vocabulary they test (consent choices, age wording, leave buttons, legal clauses) is defined here, next to them.
4
+ * See docs/heuristic-detection.md.
5
+ */
6
+ import {
7
+ HeuristicInput,
8
+ ACCEPTEZ_UTILISATION,
9
+ ACCEPT_ALL,
10
+ BY_CONTINUING_PRIVACY,
11
+ DE_COOKIE_VERB,
12
+ GEBRUIK_VAN_COOKIES,
13
+ USE_OF_COOKIES,
14
+ UTILISATION_DES_COOKIES,
15
+ VERWENDUNG_VON_COOKIES,
16
+ } from './heuristic-patterns';
17
+
18
+ /** A test on a text: a regex that must match it, or a predicate. */
19
+ export type TextTest = RegExp | ((text: string) => boolean);
20
+ /**
21
+ * Drops a single detect pattern match when its context matches `pattern` and not `unless` (with only `unless`, when the
22
+ * context lacks it). The context is `window` chars either side of the match, or its line and `lines` lines either side
23
+ * ([before, after] counts each side); the default is 150 chars. With `whole`, the context is the whole text, so a hit
24
+ * drops every match: the text is excluded. `appliesTo` limits it to some detect patterns.
25
+ */
26
+ export type ContextNegative = {
27
+ name: string;
28
+ pattern?: RegExp;
29
+ unless?: TextTest;
30
+ window?: number;
31
+ lines?: number | [number, number];
32
+ whole?: boolean;
33
+ input?: HeuristicInput;
34
+ appliesTo?: RegExp[];
35
+ };
36
+
37
+ // a cookie choice or dismiss control, or consent dialog wording, in the core languages, except a bare accept
38
+ const COOKIE_CHOICE = [
39
+ '\\b(?:accept|reject|decline|refuse|deny|allow|manage|customi[sz]e)\\b[^\\n]{0,25}\\bcookies?\\b',
40
+ '\\b(?:reject|decline|deny|refuse) all\\b',
41
+ '\\b(?:essential|necessary|required) (?:cookies )?only\\b|\\bonly (?:essential|necessary|required)\\b',
42
+ '\\bcookies? (?:notice|settings|preferences|banner)\\b',
43
+ '\\b(?:alle )?(?:cookies )?ablehnen\\b',
44
+ '\\b(?:alles |alle cookies )?(?:weigeren|weiger|afwijzen)\\b',
45
+ '\\b(?:tout )?refuser\\b',
46
+ '\\brechazar(?: todas?)?\\b',
47
+ '\\brifiuta(?: tutti)?\\b',
48
+ // purposes and vendors as a button or heading line: some consent dialogs ask "under 18?"
49
+ '^[^\\n]{0,40}\\b(?:purposes|finalités|propósitos|zwecke|doeleinden|finalità|vendors|fournisseurs|proveedores|leveranciers|fornitori)(?!\\w)[^\\n]{0,10}$',
50
+ '\\b(?:legitimate (?:business )?interest|intérêt légitime|interés legítimo|berechtigtes interesse|gerechtvaardigd belang|legittimo interesse)\\b',
51
+ '\\b(?:we|nous|wir|wij|noi|nosotros) (?:and|et|und|en|e|y) (?:our|nos|unsere|onze|i nostri|nuestros) (?:\\d+ )?(?:partners|partenaires|partner|socios)\\b',
52
+ ].join('|');
53
+ // a bare accept or allow (all), which can also be an age gate's own confirmation
54
+ const BARE_ACCEPT = [
55
+ '\\b(?:accept|allow) all\\b',
56
+ '\\b(?:alle )?(?:cookies )?(?:akzeptieren|erlauben|zulassen)\\b',
57
+ '\\b(?:alles |alle cookies )?(?:accepteren|accepteer|toestaan)\\b',
58
+ '\\b(?:tout )?accepter\\b',
59
+ '\\baceptar(?: todas?)?\\b',
60
+ '\\baccetta(?: tutti)?\\b',
61
+ ].join('|');
62
+ const COOKIE_CHOICE_RE = new RegExp(COOKIE_CHOICE, 'im');
63
+ const CONSENT_CHOICE = new RegExp(`${COOKIE_CHOICE}|${BARE_ACCEPT}`, 'im');
64
+
65
+ // an age limit, an adults-only statement or an age check, in the core languages
66
+ const AGE_WORDING = new RegExp(
67
+ [
68
+ '\\b(?:over|above|at least|older than|minimum(?: age of)?)\\s*(?:18|21|eighteen)\\b',
69
+ // "18+" only with age words after it: a bare "18+" also appears in cookie banners on adult sites
70
+ '\\b(?:18|21)\\+?\\s*(?:years?(?: of age| old)?|yo|or older|or over)\\b',
71
+ '\\b(?:you|users?|visitors?) must be (?:over |above |at least )?(?:18|21)\\b',
72
+ "\\b(?:i'?m|i am) (?:over |at least )?(?:18|21)\\b",
73
+ '\\bage (?:verification|confirmation|check|gate|restriction)\\b',
74
+ '\\b(?:adults? only|adult[\\s-](?:oriented|content|material|website)|legal age|age of majority|not a minor|minors)\\b',
75
+ '\\b(?:18|21) jahre\\b',
76
+ '\\balters(?:beschränkung|bestätigung|verifikation|prüfung|kontrolle)',
77
+ '\\b(?:volljährig|für erwachsene|minderjährige)\\b',
78
+ '\\b(?:18|21) jaar\\b',
79
+ '\\b(?:volwassenen|meerderjarig|minderjarigen|leeftijdsverificatie)\\b',
80
+ '\\b(?:18|21) ans\\b',
81
+ // no \\b before an accented letter: without the u flag it is not a word character
82
+ '\\b(?:pour adultes|vérification de l.âge|mineurs)\\b|âge légal\\b',
83
+ '\\b(?:18|21) años\\b',
84
+ '\\b(?:mayor(?:es)? de edad|menores de edad|para adultos|verificación de edad)\\b',
85
+ '\\b(?:18|21) anni\\b',
86
+ '\\b(?:maggiorenne|minorenni|per adulti)\\b|\\bverifica dell.età(?!\\w)',
87
+ ].join('|'),
88
+ 'i',
89
+ );
90
+
91
+ // a dismiss or consent button on its own line, as innerText keeps it
92
+ const DISMISS_LINE =
93
+ /^\s*(?:(?:yes,? )?(?:i )?(?:ok(?:ay)?|accept|agree|allow|decline|deny|reject|refuse|understand|acknowledge(?: the use of cookies)?|got it|understood)(?: all)?(?:,? (?:and|&) (?:continue|close))?(?: non-essential)?|close|dismiss|akzeptieren|zustimmen|verstanden|einverstanden|ablehnen|accepteren|akkoord|weigeren|accepter|j.accepte|d.accord|refuser|fermer|aceptar|acepto|rechazar|entendido|accetto|accetta|rifiuta|ho capito|chiudi)\s*[!.]?\s*$/im;
94
+ // a dismiss button at the end of a notice's line, or a close control
95
+ const DISMISS_END = /[.!?]\s+(?:ok(?:ay)?|got it|i agree|accept)\s*!?\s*$|\[\s*[x×]\s*\]|^\s*[x×✕]\s*$/im;
96
+ const NOTICE_CONTROL = new RegExp(`${CONSENT_CHOICE.source}|${DISMISS_LINE.source}|${DISMISS_END.source}`, 'im');
97
+ // an age gate's leave button on its own line, or "I am under 18" in the core languages
98
+ const LEAVE_LINE =
99
+ /^\s*(?:(?:no,? )?(?:i )?(?:want to )?(?:leave|exit|verlassen|quitter|sortir|salir|abandonar|esci|uscire|verlaten)\b[^\n]{0,30}|no,? take me away|(?:seite|hier) verlassen|(?:i am|i'm|ich bin|ik ben|je suis|soy|sono) (?:under|unter|onder|jonger dan|menor de(?: edad)?|minorenne|mineur)\b[^\n]{0,10})\s*[!.]?\s*$/im;
100
+ // a notice's own control: manage or configure cookies, a bare settings button line, or "close this popup"
101
+ const NOTICE_OWN_CONTROL = new RegExp(
102
+ [
103
+ '\\bcookies? verwalten\\b|\\bcookie-?(?:einstellungen|präferenzen)\\b|\\beinstellungen verwalten\\b',
104
+ '\\bconfigura(?:r|ción de)(?: las)? cookies\\b|\\bgestionar(?: las)? cookies\\b|\\bpersonalizar(?: las)? cookies\\b',
105
+ '\\bparam[ée]trer(?: les)? cookies\\b|\\bparam[èe]tres(?: des)? cookies\\b|\\bg[ée]rer(?: les)? cookies\\b|\\bpersonnaliser(?: les)? cookies\\b',
106
+ '\\bgestisci(?: i)? cookie|\\bimpostazioni(?: dei| sui)? cookie|\\bpersonalizza(?: i)? cookie',
107
+ '\\bcookie-?instellingen\\b|\\bcookies? beheren\\b|\\bvoorkeuren (?:beheren|aanpassen)\\b',
108
+ '^\\s*(?:customi[sz]e|personnaliser|paramétrer|personalizar|configurar|personalizza|anpassen|aanpassen|meer opties|more options|weitere optionen|plus d.options|más opciones|altre opzioni|manage (?:options|preferences|choices))\\s*$',
109
+ '^\\s*close (?:this|the) (?:popup|banner|notice|message)\\s*$',
110
+ ].join('|'),
111
+ 'im',
112
+ );
113
+ // the age-gate exclusions' unless: a consent or notice control, and no leave button. An age gate's "OK" next to "Leave"
114
+ // confirms the age, not cookies.
115
+ const ageGateUnless =
116
+ (control: RegExp) =>
117
+ (text: string): boolean =>
118
+ !LEAVE_LINE.test(text) && (control.test(text) || NOTICE_OWN_CONTROL.test(text));
119
+ // consent vocabulary beyond "privacy", for patterns that also match terms of use and login text
120
+ const CONSENT_WORDS =
121
+ /cookie|consent|track|partner|personali[sz]|advertis|analytic|privacy (?:options|choices|settings|rights)|do not sell|opt[- ]out/i;
122
+
123
+ // license and terms clauses that cookie notices never contain, so a popup with them is a legal agreement
124
+ const LEGAL_AGREEMENT =
125
+ /\b(?:end[- ]user licen[cs]e agreement|licen[cs]e agreement|limitation of liability|governing law|indemnif\w*|hereunder|disclaimers? of warrant\w*|warrant(?:y|ies) of merchantability)\b/i;
126
+
127
+ // drop single matches whose context shows the text isn't a consent notice, or whole popups that aren't one
128
+ export const DETECT_CONTEXT_NEGATIVES: ContextNegative[] = [
129
+ // popups with their own age confirmation are age gates, even when they mention cookies; a bare accept doesn't count
130
+ // as a cookie choice here, since it may confirm the age
131
+ { name: 'age-gate-popup', pattern: AGE_WORDING, unless: ageGateUnless(COOKIE_CHOICE_RE), whole: true, input: 'popup' },
132
+ // a license or terms agreement may mention cookies, and its decline button must not be clicked as a cookie reject
133
+ { name: 'legal-agreement', pattern: LEGAL_AGREEMENT, whole: true, input: 'popup' },
134
+ // page text next to an age gate, unless a consent control is there too
135
+ { name: 'age-gate', pattern: AGE_WORDING, unless: ageGateUnless(NOTICE_CONTROL), lines: [4, 5], input: 'page' },
136
+ // terms of use need cookie or consent wording; a privacy-policy-only notice needs that or a button
137
+ {
138
+ name: 'terms-without-consent',
139
+ pattern: /\bterms\b|\bconditions\b/i,
140
+ unless: CONSENT_WORDS,
141
+ appliesTo: [BY_CONTINUING_PRIVACY],
142
+ },
143
+ {
144
+ name: 'privacy-without-control',
145
+ unless: new RegExp(`${CONSENT_WORDS.source}|${DISMISS_LINE.source}`, 'im'),
146
+ appliesTo: [BY_CONTINUING_PRIVACY],
147
+ },
148
+ // a cookie policy link among short footer link lines
149
+ {
150
+ name: 'footer-link',
151
+ pattern: /^[^.!?:\n]{0,60}\n[\s]*\n?[^.!?:\s][^.!?:\n]{0,59}(?:\n|$)/,
152
+ unless: NOTICE_CONTROL,
153
+ lines: [0, 2],
154
+ input: 'page',
155
+ appliesTo: [USE_OF_COOKIES, VERWENDUNG_VON_COOKIES, UTILISATION_DES_COOKIES, GEBRUIK_VAN_COOKIES],
156
+ },
157
+ // "accept all" in prose; case-sensitive since button labels run together in innerText
158
+ {
159
+ name: 'accept-all-prose',
160
+ pattern: /\baccept all [a-z]|\baccept All[a-z]/,
161
+ unless: /accept all (?:cookies|and|&)/i,
162
+ window: 15,
163
+ appliesTo: [ACCEPT_ALL],
164
+ },
165
+ {
166
+ name: 'acceptez-terms',
167
+ pattern: /conditions (?:générales )?d.utilisation|\bcgu\b/i,
168
+ unless: /cookie|témoin|traceur|partenaire/i,
169
+ appliesTo: [ACCEPTEZ_UTILISATION],
170
+ },
171
+ // the same sentence is also a footer line with only a "learn more" link
172
+ { name: 'de-cookie-verb-needs-control', unless: NOTICE_CONTROL, lines: [1, 6], input: 'page', appliesTo: [DE_COOKIE_VERB] },
173
+ ];