@whotracksme/reporting 12.1.18 β†’ 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 CHANGED
@@ -1,3 +1,15 @@
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
+
1
13
  # v12.1.18 (Thu Nov 19 2026)
2
14
 
3
15
  #### πŸ› Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "12.1.18",
3
+ "version": "12.1.19",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  "./sanitizer": "./reporting/src/sanitizer.js",
@@ -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
- this.dns.set(hostname_, { ip, updatedAt: now });
264
- return true;
263
+ if (!hostname_) {
264
+ return false;
265
265
  }
266
- return false;
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()) {
@@ -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.