Skip to content

Fallback topic detection generates false positives #4706

Closed
@tari

Description

@tari

When the MQTT client ID and topic are set to the same value, received messages are treated as coming in on the fallback topic, rather than the regular topic. For instance, if both are set to sonoff-0000 and the topic is %topic%/%prefix%/, then commands received on the regular topic sonoff-0000/cmnd/ are responded to on the fallback topic cmnd/sonoff-0000/.

While the fallback topic is a useful feature to have (eg #1528, #4190, probably others), the value of fallback_topic_flag in MqttDataHandler depends only on finding the client ID in the topic, rather than it actually being the fallback topic:

 fallback_topic_flag = (strstr(topicBuf, mqtt_client) != NULL);

Since this logical shortcut has bitten multiple users in the past, I think it should be changed to check that the topic is actually the fallback topic (match the beginning against the command prefix); this doesn't break the fallback, but does prevent confusion when users want to make the default topic contain the client ID (which is particularly useful when setting pattern ACLs in mosquitto).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugType - Confirmated BugfixedResult - The work on the issue has ended

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions