Skip to content

Reject MQTT5 PUBLISH with Topic Alias 0 - #326

Merged
popduke merged 2 commits into
apache:mainfrom
RaphaelFakhri:fix/mqtt5-reject-topic-alias-zero
Nov 5, 2026
Merged

popduke merged 2 commits into
apache:mainfrom
RaphaelFakhri:fix/mqtt5-reject-topic-alias-zero

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

Fixes #325

Summary

The MQTT 5.0 specification does not permit a Topic Alias of 0 ([MQTT-3.3.2-8]). MQTT5ProtocolHelper.validatePubMessage only rejected aliases greater than MaxTopicAlias, so a PUBLISH with Topic Alias 0 was routed and alias 0 was stored in the receiver alias map.

This change disconnects the client with reason code 0x94 (Topic Alias invalid) and reports a ProtocolViolation event with statement MQTT5-3.3.2-8, the same handling as an alias above the maximum.

Tests

  • Adds TransientSessionHandlerTest.c2sPubWithZeroTopicAlias. It sends a QoS 1 PUBLISH with Topic Alias 0 and checks for DISCONNECT 0x94, a closed channel, no dist call, and a PROTOCOL_VIOLATION event.
  • The test fails without the fix and passes with it.

@popduke
popduke merged commit eea99b3 into apache:main Nov 5, 2026
5 of 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.

MQTT 5 broker accepts PUBLISH with Topic Alias 0

2 participants