Repository navigation
fix: parse a minimal Success AUTH packet (Remaining Length 0) - #160
Merged
robertsLando merged 1 commit intoJun 24, 2026
Merged
Conversation
MQTT 5.0 section 3.15.2.2.1 allows the AUTH reason code and property length to be omitted when the reason code is 0x00 (Success) and there are no properties, giving a packet with Remaining Length 0 (bytes `f0 00`). The parser read the reason code unconditionally, so for an empty payload `_parseByte()` returned undefined, failed the reason-code validation, and the packet was rejected with "Invalid auth reason code". Guard the reason-code read with the same remaining-length check that `_parseDisconnect` already uses, defaulting the reason code to 0 when the payload is empty.
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
MQTT 5.0 §3.15.2.2.1 says the AUTH Reason Code and Property Length can be omitted when the Reason Code is
0x00(Success) and there are no Properties — giving an AUTH packet with Remaining Length 0, i.e. the two bytesf0 00. The re-authentication flow (§4.12) ends with the server sending such a Success AUTH, which a compliant peer may encode in this minimal form.The parser rejects it:
Cause
_parseAuth()reads the reason code unconditionally:With Remaining Length 0 there is no reason-code byte, so
_parseByte()returnsundefined,MQTT5_AUTH_CODES[undefined]is falsy, and the packet is dropped. The sibling_parseDisconnect()already handles the analogous DISCONNECTe0 00case by guarding the read withif (this._list.length > 0)and defaulting the reason code to0; AUTH is the only reason-code packet missing that guard.Impact
A spec-compliant minimal Success AUTH from a broker or client doing enhanced/re-authentication is rejected as an error, breaking the auth handshake when interoperating with peers that use the minimal encoding (affects MQTT.js and Aedes).
generate()is unaffected — it always emits the longerf0 02 00 00form — which is why a self round-trip never exposed this; the minimal form only arrives from an external encoder.Fix
Mirror the existing
_parseDisconnectguard: only read/validate the reason code when bytes remain, otherwise default it to0. Non-empty AUTH packets (including invalid reason codes) behave exactly as before.Tests
Added a parse-only case for
f0 00asserting{ cmd: 'auth', reasonCode: 0, length: 0 }. The full suite passes (668) andstandardis clean.