@whotracksme/reporting 5.1.17 → 5.1.19
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/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
# v5.1.19 (Thu Aug 01 2024)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- New builtin: filterExact [#87](https://github.com/whotracksme/webextension-packages/pull/87) ([@philipp-classen](https://github.com/philipp-classen))
|
|
6
|
+
|
|
7
|
+
#### Authors: 1
|
|
8
|
+
|
|
9
|
+
- Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# v5.1.18 (Thu Aug 01 2024)
|
|
14
|
+
|
|
15
|
+
#### 🐛 Bug Fix
|
|
16
|
+
|
|
17
|
+
- Abort if a transform rule is not well-formed [#88](https://github.com/whotracksme/webextension-packages/pull/88) ([@philipp-classen](https://github.com/philipp-classen))
|
|
18
|
+
|
|
19
|
+
#### Authors: 1
|
|
20
|
+
|
|
21
|
+
- Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
1
25
|
# v5.0.17 (Mon Jul 08 2024)
|
|
2
26
|
|
|
3
27
|
#### 🐛 Bug Fix
|
package/package.json
CHANGED
|
@@ -94,6 +94,8 @@ import {
|
|
|
94
94
|
* 2) Returning "null"/"undefined" has the semantic of stopping the
|
|
95
95
|
* execution without an error. It is still possible that a
|
|
96
96
|
* message will be sent, but with a missing value.
|
|
97
|
+
*
|
|
98
|
+
* After adding a new transformation, increase the API version (see PATTERN_DSL_VERSION).
|
|
97
99
|
*/
|
|
98
100
|
const TRANSFORMS = new Map(
|
|
99
101
|
Object.entries({
|
|
@@ -105,6 +107,8 @@ const TRANSFORMS = new Map(
|
|
|
105
107
|
* - "/example.test/path?foo=bar+baz" -> "bar baz"
|
|
106
108
|
* - "/example.test/path" -> null
|
|
107
109
|
* - "This is a string but not an URL" -> null
|
|
110
|
+
*
|
|
111
|
+
* @since: 1
|
|
108
112
|
*/
|
|
109
113
|
queryParam: (url, queryParam) => {
|
|
110
114
|
requireString(url);
|
|
@@ -133,6 +137,8 @@ const TRANSFORMS = new Map(
|
|
|
133
137
|
*
|
|
134
138
|
* Example ["removeParams", ["foo", "bar"]]:
|
|
135
139
|
* - "https://example.test/path?foo=1&bar=2" -> "https://example.test/path"
|
|
140
|
+
*
|
|
141
|
+
* @since: 1
|
|
136
142
|
*/
|
|
137
143
|
removeParams: (url, queryParams) => {
|
|
138
144
|
requireString(url);
|
|
@@ -147,16 +153,32 @@ const TRANSFORMS = new Map(
|
|
|
147
153
|
/**
|
|
148
154
|
* Given text, it will verify that it is a well-formed URL;
|
|
149
155
|
* otherwise, it will end the processing by "nulling" it out.
|
|
156
|
+
*
|
|
157
|
+
* @since: 1
|
|
150
158
|
*/
|
|
151
159
|
requireURL: (url) => {
|
|
152
160
|
requireString(url);
|
|
153
161
|
return URL.canParse(url) ? url : null;
|
|
154
162
|
},
|
|
155
163
|
|
|
164
|
+
/**
|
|
165
|
+
* Validates if the given value is in a predefined list of allowed
|
|
166
|
+
* values; otherwise, it will end the processing by "nulling" it out.
|
|
167
|
+
*
|
|
168
|
+
* @since: 2
|
|
169
|
+
*/
|
|
170
|
+
filterExact: (text, allowedStrings) => {
|
|
171
|
+
requireString(text);
|
|
172
|
+
requireArrayOfStrings(allowedStrings);
|
|
173
|
+
return allowedStrings.includes(text) ? text : null;
|
|
174
|
+
},
|
|
175
|
+
|
|
156
176
|
/**
|
|
157
177
|
* Given a URL, it runs a set of extra checks to filter out
|
|
158
178
|
* parts that may be sensitive (i.e. keeping only the hostname),
|
|
159
179
|
* or even drop it completely.
|
|
180
|
+
*
|
|
181
|
+
* @since: 1
|
|
160
182
|
*/
|
|
161
183
|
maskU: (url) => {
|
|
162
184
|
requireString(url);
|
|
@@ -174,6 +196,8 @@ const TRANSFORMS = new Map(
|
|
|
174
196
|
* URLs that can be dropped without causing much harm, using "strictMaskU"
|
|
175
197
|
* can be useful. However, it will drop many harmless URLs; in other words,
|
|
176
198
|
* expect a high number of false-positives.
|
|
199
|
+
*
|
|
200
|
+
* @since: 1
|
|
177
201
|
*/
|
|
178
202
|
strictMaskU: (url) => {
|
|
179
203
|
requireString(url);
|
|
@@ -186,6 +210,8 @@ const TRANSFORMS = new Map(
|
|
|
186
210
|
|
|
187
211
|
/**
|
|
188
212
|
* Like "maskU", but tries to preserve the URL path when truncating.
|
|
213
|
+
*
|
|
214
|
+
* @since: 1
|
|
189
215
|
*/
|
|
190
216
|
relaxedMaskU: (url) => {
|
|
191
217
|
requireString(url);
|
|
@@ -197,6 +223,9 @@ const TRANSFORMS = new Map(
|
|
|
197
223
|
}
|
|
198
224
|
},
|
|
199
225
|
|
|
226
|
+
/**
|
|
227
|
+
* @since: 1
|
|
228
|
+
*/
|
|
200
229
|
split: (text, splitON, arrPos) => {
|
|
201
230
|
requireString(text);
|
|
202
231
|
requireString(splitON);
|
|
@@ -209,6 +238,9 @@ const TRANSFORMS = new Map(
|
|
|
209
238
|
return parts[arrPos] ?? null;
|
|
210
239
|
},
|
|
211
240
|
|
|
241
|
+
/**
|
|
242
|
+
* @since: 1
|
|
243
|
+
*/
|
|
212
244
|
trySplit: (text, splitON, arrPos) => {
|
|
213
245
|
requireString(text);
|
|
214
246
|
requireString(splitON);
|
|
@@ -217,6 +249,9 @@ const TRANSFORMS = new Map(
|
|
|
217
249
|
return text.split(splitON)[arrPos] || text;
|
|
218
250
|
},
|
|
219
251
|
|
|
252
|
+
/**
|
|
253
|
+
* @since: 1
|
|
254
|
+
*/
|
|
220
255
|
decodeURIComponent: (text) => {
|
|
221
256
|
requireString(text);
|
|
222
257
|
try {
|
|
@@ -226,6 +261,9 @@ const TRANSFORMS = new Map(
|
|
|
226
261
|
}
|
|
227
262
|
},
|
|
228
263
|
|
|
264
|
+
/**
|
|
265
|
+
* @since: 1
|
|
266
|
+
*/
|
|
229
267
|
tryDecodeURIComponent: (text) => {
|
|
230
268
|
requireString(text);
|
|
231
269
|
try {
|
|
@@ -240,6 +278,8 @@ const TRANSFORMS = new Map(
|
|
|
240
278
|
* given path. By default, it will only extract safe types (strings,
|
|
241
279
|
* numbers, booleans), mostly to prevent accidentally extracting
|
|
242
280
|
* more than intended.
|
|
281
|
+
*
|
|
282
|
+
* @since: 1
|
|
243
283
|
*/
|
|
244
284
|
json: (text, path, extractObjects = false) => {
|
|
245
285
|
requireString(text);
|
|
@@ -285,7 +325,7 @@ export function lookupBuiltinTransform(name) {
|
|
|
285
325
|
* to disable clients that do not meet the minimum requirements of the
|
|
286
326
|
* current patterns.
|
|
287
327
|
*/
|
|
288
|
-
const PATTERN_DSL_VERSION =
|
|
328
|
+
const PATTERN_DSL_VERSION = 2;
|
|
289
329
|
|
|
290
330
|
/**
|
|
291
331
|
* "Magic" empty rule set, which exists only if patterns were loaded, but
|
|
@@ -78,13 +78,20 @@ function runSelector(item, selector, attr, baseURI) {
|
|
|
78
78
|
|
|
79
79
|
function runTransforms(value, transformSteps = []) {
|
|
80
80
|
if (!Array.isArray(transformSteps)) {
|
|
81
|
-
throw new BadPatternError(
|
|
81
|
+
throw new BadPatternError(
|
|
82
|
+
'Transform definitions must be an array (of arrays).',
|
|
83
|
+
);
|
|
82
84
|
}
|
|
83
85
|
if (value === undefined || value === null) {
|
|
84
86
|
return null;
|
|
85
87
|
}
|
|
86
88
|
let tmpValue = value;
|
|
87
89
|
for (const step of transformSteps) {
|
|
90
|
+
if (!Array.isArray(step)) {
|
|
91
|
+
throw new BadPatternError(
|
|
92
|
+
'Single transform definitions must be an array.',
|
|
93
|
+
);
|
|
94
|
+
}
|
|
88
95
|
const [name, ...args] = step;
|
|
89
96
|
const transform = lookupBuiltinTransform(name);
|
|
90
97
|
tmpValue = transform(tmpValue, ...args);
|
|
@@ -279,7 +279,7 @@ describe('Test builtin primitives', function () {
|
|
|
279
279
|
});
|
|
280
280
|
|
|
281
281
|
describe('robustness on untrusted data', function () {
|
|
282
|
-
it('should fail if input is not [string] (more parameters are ignored)', function () {
|
|
282
|
+
it('should fail if input is not [string, [string]] (more parameters are ignored)', function () {
|
|
283
283
|
expect(() => removeParams()).to.throw();
|
|
284
284
|
expect(() => removeParams('too few arguments')).to.throw();
|
|
285
285
|
expect(() => removeParams({ wrong: 'types' }, 42)).to.throw();
|
|
@@ -365,6 +365,83 @@ describe('Test builtin primitives', function () {
|
|
|
365
365
|
});
|
|
366
366
|
});
|
|
367
367
|
|
|
368
|
+
describe('#filterExact', function () {
|
|
369
|
+
let filterExact;
|
|
370
|
+
|
|
371
|
+
beforeEach(function () {
|
|
372
|
+
filterExact = lookupBuiltinTransform('filterExact');
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
describe('core functionality', function () {
|
|
376
|
+
it('should accept any string that is allowed', function () {
|
|
377
|
+
expect(filterExact('allowed', ['allowed'])).to.eql('allowed');
|
|
378
|
+
expect(filterExact('', [''])).to.eql('');
|
|
379
|
+
expect(filterExact(' ', [' '])).to.eql(' ');
|
|
380
|
+
expect(filterExact('0', ['0'])).to.eql('0');
|
|
381
|
+
expect(filterExact('false', ['false'])).to.eql('false');
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('should reject any string that is not in the allowed list', function () {
|
|
385
|
+
expect(filterExact('rejected', ['allowed'])).to.eql(null);
|
|
386
|
+
expect(filterExact('rejected', [])).to.eql(null);
|
|
387
|
+
expect(filterExact('', ['allowed'])).to.eql(null);
|
|
388
|
+
expect(filterExact('', [])).to.eql(null);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('should accept all matching texts', function () {
|
|
392
|
+
fc.assert(
|
|
393
|
+
fc.property(fc.array(fc.string()), (allowedTexts) => {
|
|
394
|
+
for (const text of allowedTexts) {
|
|
395
|
+
expect(filterExact(text, allowedTexts)).to.eql(text);
|
|
396
|
+
}
|
|
397
|
+
}),
|
|
398
|
+
);
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
it('should drop all non-matching untrustedTexts', function () {
|
|
402
|
+
fc.assert(
|
|
403
|
+
fc.property(fc.fullUnicodeString(), (untrustedText) => {
|
|
404
|
+
expect(filterExact(untrustedText, [])).to.eql(null);
|
|
405
|
+
expect(
|
|
406
|
+
filterExact(untrustedText, [untrustedText + 'force_mismatch']),
|
|
407
|
+
).to.eql(null);
|
|
408
|
+
expect(
|
|
409
|
+
filterExact(untrustedText, [
|
|
410
|
+
untrustedText + 'force_mismatch',
|
|
411
|
+
untrustedText + 'also_force_mismatch',
|
|
412
|
+
]),
|
|
413
|
+
).to.eql(null);
|
|
414
|
+
}),
|
|
415
|
+
);
|
|
416
|
+
});
|
|
417
|
+
});
|
|
418
|
+
|
|
419
|
+
describe('robustness on untrusted data', function () {
|
|
420
|
+
it('should fail if input is not [string, [string]] (more parameters are ignored)', function () {
|
|
421
|
+
expect(() => filterExact()).to.throw();
|
|
422
|
+
expect(() => filterExact({ wrong: 'types' }, 42)).to.throw();
|
|
423
|
+
expect(() => filterExact('text', 42).to.throw());
|
|
424
|
+
expect(() => filterExact('text', '42').to.throw());
|
|
425
|
+
expect(() => filterExact(42, null).to.throw());
|
|
426
|
+
});
|
|
427
|
+
|
|
428
|
+
it('should not fail on well-formed but arbitrary text', function () {
|
|
429
|
+
fc.assert(
|
|
430
|
+
fc.property(
|
|
431
|
+
fc.fullUnicodeString(),
|
|
432
|
+
fc.array(fc.string()),
|
|
433
|
+
(untrustedText, allowedValues) => {
|
|
434
|
+
expect(filterExact(untrustedText, allowedValues)).to.be.oneOf([
|
|
435
|
+
untrustedText,
|
|
436
|
+
null,
|
|
437
|
+
]);
|
|
438
|
+
},
|
|
439
|
+
),
|
|
440
|
+
);
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
});
|
|
444
|
+
|
|
368
445
|
describe('#maskU', function () {
|
|
369
446
|
let maskU;
|
|
370
447
|
|