Skip to content

Reject duplicate MQTT 5 PUBLISH singleton properties - #2261

Merged
chkr1011 merged 1 commit into
dotnet:masterfrom
YAJeff:fix/mqtt5-publish-singleton-properties
Sep 30, 2026
Merged

chkr1011 merged 1 commit into
dotnet:masterfrom
YAJeff:fix/mqtt5-publish-singleton-properties

Conversation

@YAJeff

@YAJeff YAJeff commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

The MQTT 5 decoder accepts repeated singleton PUBLISH properties and overwrites the earlier value. Track presence within each PUBLISH packet and reject duplicates with MqttProtocolViolationException, including when the first value is zero or empty.

This covers Payload Format Indicator, Message Expiry Interval, Topic Alias, Response Topic, Correlation Data, and Content Type. MQTT 5.0 sections 3.3.2.3.2–3.3.2.3.6 and 3.3.2.3.9 explicitly classify these duplicates as Protocol Errors: https://docs.oasis-open.org/mqtt/mqtt/v5.0/os/mqtt-v5.0-os.html. Repeated User Properties and server-to-client Subscription Identifiers remain supported. MQTT 3 decoding and public APIs are unchanged.

Reproduction on master 18731d9: after a successful MQTT 5 CONNECT, sending QoS 1 PUBLISH bytes 32 0A 00 01 61 00 01 04 01 00 01 00 yields PUBACK despite duplicate Payload Format Indicators. With this change the server closes the connection. The six synthetic decoder regression cases fail on unmodified master; the legal repeated-property control passes.

Validation (Windows, Release):

  • dotnet build MQTTnet.slnx --no-restore --configuration Release: passed; three warnings in unchanged benchmark code.
  • dotnet test --no-restore --framework net10.0 --configuration Release --project Source/MQTTnet.Tests/MQTTnet.Tests.csproj: all 493 tests passed.
  • Formatter test filter on net8.0 and net10.0: all 87 tests passed on each framework, including MQTT 3 serialization coverage.
  • git diff --check and whitespace verification of the changed decoder: passed.

This PR is limited to PUBLISH singleton-property validation.

@chkr1011
chkr1011 merged commit 6e5351c into dotnet:master Sep 30, 2026
6 checks passed
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.

2 participants