systeminformation 5.33.21 → 5.33.23

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/README.md CHANGED
@@ -31,17 +31,17 @@
31
31
  ## The Systeminformation Project
32
32
 
33
33
  This is amazing. Started as a small project just for myself, it now has > 20,000
34
- lines of code, > 750 versions published, up to 50 mio downloads per month, > 700
34
+ lines of code, > 800 versions published, up to 90 mio downloads per month, > 900
35
35
  mio downloads overall. Top 5 NPM ranking for backend packages. Thank you to all
36
36
  who contributed to this project!
37
37
 
38
38
  > ### **Version 6** beta just released ⭐️⭐️⭐️
39
39
  >
40
- > 🏆🏆🏆 We're proud to have just released the first beta of the new version 6 of systeminformation.
40
+ > 🏆🏆🏆 We're proud to have just released the first beta of the new version 6 of systeminformation.
41
41
  > Version 6 of this package (written completely in TypeScript) is
42
42
  > comming with a lot of new features and improvements. We also cleaned up the API so
43
43
  > there will also be some breaking changes.
44
- >
44
+ >
45
45
  > **Thanks to everyone testing this new version!**
46
46
 
47
47
  ## Please support this project ... ☕️
@@ -72,7 +72,7 @@ If you want to test the new version 6.0 (currently in beta), you can eather inst
72
72
  npm i systeminformation@beta
73
73
  ```
74
74
 
75
- Then just test it with your existing code - be sure to check all breaking changes. Docs can be found here:
75
+ Then just test it with your existing code - be sure to check all breaking changes. Docs can be found here:
76
76
 
77
77
  - [V6 Docs][v6-docs-url]
78
78
  - [V6 major changes][v6-changes-url]
@@ -80,12 +80,12 @@ Then just test it with your existing code - be sure to check all breaking change
80
80
  If you want to run the whole test locally on your machines (without writing any code):
81
81
 
82
82
  ```bash
83
- # clone v6 branch
83
+ # clone v6 branch
84
84
  git clone -b v6 https://github.com/sebhildebrandt/systeminformation.git
85
85
  cd systeminformation
86
86
 
87
87
  # install dev dependencies and build
88
- npm ci
88
+ npm ci
89
89
  npm run build
90
90
 
91
91
  # run tests
@@ -1248,4 +1248,4 @@ All other trademarks are the property of their respective owners.
1248
1248
  [mmon-github-url]: https://github.com/sebhildebrandt/mmon
1249
1249
  [smc-code-url]: https://github.com/pcafstockf/smc-reader
1250
1250
  [v6-docs-url]: https://systeminformation.io/v6/
1251
- [v6-changes-url]: https://systeminformation.io/v6/changes.html
1251
+ [v6-changes-url]: https://systeminformation.io/v6/changes.html
package/lib/filesystem.js CHANGED
@@ -1808,7 +1808,7 @@ function diskLayout(callback) {
1808
1808
  workload.push(util.powerShell('Get-PhysicalDisk | select BusType,MediaType,FriendlyName,Model,SerialNumber,Size | fl'));
1809
1809
  if (util.smartMonToolsInstalled()) {
1810
1810
  try {
1811
- const smartDev = JSON.parse(execSync('smartctl --scan -j').toString());
1811
+ const smartDev = JSON.parse(execSync('smartctl --scan -j', util.execOptsWin).toString());
1812
1812
  if (smartDev && smartDev.devices && smartDev.devices.length > 0) {
1813
1813
  smartDev.devices.forEach((dev) => {
1814
1814
  // device names come from smartctl output - never let anything but a plain path reach the shell
package/lib/osinfo.js CHANGED
@@ -16,8 +16,9 @@
16
16
  const os = require('os');
17
17
  const fs = require('fs');
18
18
  const util = require('./util');
19
- const exec = require('child_process').exec;
19
+ const exec = util.execCwd;
20
20
  const execSync = require('child_process').execSync;
21
+ const execFile = require('child_process').execFile;
21
22
 
22
23
  const _platform = process.platform;
23
24
 
@@ -207,11 +208,10 @@ function getFQDN() {
207
208
  }
208
209
  }
209
210
  if (_windows) {
210
- try {
211
- const stdout = execSync('echo %COMPUTERNAME%.%USERDNSDOMAIN%', util.execOptsWin);
212
- fqdn = stdout.toString().replace('.%USERDNSDOMAIN%', '').split(os.EOL)[0];
213
- } catch {
214
- util.noop();
211
+ // read env directly - cmd.exe would interpret metacharacters in expanded values
212
+ const name = process.env.COMPUTERNAME;
213
+ if (name) {
214
+ fqdn = process.env.USERDNSDOMAIN ? name + '.' + process.env.USERDNSDOMAIN : name;
215
215
  }
216
216
  }
217
217
  return fqdn;
@@ -430,20 +430,25 @@ function isUefiWindows() {
430
430
  return new Promise((resolve) => {
431
431
  process.nextTick(() => {
432
432
  try {
433
- exec('findstr /C:"Detected boot environment" "%windir%\\Panther\\setupact.log"', util.execOptsWin, (error, stdout) => {
434
- if (!error) {
435
- const line = stdout.toString().split('\n\r')[0];
436
- return resolve(line.toLowerCase().indexOf('efi') >= 0);
437
- } else {
438
- exec('echo %firmware_type%', util.execOptsWin, (error, stdout) => {
439
- if (!error) {
440
- const line = stdout.toString() || '';
441
- return resolve(line.toLowerCase().indexOf('efi') >= 0);
442
- } else {
443
- return resolve(false);
444
- }
445
- });
433
+ const logFile = util.WINDIR + '\\Panther\\setupact.log';
434
+ const fwEfi = () => (process.env.firmware_type || '').toLowerCase().indexOf('efi') >= 0;
435
+ fs.stat(logFile, (error, stats) => {
436
+ // skip huge logs
437
+ if (error || stats.size > 50 * 1024 * 1024) {
438
+ return resolve(fwEfi());
446
439
  }
440
+ fs.readFile(logFile, 'latin1', (error, content) => {
441
+ const line = !error
442
+ ? content
443
+ .split('\n')
444
+ .filter((l) => l.indexOf('Detected boot environment') >= 0)
445
+ .join('\n')
446
+ : '';
447
+ if (line) {
448
+ return resolve(line.toLowerCase().indexOf('efi') >= 0);
449
+ }
450
+ return resolve(fwEfi());
451
+ });
447
452
  });
448
453
  } catch {
449
454
  return resolve(false);
@@ -1284,14 +1289,12 @@ echo -n "hardware: "; cat /sys/class/dmi/id/product_uuid 2> /dev/null; echo;`;
1284
1289
  });
1285
1290
  }
1286
1291
  if (_windows) {
1287
- let sysdir = '%windir%\\System32';
1288
- if (process.arch === 'ia32' && Object.prototype.hasOwnProperty.call(process.env, 'PROCESSOR_ARCHITEW6432')) {
1289
- sysdir = '%windir%\\sysnative\\cmd.exe /c %windir%\\System32';
1290
- }
1292
+ // Sysnative: 64-bit reg.exe from a 32-bit node process
1293
+ const sysdir = process.arch === 'ia32' && Object.prototype.hasOwnProperty.call(process.env, 'PROCESSOR_ARCHITEW6432') ? 'Sysnative' : 'System32';
1291
1294
  util.powerShell('Get-CimInstance Win32_ComputerSystemProduct | select UUID | fl').then((stdout) => {
1292
1295
  let lines = stdout.split('\r\n');
1293
1296
  result.hardware = util.getValue(lines, 'uuid', ':').toLowerCase();
1294
- exec(`${sysdir}\\reg query "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography" /v MachineGuid`, util.execOptsWin, (error, stdout) => {
1297
+ execFile(util.WINDIR + '\\' + sysdir + '\\reg.exe', ['query', 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography', '/v', 'MachineGuid'], util.execOptsWin, (error, stdout) => {
1295
1298
  parts = stdout.toString().split('\n\r')[0].split('REG_SZ');
1296
1299
  result.os = parts.length > 1 ? parts[1].replace(/\r+|\n+|\s+/gi, '').toLowerCase() : '';
1297
1300
  if (callback) {
package/lib/processes.js CHANGED
@@ -109,6 +109,19 @@ function parseElapsedTime(etime) {
109
109
  // pass a comma separated string with services to check (mysql, apache, postgresql, ...)
110
110
  // this function gives an array back, if the services are running.
111
111
 
112
+ // whitelist via char compare - no String/RegExp prototype methods involved
113
+ function psServiceName(srv) {
114
+ const s = String(srv);
115
+ let name = '';
116
+ for (let i = 0; i < s.length; i++) {
117
+ const c = s[i];
118
+ if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c === ' ' || c === '_' || c === '.' || c === '-' || c === '@') {
119
+ name += c;
120
+ }
121
+ }
122
+ return name;
123
+ }
124
+
112
125
  function services(srv, callback) {
113
126
  callback = util.isFunction(callback) ? callback : null;
114
127
  // fallback - if only callback is given
@@ -136,6 +149,7 @@ function services(srv, callback) {
136
149
  srvString.__proto__.substring = util.stringSubstring;
137
150
  srvString.__proto__.trim = util.stringTrim;
138
151
  srvString.__proto__.startsWith = util.stringStartWith;
152
+ srvString.__proto__.split = util.stringSplit;
139
153
  } catch (e) {
140
154
  Object.setPrototypeOf(srvString, util.stringObj);
141
155
  }
@@ -155,7 +169,7 @@ function services(srv, callback) {
155
169
  if (util.isPrototypePolluted() && srvString !== '*') {
156
170
  srvString = '------';
157
171
  }
158
- let srvs = srvString.split('|');
172
+ let srvs = util.stringSplit.call(srvString, '|');
159
173
  const result = [];
160
174
  const dataSrv = [];
161
175
 
@@ -362,7 +376,7 @@ function services(srv, callback) {
362
376
  wincommand += ' -Filter "';
363
377
  srvs.forEach((srv) => {
364
378
  // whitelist: srv is inserted into a PowerShell string
365
- wincommand += `Name='${srv.replace(/[^a-zA-Z0-9 _.\-@]/g, '')}' or `;
379
+ wincommand += `Name='${psServiceName(srv)}' or `;
366
380
  });
367
381
  wincommand = `${wincommand.slice(0, -4)}"`;
368
382
  }
@@ -1137,6 +1151,7 @@ function processLoad(proc, callback) {
1137
1151
  processesString.__proto__.substring = util.stringSubstring;
1138
1152
  processesString.__proto__.trim = util.stringTrim;
1139
1153
  processesString.__proto__.startsWith = util.stringStartWith;
1154
+ processesString.__proto__.split = util.stringSplit;
1140
1155
  } catch {
1141
1156
  Object.setPrototypeOf(processesString, util.stringObj);
1142
1157
  }
@@ -1157,7 +1172,7 @@ function processLoad(proc, callback) {
1157
1172
  if (util.isPrototypePolluted() && processesString !== '*') {
1158
1173
  processesString = '------';
1159
1174
  }
1160
- const processes = processesString.split('|');
1175
+ const processes = util.stringSplit.call(processesString, '|');
1161
1176
  const result = [];
1162
1177
 
1163
1178
  const procSanitized = util.isPrototypePolluted() ? '' : util.sanitizeShellString(proc) || '*';
package/lib/util.js CHANGED
@@ -48,13 +48,33 @@ const _psError = '--ERROR--';
48
48
  const _psCmdSeperator = '--###ENDCMD###--';
49
49
  const _psIdSeperator = '--##ID##--';
50
50
 
51
+ // cmd.exe and libuv search cwd before PATH: run from system32 so bare names never resolve to files in the caller's cwd (CWE-427)
52
+ const _winSysDir = WINDIR + '\\system32';
53
+
51
54
  const execOptsWin = {
52
55
  windowsHide: true,
53
56
  maxBuffer: 1024 * 102400,
54
57
  encoding: 'UTF-8',
55
- env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' })
58
+ env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' }),
59
+ cwd: _windows && fs.existsSync(_winSysDir) ? _winSysDir : undefined
56
60
  };
57
61
 
62
+ function winCwd(options) {
63
+ if (!execOptsWin.cwd || (options && options.cwd)) {
64
+ return options;
65
+ }
66
+ return Object.assign({}, options, { cwd: execOptsWin.cwd });
67
+ }
68
+
69
+ // child_process.exec with system32 as default cwd on Windows (CWE-427)
70
+ function execCwd(cmd, opts, callback) {
71
+ if (typeof opts === 'function') {
72
+ callback = opts;
73
+ opts = undefined;
74
+ }
75
+ return exec(cmd, winCwd(opts), callback);
76
+ }
77
+
58
78
  const execOptsLinux = {
59
79
  maxBuffer: 1024 * 102400,
60
80
  encoding: 'UTF-8',
@@ -92,6 +112,7 @@ const stringSubstr = new String().substr;
92
112
  const stringSubstring = new String().substring;
93
113
  const stringTrim = new String().trim;
94
114
  const stringStartWith = new String().startsWith;
115
+ const stringSplit = new String().split;
95
116
  const mathMin = Math.min;
96
117
 
97
118
  function isFunction(functionToCheck) {
@@ -365,7 +386,8 @@ function getPowershell() {
365
386
 
366
387
  function getVboxmanage() {
367
388
  const vboxPath = (process.env.VBOX_INSTALL_PATH || process.env.VBOX_MSI_INSTALL_PATH || '').replace(/["%!^&|<>`$;\r\n]/g, '');
368
- return _windows ? `"${vboxPath}\\VBoxManage.exe"` : 'vboxmanage';
389
+ // empty path would give "\VBoxManage.exe" = root of the current drive
390
+ return _windows ? (vboxPath ? `"${vboxPath}\\VBoxManage.exe"` : 'VBoxManage.exe') : 'vboxmanage';
369
391
  }
370
392
 
371
393
  function powerShellProceedResults(data) {
@@ -405,7 +427,8 @@ function powerShellStart() {
405
427
  windowsHide: true,
406
428
  maxBuffer: 1024 * 102400,
407
429
  encoding: 'UTF-8',
408
- env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' })
430
+ env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' }),
431
+ cwd: execOptsWin.cwd
409
432
  });
410
433
  if (_psChild && _psChild.pid) {
411
434
  _psPersistent = true;
@@ -489,7 +512,8 @@ function powerShell(cmd) {
489
512
  windowsHide: true,
490
513
  maxBuffer: 1024 * 102400,
491
514
  encoding: 'UTF-8',
492
- env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' })
515
+ env: Object.assign({}, process.env, { LANG: 'en_US.UTF-8' }),
516
+ cwd: execOptsWin.cwd
493
517
  });
494
518
 
495
519
  if (child && !child.pid) {
@@ -537,7 +561,7 @@ function powerShell(cmd) {
537
561
 
538
562
  function execSafe(cmd, args, options) {
539
563
  let result = '';
540
- options = options || {};
564
+ options = winCwd(options || {});
541
565
 
542
566
  return new Promise((resolve) => {
543
567
  process.nextTick(() => {
@@ -670,7 +694,7 @@ function execWin(cmd, opts, callback) {
670
694
  opts = execOptsWin;
671
695
  }
672
696
  const newCmd = 'chcp 65001 > nul && cmd /C ' + cmd + ' && chcp ' + codepage + ' > nul';
673
- exec(newCmd, opts, (error, stdout) => {
697
+ exec(newCmd, winCwd(opts), (error, stdout) => {
674
698
  callback(error, stdout);
675
699
  });
676
700
  }
@@ -798,6 +822,7 @@ function isPrototypePolluted() {
798
822
  st.__proto__.toString = stringToString;
799
823
  st.__proto__.substr = stringSubstr;
800
824
  st.__proto__.substring = stringSubstring;
825
+ st.__proto__.split = stringSplit;
801
826
  st.__proto__.trim = stringTrim;
802
827
  st.__proto__.startsWith = stringStartWith;
803
828
  } catch (e) {
@@ -2826,6 +2851,7 @@ function isProtoKey(key) {
2826
2851
  exports.toInt = toInt;
2827
2852
  exports.splitByNumber = splitByNumber;
2828
2853
  exports.execOptsWin = execOptsWin;
2854
+ exports.execCwd = execCwd;
2829
2855
  exports.execOptsLinux = execOptsLinux;
2830
2856
  exports.getCodepage = getCodepage;
2831
2857
  exports.execWin = execWin;
@@ -2873,6 +2899,7 @@ exports.stringSubstr = stringSubstr;
2873
2899
  exports.stringSubstring = stringSubstring;
2874
2900
  exports.stringTrim = stringTrim;
2875
2901
  exports.stringStartWith = stringStartWith;
2902
+ exports.stringSplit = stringSplit;
2876
2903
  exports.mathMin = mathMin;
2877
2904
  exports.WINDIR = WINDIR;
2878
2905
  exports.getFilesInPath = getFilesInPath;
package/lib/virtualbox.js CHANGED
@@ -14,8 +14,8 @@
14
14
  // ----------------------------------------------------------------------------------
15
15
 
16
16
  const os = require('os');
17
- const exec = require('child_process').exec;
18
17
  const util = require('./util');
18
+ const exec = util.execCwd;
19
19
 
20
20
  function vboxInfo(callback) {
21
21
  callback = util.isFunction(callback) ? callback : null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "systeminformation",
3
- "version": "5.33.21",
3
+ "version": "5.33.23",
4
4
  "description": "Advanced, lightweight system and OS information library",
5
5
  "license": "MIT",
6
6
  "author": "Sebastian Hildebrandt <hildebrandt@plus-innovations.com> (https://plus-innovations.com)",