@whotracksme/reporting 7.12.2 → 8.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/CHANGELOG.md +24 -0
- package/communication/test/helpers/in-memory-database.js +45 -0
- package/package.json +2 -2
- package/reporting/src/hash-detector-v2/index.js +164 -0
- package/reporting/src/hash-detector-v2/prob.js +599 -0
- package/reporting/src/hash-detector-v2.js +18 -0
- package/reporting/src/observable.js +43 -0
- package/reporting/src/pages.js +11 -12
- package/reporting/src/paused-domains-reporter.js +50 -0
- package/reporting/src/persisted-counters.js +158 -0
- package/reporting/src/popularity-estimator.js +625 -0
- package/reporting/src/popularity-vote-handler.js +219 -0
- package/reporting/src/popularity-vote-sanitizer.js +384 -0
- package/reporting/src/random.js +90 -1
- package/reporting/src/reporting.js +98 -13
- package/reporting/src/utils.js +41 -1
- package/reporting/test/activity-estimator.spec.js +3 -2
- package/reporting/test/alive-check.spec.js +2 -2
- package/reporting/test/country-provider.spec.js +2 -2
- package/reporting/test/index.js +6 -0
- package/reporting/test/job-scheduler.spec.js +2 -2
- package/reporting/test/observable.spec.js +72 -0
- package/reporting/test/page-aggregator.spec.js +3 -0
- package/reporting/test/patterns-updater.spec.js +2 -2
- package/reporting/test/persisted-counters.spec.js +132 -0
- package/reporting/test/popularity-estimator.spec.js +710 -0
- package/reporting/test/popularity-vote-handler.spec.js +420 -0
- package/reporting/test/popularity-vote-sanitizer.spec.js +635 -0
- package/reporting/test/random.spec.js +157 -0
- package/reporting/test/reporting.spec.js +202 -180
- package/reporting/test/utils.spec.js +42 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
# v8.0.0 (Thu Apr 16 2026)
|
|
2
|
+
|
|
3
|
+
#### 💥 Breaking Change
|
|
4
|
+
|
|
5
|
+
- Popularity reporting and preparation for breakage detection [#193](https://github.com/whotracksme/webextension-packages/pull/193) ([@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
|
+
# v7.12.3 (Mon Mar 30 2026)
|
|
14
|
+
|
|
15
|
+
#### ⚠️ Pushed to `main`
|
|
16
|
+
|
|
17
|
+
- Cleanup: also upgrade dependency in the main package.json ([@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
|
# v7.12.2 (Mon Mar 30 2026)
|
|
2
26
|
|
|
3
27
|
#### 🐛 Bug Fix
|
|
@@ -40,4 +40,49 @@ export default class InMemoryDatabase {
|
|
|
40
40
|
async keys() {
|
|
41
41
|
return [...this.db.keys()];
|
|
42
42
|
}
|
|
43
|
+
|
|
44
|
+
// Note: does not support rollbacks and exclusive access
|
|
45
|
+
async transaction({ readonly }, cb) {
|
|
46
|
+
const tx = {};
|
|
47
|
+
|
|
48
|
+
tx.get = (key) => this.get(key);
|
|
49
|
+
tx.scan = async () => {
|
|
50
|
+
const entries = [...this.db];
|
|
51
|
+
let pos = 0;
|
|
52
|
+
const nextCursor = async () => {
|
|
53
|
+
if (pos === entries.length) {
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
const [key, value] = entries[pos++];
|
|
57
|
+
return {
|
|
58
|
+
key,
|
|
59
|
+
value,
|
|
60
|
+
next: nextCursor,
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
return nextCursor();
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
if (!readonly) {
|
|
67
|
+
tx.set = (key, value) => this.set(key, value);
|
|
68
|
+
tx.remove = (key) => this.remove(key);
|
|
69
|
+
tx.clear = () => this.clear();
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
await cb(tx);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async _dumpToMap() {
|
|
76
|
+
return new Map([...this.db]);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// To be used for tests to simulate lost write when the extension restarts.
|
|
80
|
+
// By cloning the database, writes can still go into the old instance
|
|
81
|
+
// without unintentionally updating the live version (after the simulated
|
|
82
|
+
// service worker restart).
|
|
83
|
+
_clone() {
|
|
84
|
+
const clone = new InMemoryDatabase();
|
|
85
|
+
clone.db = new Map([...this.db]);
|
|
86
|
+
return clone;
|
|
87
|
+
}
|
|
43
88
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@whotracksme/reporting",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "",
|
|
6
6
|
"scripts": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"idb": "^8.0.3",
|
|
47
47
|
"linkedom": "^0.18.12",
|
|
48
48
|
"pako": "^2.1.0",
|
|
49
|
-
"tldts-experimental": "^7.0.
|
|
49
|
+
"tldts-experimental": "^7.0.27",
|
|
50
50
|
"bowser": "^2.12.1"
|
|
51
51
|
}
|
|
52
52
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
2
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
3
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
|
4
|
+
|
|
5
|
+
import prob from './prob.js';
|
|
6
|
+
|
|
7
|
+
// Prefilters — instant classification for unambiguous patterns
|
|
8
|
+
const RE_PURE_NUMBERS = /^\d+$/;
|
|
9
|
+
const RE_RESOLUTION = /^\d+x\d+$/;
|
|
10
|
+
const RE_UK_POSTCODE = /^[A-Z]{1,2}\d[A-Z\d]?\d[A-Z]{2}$/i;
|
|
11
|
+
const RE_UUID =
|
|
12
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
13
|
+
const RE_PERCENT_ENCODED = /%[0-9A-Fa-f]{2}/;
|
|
14
|
+
|
|
15
|
+
export class HashProb {
|
|
16
|
+
constructor() {
|
|
17
|
+
this.probHashLogM = prob.logM;
|
|
18
|
+
this.classifierWeights = prob.classifierWeights;
|
|
19
|
+
this.probHashChars = {};
|
|
20
|
+
'abcdefghijklmnopqrstuvwxyz1234567890.- '.split('').forEach((e, idx) => {
|
|
21
|
+
this.probHashChars[e] = idx;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
isHashProb(str) {
|
|
26
|
+
if (!this.probHashLogM) {
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
let logProb = 0.0;
|
|
30
|
+
let transC = 0;
|
|
31
|
+
str = str.toLowerCase().replace(/[^a-z0-9.\- ]/g, '');
|
|
32
|
+
for (let i = 0; i < str.length - 1; i += 1) {
|
|
33
|
+
const pos1 = this.probHashChars[str[i]];
|
|
34
|
+
const pos2 = this.probHashChars[str[i + 1]];
|
|
35
|
+
|
|
36
|
+
logProb += this.probHashLogM[pos1][pos2];
|
|
37
|
+
transC += 1;
|
|
38
|
+
}
|
|
39
|
+
if (transC > 0) {
|
|
40
|
+
return Math.exp(logProb / transC);
|
|
41
|
+
}
|
|
42
|
+
return Math.exp(logProb);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
isHash(str) {
|
|
46
|
+
// Do not consider small strings
|
|
47
|
+
if (str.length < 6) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Layer 1: URL-decode preprocessing (always applies)
|
|
52
|
+
if (str.includes('%') && RE_PERCENT_ENCODED.test(str)) {
|
|
53
|
+
try {
|
|
54
|
+
str = decodeURIComponent(str);
|
|
55
|
+
} catch (e) {
|
|
56
|
+
/* keep original */
|
|
57
|
+
}
|
|
58
|
+
if (str.length < 6) {
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Instant false: known safe formats
|
|
64
|
+
if (RE_PURE_NUMBERS.test(str)) return false;
|
|
65
|
+
if (RE_RESOLUTION.test(str)) return false;
|
|
66
|
+
if (RE_UK_POSTCODE.test(str)) return false;
|
|
67
|
+
|
|
68
|
+
// Instant true: UUID is the one pattern the LR classifier sometimes misses
|
|
69
|
+
if (RE_UUID.test(str)) return true;
|
|
70
|
+
|
|
71
|
+
// Multi-feature logistic regression
|
|
72
|
+
const bigramProb = this.isHashProb(str);
|
|
73
|
+
const features = extractFeatures(str, bigramProb);
|
|
74
|
+
const w = this.classifierWeights;
|
|
75
|
+
|
|
76
|
+
const score =
|
|
77
|
+
w[0] +
|
|
78
|
+
w[1] * features.bigramProb +
|
|
79
|
+
w[2] * features.entropy +
|
|
80
|
+
w[3] * features.hexRatio +
|
|
81
|
+
w[4] * features.vowelRatio +
|
|
82
|
+
w[5] * features.transitions;
|
|
83
|
+
|
|
84
|
+
const probability = 1 / (1 + Math.exp(-score));
|
|
85
|
+
return probability > (w[6] ?? 0.5);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Extract all 5 features from a string in a single pass.
|
|
91
|
+
* All features are O(n) in string length.
|
|
92
|
+
*/
|
|
93
|
+
function extractFeatures(str, bigramProb) {
|
|
94
|
+
const lower = str.toLowerCase();
|
|
95
|
+
const len = lower.length;
|
|
96
|
+
|
|
97
|
+
// Character frequency counts for entropy + hex ratio + vowel ratio
|
|
98
|
+
const freq = {};
|
|
99
|
+
let hexCount = 0;
|
|
100
|
+
let vowelCount = 0;
|
|
101
|
+
let alphaCount = 0;
|
|
102
|
+
let transitionCount = 0;
|
|
103
|
+
|
|
104
|
+
// Previous character class: 0=letter, 1=digit, -1=other
|
|
105
|
+
let prevClass = -1;
|
|
106
|
+
|
|
107
|
+
for (let i = 0; i < len; i++) {
|
|
108
|
+
const c = lower[i];
|
|
109
|
+
const code = lower.charCodeAt(i);
|
|
110
|
+
|
|
111
|
+
// Frequency counting for entropy
|
|
112
|
+
freq[c] = (freq[c] || 0) + 1;
|
|
113
|
+
|
|
114
|
+
// Hex character ratio
|
|
115
|
+
if (
|
|
116
|
+
(code >= 48 && code <= 57) || // 0-9
|
|
117
|
+
(code >= 97 && code <= 102)
|
|
118
|
+
) {
|
|
119
|
+
// a-f
|
|
120
|
+
hexCount++;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// Vowel ratio (among alphabetic chars)
|
|
124
|
+
if (code >= 97 && code <= 122) {
|
|
125
|
+
// a-z
|
|
126
|
+
alphaCount++;
|
|
127
|
+
if (c === 'a' || c === 'e' || c === 'i' || c === 'o' || c === 'u') {
|
|
128
|
+
vowelCount++;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Char-class transitions (letter <-> digit)
|
|
133
|
+
let curClass;
|
|
134
|
+
if (code >= 97 && code <= 122) {
|
|
135
|
+
curClass = 0; // letter
|
|
136
|
+
} else if (code >= 48 && code <= 57) {
|
|
137
|
+
curClass = 1; // digit
|
|
138
|
+
} else {
|
|
139
|
+
curClass = -1; // other
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (prevClass >= 0 && curClass >= 0 && prevClass !== curClass) {
|
|
143
|
+
transitionCount++;
|
|
144
|
+
}
|
|
145
|
+
if (curClass >= 0) {
|
|
146
|
+
prevClass = curClass;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// Shannon entropy: -sum(p(c) * log2(p(c)))
|
|
151
|
+
let entropy = 0;
|
|
152
|
+
for (const c in freq) {
|
|
153
|
+
const p = freq[c] / len;
|
|
154
|
+
entropy -= p * Math.log2(p);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return {
|
|
158
|
+
bigramProb,
|
|
159
|
+
entropy,
|
|
160
|
+
hexRatio: len > 0 ? hexCount / len : 0,
|
|
161
|
+
vowelRatio: alphaCount > 0 ? vowelCount / alphaCount : 0,
|
|
162
|
+
transitions: len > 1 ? transitionCount / (len - 1) : 0,
|
|
163
|
+
};
|
|
164
|
+
}
|