Skip to content

fix: Don't allow publishing wildcards in MQTT topic #27025

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 8, 2025
Merged

Conversation

Koenkk
Copy link
Owner

@Koenkk Koenkk commented Apr 6, 2025

To prevent another: #26939

@Koenkk Koenkk requested a review from Nerivec April 6, 2025 19:43
@Nerivec
Copy link
Collaborator

Nerivec commented Apr 6, 2025

If a publish is done while starting (like that issue), it will still fail to start though since it throws, won't it?

@Koenkk
Copy link
Owner Author

Koenkk commented Apr 7, 2025

In that case e.g. the HA discovery would fail (with a proper error).

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 7, 2025

If one of the extensions throws during start, it will fail to load the extension for example:

try {
await extension.start();
} catch (error) {
logger.error(`Failed to start '${extension.constructor.name}' (${(error as Error).stack})`);
}

Nothing was throwing in that function previously (and no call to publish is try/catch-ed):

zigbee2mqtt/lib/mqtt.ts

Lines 215 to 222 in a2debc0

try {
await this.client.publishAsync(topic, payload, actualOptions);
} catch (error) {
if (!skipLog) {
logger.error(`MQTT server error: ${(error as Error).message}`);
logger.error(`Could not send message: topic: '${topic}', payload: '${payload}`);
}
}

@Koenkk
Copy link
Owner Author

Koenkk commented Apr 8, 2025

Maybe its better to skip the publish and log an error?

@Nerivec
Copy link
Collaborator

Nerivec commented Apr 8, 2025

Probably safer, would have to check every publish calls otherwise, and where they lead 😅

@Koenkk Koenkk merged commit 850f082 into dev Apr 8, 2025
24 checks passed
@Koenkk Koenkk deleted the fix/wildcard-topic branch April 8, 2025 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants