@whotracksme/reporting 12.1.17 → 12.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 +24 -0
- package/package.json +1 -1
- package/reporting/src/doublefetch-page-handler.js +6 -3
- package/reporting/src/network.js +14 -4
- package/reporting/test/doublefetch-page-handler.spec.js +70 -0
- package/reporting/test/network.spec.js +59 -0
- package/reporting/test/pages.spec.js +35 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,27 @@
|
|
|
1
|
+
# v12.1.19 (Thu Nov 19 2026)
|
|
2
|
+
|
|
3
|
+
#### 🐛 Bug Fix
|
|
4
|
+
|
|
5
|
+
- fixed: only write DNS mappings if something changes [#261](https://github.com/whotracksme/webextension-packages/pull/261) ([@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
|
+
# v12.1.18 (Thu Nov 19 2026)
|
|
14
|
+
|
|
15
|
+
#### 🐛 Bug Fix
|
|
16
|
+
|
|
17
|
+
- fixed: doublefetch ignored the download limit [#260](https://github.com/whotracksme/webextension-packages/pull/260) ([@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
|
# v12.1.17 (Thu Nov 19 2026)
|
|
2
26
|
|
|
3
27
|
#### 🐛 Bug Fix
|
package/package.json
CHANGED
|
@@ -312,7 +312,8 @@ function unbreakConfig(url) {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
class CachedPageFetcher {
|
|
315
|
-
constructor() {
|
|
315
|
+
constructor({ downloadLimit } = {}) {
|
|
316
|
+
this.downloadLimit = downloadLimit;
|
|
316
317
|
this.urlToAsyncPageStructure = new Map();
|
|
317
318
|
}
|
|
318
319
|
|
|
@@ -380,7 +381,7 @@ export default class DoublefetchPageHandler {
|
|
|
380
381
|
newPageApprover,
|
|
381
382
|
|
|
382
383
|
// by default, use a separate fetcher cache per job
|
|
383
|
-
pageFetcherProvider = () => new CachedPageFetcher(),
|
|
384
|
+
pageFetcherProvider = (options) => new CachedPageFetcher(options),
|
|
384
385
|
}) {
|
|
385
386
|
this.sanitizer = requireParam(sanitizer);
|
|
386
387
|
this.newPageApprover = requireParam(newPageApprover);
|
|
@@ -420,7 +421,9 @@ export default class DoublefetchPageHandler {
|
|
|
420
421
|
throw new BadJobError('preDoublefetch missing');
|
|
421
422
|
}
|
|
422
423
|
|
|
423
|
-
const pageFetcher = this.pageFetcherProvider(
|
|
424
|
+
const pageFetcher = this.pageFetcherProvider({
|
|
425
|
+
downloadLimit: this.downloadLimit,
|
|
426
|
+
});
|
|
424
427
|
const log = logger.debug.bind(logger.debug, `[doublefetch=${url}]`);
|
|
425
428
|
const logWarn = logger.warn.bind(logger.warn, `[doublefetch=${url}]`);
|
|
426
429
|
const withBaseUrl = (baseUrl) => ({ baseUrl, log, logWarn });
|
package/reporting/src/network.js
CHANGED
|
@@ -257,13 +257,23 @@ export class DnsResolver {
|
|
|
257
257
|
return false;
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
+
// Returns true if the cache changed. The caller can then persist it.
|
|
260
261
|
cacheDnsResolution({ url, hostname, ip, now = Date.now() }) {
|
|
261
262
|
const hostname_ = hostname || this._tryParseHostname(url);
|
|
262
|
-
if (hostname_) {
|
|
263
|
-
|
|
264
|
-
return true;
|
|
263
|
+
if (!hostname_) {
|
|
264
|
+
return false;
|
|
265
265
|
}
|
|
266
|
-
|
|
266
|
+
|
|
267
|
+
// Most requests bring no new information. Skip them, but refresh the
|
|
268
|
+
// timestamp from time to time; otherwise, a hostname in use expires.
|
|
269
|
+
const oldEntry = this.dns.get(hostname_);
|
|
270
|
+
const isFresh = oldEntry && Math.abs(now - oldEntry.updatedAt) < 2 * MINUTE;
|
|
271
|
+
if (isFresh && oldEntry.ip === ip) {
|
|
272
|
+
return false;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
this.dns.set(hostname_, { ip, updatedAt: now });
|
|
276
|
+
return true;
|
|
267
277
|
}
|
|
268
278
|
|
|
269
279
|
expireEntries(now = Date.now()) {
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { expect, assert } from 'chai';
|
|
13
|
+
import sinon from 'sinon';
|
|
13
14
|
import * as fc from 'fast-check';
|
|
14
15
|
|
|
15
16
|
import Sanitizer from '../src/sanitizer';
|
|
@@ -990,6 +991,75 @@ describe('DoublefetchPageHandler', function () {
|
|
|
990
991
|
expect(details).to.be.a('string').that.is.not.empty;
|
|
991
992
|
});
|
|
992
993
|
});
|
|
994
|
+
|
|
995
|
+
describe('with the default page fetcher', function () {
|
|
996
|
+
const url = 'https://example.com/some/article';
|
|
997
|
+
let fetchStub;
|
|
998
|
+
let numDownloads;
|
|
999
|
+
|
|
1000
|
+
function mockServerResponse({ contentLength }) {
|
|
1001
|
+
fetchStub.callsFake(async (requestedUrl) => ({
|
|
1002
|
+
ok: true,
|
|
1003
|
+
status: 200,
|
|
1004
|
+
type: 'basic',
|
|
1005
|
+
url: requestedUrl,
|
|
1006
|
+
headers: new Headers({
|
|
1007
|
+
'content-type': 'text/html',
|
|
1008
|
+
'content-length': String(contentLength),
|
|
1009
|
+
}),
|
|
1010
|
+
async text() {
|
|
1011
|
+
numDownloads += 1;
|
|
1012
|
+
return '<!doctype html><html><head><title>Some article</title></head></html>';
|
|
1013
|
+
},
|
|
1014
|
+
}));
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
function somePage() {
|
|
1018
|
+
return {
|
|
1019
|
+
url,
|
|
1020
|
+
title: 'Some article',
|
|
1021
|
+
status: 'complete',
|
|
1022
|
+
pageLoadMethod: 'full-page-load',
|
|
1023
|
+
preDoublefetch: {
|
|
1024
|
+
title: 'Some article',
|
|
1025
|
+
url,
|
|
1026
|
+
noindex: false,
|
|
1027
|
+
meta: {},
|
|
1028
|
+
},
|
|
1029
|
+
aggregator: { activity: 0.1 },
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
beforeEach(function () {
|
|
1034
|
+
numDownloads = 0;
|
|
1035
|
+
fetchStub = sinon.stub(globalThis, 'fetch');
|
|
1036
|
+
uut = new DoublefetchPageHandler({
|
|
1037
|
+
jobScheduler,
|
|
1038
|
+
sanitizer,
|
|
1039
|
+
newPageApprover,
|
|
1040
|
+
});
|
|
1041
|
+
});
|
|
1042
|
+
|
|
1043
|
+
afterEach(function () {
|
|
1044
|
+
fetchStub.restore();
|
|
1045
|
+
});
|
|
1046
|
+
|
|
1047
|
+
it('should download a page that is smaller than the download limit', async function () {
|
|
1048
|
+
mockServerResponse({ contentLength: uut.downloadLimit - 1 });
|
|
1049
|
+
|
|
1050
|
+
await uut.runJob(somePage());
|
|
1051
|
+
expect(numDownloads).to.eql(1);
|
|
1052
|
+
});
|
|
1053
|
+
|
|
1054
|
+
it('should not download a page that is bigger than the download limit', async function () {
|
|
1055
|
+
mockServerResponse({ contentLength: uut.downloadLimit + 1 });
|
|
1056
|
+
|
|
1057
|
+
const { ok, details } = await uut.runJob(somePage());
|
|
1058
|
+
expect(ok).to.be.false;
|
|
1059
|
+
expect(details).to.include('Exceeded size limit');
|
|
1060
|
+
expect(numDownloads).to.eql(0);
|
|
1061
|
+
});
|
|
1062
|
+
});
|
|
993
1063
|
});
|
|
994
1064
|
|
|
995
1065
|
describe('#titlesMatchAfterDoublefetch', function () {
|
|
@@ -125,4 +125,63 @@ describe('DnsResolver', function () {
|
|
|
125
125
|
expect(uut.isPrivateURL('not-a-url')).to.be.true;
|
|
126
126
|
});
|
|
127
127
|
});
|
|
128
|
+
|
|
129
|
+
describe('#cacheDnsResolution', function () {
|
|
130
|
+
const SECOND = 1000;
|
|
131
|
+
const MINUTE = 60 * SECOND;
|
|
132
|
+
const HOUR = 60 * MINUTE;
|
|
133
|
+
const hostname = 'www.example.com';
|
|
134
|
+
const now = Date.now();
|
|
135
|
+
|
|
136
|
+
it('should report a change for a new hostname', function () {
|
|
137
|
+
expect(uut.cacheDnsResolution({ hostname, ip: '1.2.3.4', now })).to.be
|
|
138
|
+
.true;
|
|
139
|
+
expect(uut.serialize({ now })).to.have.lengthOf(1);
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it('should report no change if the same IP is seen again shortly after', function () {
|
|
143
|
+
uut.cacheDnsResolution({ hostname, ip: '1.2.3.4', now });
|
|
144
|
+
|
|
145
|
+
for (let i = 1; i <= 10; i += 1) {
|
|
146
|
+
const later = now + i * 10 * SECOND;
|
|
147
|
+
expect(uut.cacheDnsResolution({ hostname, ip: '1.2.3.4', now: later }))
|
|
148
|
+
.to.be.false;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it('should report a change if the IP is different', function () {
|
|
153
|
+
uut.cacheDnsResolution({
|
|
154
|
+
hostname: 'router.example',
|
|
155
|
+
ip: '1.2.3.4',
|
|
156
|
+
now,
|
|
157
|
+
});
|
|
158
|
+
expect(uut.isPrivateHostname('router.example')).to.be.false;
|
|
159
|
+
|
|
160
|
+
const later = now + MINUTE;
|
|
161
|
+
expect(
|
|
162
|
+
uut.cacheDnsResolution({
|
|
163
|
+
hostname: 'router.example',
|
|
164
|
+
ip: '192.168.0.1',
|
|
165
|
+
now: later,
|
|
166
|
+
}),
|
|
167
|
+
).to.be.true;
|
|
168
|
+
expect(uut.isPrivateHostname('router.example')).to.be.true;
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it('should not let a hostname expire that is in use', function () {
|
|
172
|
+
let numCalls = 0;
|
|
173
|
+
let numChanges = 0;
|
|
174
|
+
for (let t = now; t <= now + 48 * HOUR; t += 10 * SECOND) {
|
|
175
|
+
numCalls += 1;
|
|
176
|
+
if (uut.cacheDnsResolution({ hostname, ip: '1.2.3.4', now: t })) {
|
|
177
|
+
numChanges += 1;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
expect(uut.serialize({ now: now + 48 * HOUR })).to.have.lengthOf(1);
|
|
181
|
+
|
|
182
|
+
// the timestamp is refreshed from time to time, but not on each call
|
|
183
|
+
expect(numChanges).to.be.greaterThan(48);
|
|
184
|
+
expect(numChanges).to.be.lessThan(numCalls / 10);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
128
187
|
});
|
|
@@ -767,6 +767,41 @@ describe('#Pages', function () {
|
|
|
767
767
|
});
|
|
768
768
|
});
|
|
769
769
|
|
|
770
|
+
describe('DNS cache in the session storage', function () {
|
|
771
|
+
let numWritesOfDnsCache;
|
|
772
|
+
|
|
773
|
+
function responseFrom(hostname, ip) {
|
|
774
|
+
chromeApiMock.webRequest.onResponseStarted.dispatch({
|
|
775
|
+
tabId: 1,
|
|
776
|
+
type: 'image',
|
|
777
|
+
url: `https://${hostname}/some/image.png`,
|
|
778
|
+
ip,
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
beforeEach(function () {
|
|
783
|
+
numWritesOfDnsCache = 0;
|
|
784
|
+
const originalSet = uut.sessionStore.set.bind(uut.sessionStore);
|
|
785
|
+
uut.sessionStore.set = (key, value) => {
|
|
786
|
+
if (key === 'dnsResolver') {
|
|
787
|
+
numWritesOfDnsCache += 1;
|
|
788
|
+
}
|
|
789
|
+
originalSet(key, value);
|
|
790
|
+
};
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
it('should write the cache only if a response has new information', function () {
|
|
794
|
+
for (let i = 0; i < 100; i += 1) {
|
|
795
|
+
responseFrom('cdn.example.com', '203.0.113.1');
|
|
796
|
+
}
|
|
797
|
+
expect(numWritesOfDnsCache).to.eql(1);
|
|
798
|
+
|
|
799
|
+
responseFrom('www.example.com', '203.0.113.2');
|
|
800
|
+
expect(numWritesOfDnsCache).to.eql(2);
|
|
801
|
+
expect(uut.sessionStore.get('dnsResolver')).to.have.lengthOf(2);
|
|
802
|
+
});
|
|
803
|
+
});
|
|
804
|
+
|
|
770
805
|
// This are optional tests that can be enabled if the REPLAY_FIXTURES_URL
|
|
771
806
|
// environment variable is defined. Karma lacks access to the filesystem,
|
|
772
807
|
// but we can fetch fixtures over the network.
|