Skip to content

Validate CONNECT Will Topic names and UTF-8 - #2263

Open
YAJeff wants to merge 1 commit into
dotnet:masterfrom
YAJeff:fix/connect-will-topic
Open

YAJeff wants to merge 1 commit into
dotnet:masterfrom
YAJeff:fix/connect-will-topic

Conversation

@YAJeff

@YAJeff YAJeff commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

CONNECT currently accepts invalid Will Topic names, including wildcards, empty names, null characters and malformed UTF-8. Validate the Will Topic while decoding CONNECT, before the server can accept the connection.

The internal reader uses strict UTF-8 decoding and the existing topic-name checks, plus null-character rejection. Both MQTT 3.1.1 and MQTT 5 decoder paths use it. Other string fields and public APIs are unchanged.

Specification basis: MQTT 5.0 sections 3.1.3.3 [MQTT-3.1.3-11], 1.5.4 [MQTT-1.5.4-1, MQTT-1.5.4-2], 4.7.3 [MQTT-4.7.3-1, MQTT-4.7.3-2], and CONNECT validation [MQTT-3.1.4-1]. MQTT 3.1.1 has the corresponding Will Topic, UTF-8, topic-name, and CONNECT validation requirements.
https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html
https://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html

On unmodified master 18731d9, synthetic CONNECT packets with Will Topic a/# receive successful CONNACK under both MQTT 3.1.1 and MQTT 5. The TCP regression tests now observe connection closure before acceptance. Decoder regressions cover empty topics, wildcards, embedded null, overlong encoding, encoded surrogate, invalid leading byte and truncated UTF-8. Positive cases retain ordinary topics, slash/empty levels, dollar prefix, supplementary Unicode, BOM and literal U+FFFD.

Validation:

  • 99 formatter/Will tests passed on each of net8.0 and net10.0.
  • Eight negative decoder cases and two TCP cases fail on unmodified upstream; the six positive cases pass.
  • Full net10.0 Release suite: 501 passed, one existing external-network test failed (Connect_To_Invalid_Server_Wrong_IP: expected cancellation, got connection failure). That exact test passed when run separately on both unmodified master and this branch. No test exclusions or production changes were used to address it.
  • Changed production files pass whitespace verification; git diff --check passes.

Release solution build passed with three warnings in unchanged benchmark code.

This branch has not been deployed

No deployments
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.

1 participant