T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/mqtt-client.js:239
- Finding
- TLS Certificate Verification Is Disabled by Default<![CDATA[ ## Vulnerability Details **File Location**: `scripts/mqtt-client.js`, lines 239-246 **Vulnerability Type**: Improper certificate validation **Risk Level**: High ### Vulnerable Code ```javascript const opts = { clientId: this.options.clientId, reconnectPeriod: this.options.reconnectPeriod, connectTimeout: this.options.connectTimeout, keepalive: this.options.keepalive, clean: true, rejectUnauthorized: false }; ``` ### Technical Analysis The MQTT client unconditionally sets `rejectUnauthorized` to `false`. For TLS-based MQTT connections such as `mqtts://` or secure WebSocket connections, this directs the underlying TLS implementation to accept certificates that cannot be validated against a trusted certificate authority. This disables server authentication and allows self-signed, expired, mismatched, or attacker-controlled certificates to be accepted without warning. Although the project advertises TLS support, encryption without certificate verification does not protect against an active man-in-the-middle attacker. The setting is applied to all connections and cannot be securely overridden through the documented constructor configuration because it is hardcoded in the generated client options. ### Attack Path 1. A victim configures the client to connect to a TLS-enabled MQTT broker. 2. The attacker obtains a network position through a malicious Wi-Fi access point, DNS poisoning, routing manipulation, or a compromised proxy. 3. The attacker redirects the connection to a broker or TLS proxy under their control. 4. The attacker presents a forged or self-signed certificate. 5. The client accepts the certificate because `rejectUnauthorized` is disabled. 6. The client transmits MQTT credentials and traffic through the attacker-controlled endpoint. 7. The attacker can inspect messages, capture credentials, alter published control commands, or inject fabricated broker messages. ### Impact Assessment An attacker with a suitable network posit ...[truncated 486 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Set `rejectUnauthorized` to `true` by default. - Permit certificate verification to be disabled only through an explicit, clearly named development-only option. - Support trusted custom certificate authorities through options such as `ca`, `cert`, and `key`. - Validate that TLS-specific settings are used only with secure MQTT protocols. - Document the risks of disabling certificate verification. - Add automated tests confirming that untrusted, expired, and hostname-mismatched certificates are rejected. A safer implementation would resemble: ```javascript const opts = { clientId: this.options.clientId, reconnectPeriod: this.options.reconnectPeriod, connectTimeout: this.options.connectTimeout, keepalive: this.options.keepalive, clean: true, rejectUnauthorized: this.options.rejectUnauthorized !== false }; if (this.options.ca) opts.ca = this.options.ca; if (this.options.cert) opts.cert = this.options.cert; if (this.options.key) opts.key = this.options.key; ``` ]]>
