Skip to content

MQTT broker credentials logged in plaintext at INFO level #424

Description

@gandy92

When connecting to the MQTT broker, hm2mqtt logs the full broker connection string at INFO level, including embedded credentials:

Connecting to MQTT broker at mqtt://<username>:<password>@<host>:<port> with client ID <clientId>

This comes from src/mqttClient.ts line 50:

`Connecting to MQTT broker at ${this.config.brokerUrl} with client ID ${this.config.clientId}`,

Since brokerUrl can include username:password@host:port (as documented in the README, e.g. mqtt://username:password@host:1883), the password ends up in plaintext in application logs — at INFO level, not just DEBUG, so it's not something a user can avoid by lowering log verbosity. In containerized/addon environments (e.g. the Home Assistant add-on) these logs are often persisted, viewed via a web UI, or shared for troubleshooting, which makes this an easy way to accidentally leak a broker password.

Suggested fix: strip or mask the userinfo portion of the URL before logging it, e.g. via new URL(brokerUrl) and clearing .username/.password, or a simple regex replacing user:pass@ with ***@.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions