← Back to the chapter · Previous detail

Technical detail · MQTT Security Fundamentals

Mosquitto topic rules, patterns and wildcard scope

Mosquitto is an MQTT broker whose access rules grant clients read or write permission on message routes called topics.

In Mosquitto, topic read plant/boiler7/temperature grants one topic. topic write plant/+/temperature permits any one device level, meaning one slash-separated topic component; the plus sign does not bind the route to the logged-in sensor. topic read plant/# covers that branch’s parent and descendants.

On a pattern line, %u substitutes the authenticated username for a whole level. Thus pattern write plant/%u/temperature ties the route to that username: boiler7 maps to the boiler sensor’s plant/boiler7/temperature. On a topic line, %u is literal. %c uses the client ID, whose trust depends on broker policy. Test the login-to-route mapping rather than assuming a placeholder creates isolation.

A root hash filter (#, matching topic levels) excludes topics starting with \$; those namespaces need separately authorized filters. A literal publication topic cannot contain a wildcard. Fewer access rules can also grant broader permissions: reducing a policy’s size does not prove that it preserves the intended audience.

← Back to the chapter · Previous detail