Improve MQTT topic validation#14099
Merged
Merged
Conversation
Member
|
We support also the old 3.1 / if that also okay for this? |
balloob
reviewed
Apr 26, 2018
| raw_value = value.encode('utf-8') | ||
| except UnicodeError: | ||
| raise vol.Invalid("MQTT topic name/filter must be valid UTF-8 string.") | ||
| vol.Length(min=1, max=65535)(raw_value) |
Member
There was a problem hiding this comment.
This feels weird. Rather have us just check the length and raise if it's outside of our boundaries.
Member
Author
There was a problem hiding this comment.
I agree. Fixed it now :)
Member
Author
|
@pvizeli Theoretically, MQTT 3.1 doesn't specify that topic names must be UTF-8 encoded unicode codepoints. However, there's no mention what other encoding should be used and paho-mqtt encodes all topic names/filters with |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
In order to learn more about the MQTT protocol, I recently created my own MQTT server and client in Rust. This PR takes some of the lessons learned from doing that into the topic name and topic filter validation in Home Assistant.
Specifically (see MQTT 3.1.1 spec):
#must be the last character and must be followed by a topic level separator if it isn't by its own. ("The multi-level wildcard character MUST be specified either on its own or following a topic level separator.")+must be encapsulated by topic level separators. ("Where it is used it MUST occupy an entire level of the filter")These are all only the RFC2119 "MUST NOT" parts. There are some SHOULD NOT specifications which I left out as they are not mandatory
$SYSas publish topic ("The Server SHOULD prevent Clients from using such Topic Names to exchange messages with other Clients.")Checklist:
tox. Your PR cannot be merged unless tests passIf the code does not interact with devices: