homebridge-lg-thinq-2 2.0.12 → 2.0.13

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,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## v2.0.13
4
+
5
+ ### Security
6
+
7
+ * Fixed the host name checks that pick the root certificate for the MQTT connection: the dots in the patterns were not escaped, so they matched any character and host names that only looked like AWS IoT or LG hosts. Found by CodeQL.
8
+ * When migrating cache files from older versions, each file is now checked and read through the same open file, so it cannot be replaced in between. Found by CodeQL.
9
+
10
+ ### Development
11
+
12
+ * Hardened the GitHub Actions workflows: the CI workflow now has a read-only token, actions are pinned to commit SHAs, dependencies are installed without running their install scripts (`npm ci --ignore-scripts`), jobs have time limits, and newer pushes to a pull request cancel older checks.
13
+ * Added Dependabot version updates for npm and GitHub Actions (weekly, development dependencies grouped), and CodeQL code scanning for JavaScript and TypeScript.
14
+
3
15
  ## v2.0.12
4
16
 
5
17
  ### Homebridge UI
@@ -2,6 +2,20 @@ import NodePersist from 'node-persist';
2
2
  import Fs from 'fs/promises';
3
3
  import Path from 'path';
4
4
  import Crypto from 'crypto';
5
+ /** Reads a file as UTF-8, or returns null if it is missing or not a regular file. */
6
+ async function readRegularFile(path) {
7
+ const handle = await Fs.open(path, 'r').catch(() => null);
8
+ if (!handle) {
9
+ return null;
10
+ }
11
+ try {
12
+ const stat = await handle.stat();
13
+ return stat.isFile() ? await handle.readFile({ encoding: 'utf8' }) : null;
14
+ }
15
+ finally {
16
+ await handle.close();
17
+ }
18
+ }
5
19
  export function isPersistCacheMiss(value) {
6
20
  return value === null || value === undefined;
7
21
  }
@@ -58,15 +72,15 @@ export default class Persist {
58
72
  continue;
59
73
  }
60
74
  const p = Path.join(this.dir, f);
61
- const stat = await Fs.stat(p).catch(() => null);
62
- if (!stat || !stat.isFile()) {
63
- continue;
64
- }
65
75
  if (/^[a-f0-9]{64}$/.test(f)) {
66
76
  continue;
67
77
  }
68
78
  try {
69
- const raw = await Fs.readFile(p, { encoding: 'utf8' });
79
+ // Check and read the same open file, so it cannot be replaced in between.
80
+ const raw = await readRegularFile(p);
81
+ if (raw === null) {
82
+ continue;
83
+ }
70
84
  const parsed = JSON.parse(raw);
71
85
  const key = parsed && typeof parsed === 'object' && parsed.key ? parsed.key : f;
72
86
  const datum = { key, value: parsed && parsed.key ? parsed.value ?? parsed : parsed, ttl: undefined };
@@ -12,11 +12,14 @@ export const MQTT_CLIENT_PATH = 'service/users/client';
12
12
  export const MQTT_CERTIFICATE_PATH = 'service/users/client/certificate';
13
13
  export const MQTT_RETRY_ATTEMPTS = 5;
14
14
  export const MQTT_RETRY_DELAY_MS = 5000;
15
+ // Dots are escaped: an unescaped "." matches any character, so other hosts could match.
16
+ const AWS_ATS_MQTT_HOST = /^[^.]+-ats\.iot\.[^.]+\.amazonaws\.com$/;
17
+ const LG_MQTT_HOST = /^[^.]+\.iot\.ruic\.lgthinq\.com$/;
15
18
  export function rootCaUrlForMqttHost(hostname) {
16
- if (hostname.match(/^([^.]+)-ats.iot.([^.]+).amazonaws.com$/g)) {
19
+ if (AWS_ATS_MQTT_HOST.test(hostname)) {
17
20
  return ATS_ROOT_CA_URL;
18
21
  }
19
- if (hostname.match(/^([^.]+).iot.ruic.lgthinq.com$/g)) {
22
+ if (LG_MQTT_HOST.test(hostname)) {
20
23
  return LG_ROOT_CA_URL;
21
24
  }
22
25
  return LEGACY_ROOT_CA_URL;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "displayName": "Homebridge LG ThinQ 2",
3
3
  "name": "homebridge-lg-thinq-2",
4
- "version": "2.0.12",
4
+ "version": "2.0.13",
5
5
  "description": "Community-maintained continuation of homebridge-lg-thinq: a Homebridge plugin for controlling/monitoring LG ThinQ devices via the LG ThinQ platform.",
6
6
  "license": "Apache-2.0",
7
7
  "type": "module",