@whotracksme/reporting 5.1.23 β†’ 5.1.24

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,16 @@
1
+ # v5.1.24 (Fri Sep 13 2024)
2
+
3
+ #### πŸ› Bug Fix
4
+
5
+ - When parsing JSON, we should no attempt to extract implicitly [#96](https://github.com/whotracksme/webextension-packages/pull/96) ([@philipp-classen](https://github.com/philipp-classen))
6
+ - Test fixed: lifted the unintended dependency on the LANG environment [#95](https://github.com/whotracksme/webextension-packages/pull/95) ([@philipp-classen](https://github.com/philipp-classen))
7
+
8
+ #### Authors: 1
9
+
10
+ - Philipp Claßen ([@philipp-classen](https://github.com/philipp-classen))
11
+
12
+ ---
13
+
1
14
  # v5.1.23 (Wed Sep 11 2024)
2
15
 
3
16
  #### πŸ› Bug Fix
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@whotracksme/reporting",
3
- "version": "5.1.23",
3
+ "version": "5.1.24",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "scripts": {
@@ -24,11 +24,18 @@ import { requireParam, requireString, lazyInitAsync } from './utils';
24
24
  * breaks something on Windows.
25
25
  */
26
26
  export default class AliveMessageGenerator {
27
- constructor({ browserInfoProvider, quorumChecker, storage, storageKey }) {
27
+ constructor({
28
+ browserInfoProvider,
29
+ navigatorApi,
30
+ quorumChecker,
31
+ storage,
32
+ storageKey,
33
+ }) {
28
34
  requireParam(browserInfoProvider);
29
35
  this.quorumChecker = requireParam(quorumChecker);
30
36
  this.storage = requireParam(storage);
31
37
  this.storageKey = requireString(storageKey);
38
+ this.navigatorApi = navigatorApi || globalThis.navigator;
32
39
 
33
40
  this.staticConfigProvider = lazyInitAsync(async () =>
34
41
  this._generateBaseConfig(await browserInfoProvider()),
@@ -81,10 +88,10 @@ export default class AliveMessageGenerator {
81
88
 
82
89
  let language;
83
90
  try {
84
- language = navigator.language;
91
+ language = this.navigatorApi.language;
85
92
  } catch (e) {
86
93
  logger.warn(
87
- 'Failed to access the "navigator" (should only happen when run in NodeJs)',
94
+ '"navigator" API unavailable (should only happen when run in NodeJs 20 or lower)',
88
95
  );
89
96
  }
90
97
  language = language || '';
@@ -288,6 +288,9 @@ const TRANSFORMS = new Map(
288
288
  try {
289
289
  let obj = JSON.parse(text);
290
290
  for (const field of path.split('.')) {
291
+ if (!Object.hasOwn(obj, field)) {
292
+ return '';
293
+ }
291
294
  obj = obj[field];
292
295
  }
293
296
  if (typeof obj === 'string') {
@@ -19,6 +19,7 @@ describe('#AliveMessageGenerator', function () {
19
19
 
20
20
  const storageKey = 'some-storage-key';
21
21
  let browserInfoProvider;
22
+ let navigatorApi;
22
23
  let quorumChecker;
23
24
  let storage;
24
25
  let uut;
@@ -29,6 +30,7 @@ describe('#AliveMessageGenerator', function () {
29
30
  function newAliveMessageGenerator() {
30
31
  return new AliveMessageGenerator({
31
32
  browserInfoProvider,
33
+ navigatorApi,
32
34
  quorumChecker,
33
35
  storage,
34
36
  storageKey,
@@ -56,6 +58,9 @@ describe('#AliveMessageGenerator', function () {
56
58
  os: 'Linux',
57
59
  language: 'en-US',
58
60
  };
61
+ navigatorApi = {
62
+ language: 'en-US',
63
+ };
59
64
  browserInfoProvider = async () => _browserInfo;
60
65
 
61
66
  quorumChecker = {
@@ -155,12 +160,14 @@ describe('#AliveMessageGenerator', function () {
155
160
  os: 'Linux',
156
161
  language: 'en-US',
157
162
  };
163
+ navigatorApi.language = 'de-DE';
164
+
158
165
  const message = await uut.generateMessage('de', '2024010203');
159
- expect(message).to.deep.eql({
166
+ expect(message).to.eql({
160
167
  browser: 'Firefox',
161
168
  version: '122', // only major version
162
169
  os: 'Linux',
163
- language: 'en-US',
170
+ language: 'de-DE', // from window.navigator
164
171
  ctry: 'de',
165
172
  t: '2024010203',
166
173
  });
@@ -173,7 +180,7 @@ describe('#AliveMessageGenerator', function () {
173
180
 
174
181
  it('should not share the config', async function () {
175
182
  const message = await uut.generateMessage('de', '2024010203');
176
- expect(message).to.deep.eql({
183
+ expect(message).to.eql({
177
184
  browser: '',
178
185
  version: '',
179
186
  os: '',
@@ -801,6 +801,54 @@ describe('Test builtin primitives', function () {
801
801
  });
802
802
  });
803
803
 
804
+ describe('handling of native properties', function () {
805
+ // The observation is that some property names are implicitly provided:
806
+ //
807
+ // x = '';
808
+ // !!x['foo'] --> false
809
+ // !!x['bar'] --> false
810
+ // !!x['toString'] --> true
811
+ // !!x['__proto__'] --> true
812
+ [
813
+ // this list is incomplete, but should cover all primitive
814
+ '__proto__',
815
+ 'constructor',
816
+ 'hasOwnProperty',
817
+ 'isPrototypeOf',
818
+ 'propertyIsEnumerable',
819
+ 'toLocaleString',
820
+ 'toString',
821
+ 'valueOf',
822
+ 'toExponential',
823
+ 'toFixed',
824
+ 'toPrecision',
825
+ ].forEach((field) => {
826
+ it(`should ignore the inherited ${field} field`, function () {
827
+ expect(uut('"a"', field, true)).to.eql('');
828
+ expect(uut('["a"]', field, true)).to.eql('');
829
+ expect(uut('{"a":"b"}', field, true)).to.eql('');
830
+ });
831
+ });
832
+
833
+ // This is mostly documenting the status quo, which results from
834
+ // Object.has('foo', 'length') being true.
835
+ //
836
+ // Since this is so obscure, we should not built behavior on top of it.
837
+ // However, it is not opening up attacks, so there is also not much
838
+ // benefit in having extra logic to handle this situation.
839
+ it('should gracefully handle the implicit "length" field', function () {
840
+ expect(uut('"foo"', 'length')).to.eql('3');
841
+ expect(uut('"foo"', 'length', true)).to.eql('3');
842
+ });
843
+
844
+ it('should support an explicit "length" field', function () {
845
+ expect(uut('{"height": 17, "length": 42}', 'length')).to.eql('42');
846
+ expect(uut('{"height": 17, "length": 42}', 'length', true)).to.eql(
847
+ '42',
848
+ );
849
+ });
850
+ });
851
+
804
852
  describe('robustness on untrusted data', function () {
805
853
  it('should fail if input is not [string, string, [bool]]', function () {
806
854
  expect(() => uut()).to.throw();