Search code examples
mqttmosquitto

MQTT subscribe to # topic allows the user to read all messages?


I was reading this about topic subscription. So if I subscribe using a wild card, to the # topic, then I will receive all the messages.

Does that mean I could intercept the communication? When someone is publishing a message to a secret topic, then I will also get it.

Obviously that is not the case. But what am I missing?

On a related issue, how does the broker prevent users from subscribing to specific topics or publising to other? I assume not anybody can just send data to a broker. Is it somehow similar to HTTP?


Solution

  • With the basic out of the box configuration, anybody can connect to the broker and subscribing to # will get all the messages published and you can publish to any topic you want.

    The MQTT protocol includes support for authentication as part of setting up a connection to the broker. Once you have an authenticated user it becomes possible to apply rules to what that user can do. Different brokers implement how create those rules in different ways, but mosquitto has support for ACLs.

    With the ACL you can define what topics a user can subscribe and publish to. The built in mechanism for this is a flat file, but there is also support for a plugin system that allows you to keep username/password and allowed topics in a database. This allows the ACL to be easily updated without having to restart the broker.