Repository navigation
fix: reject an unsolicited AUTH instead of crashing the process (GHSA-fwrw-4mhv-wxvm) - #2063
Merged
Merged
Conversation
This was referenced Sep 16, 2026
Merged
robertsLando
force-pushed
the
fix/ghsa-fwrw-auth
branch
from
September 16, 2026 09:03
f7df90b to
a4ad6a4
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2063 +/- ##
==========================================
+ Coverage 83.91% 85.10% +1.19%
==========================================
Files 26 26
Lines 1672 1692 +20
Branches 388 393 +5
==========================================
+ Hits 1403 1440 +37
+ Misses 236 218 -18
- Partials 33 34 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
robertsLando
force-pushed
the
fix/ghsa-fwrw-auth
branch
from
September 16, 2026 09:05
a4ad6a4 to
dc37942
Compare
…-fwrw-4mhv-wxvm) An AUTH with reason code 24 reached the default handleAuth, which answered with no packet, and _sendPacket was handed undefined: an uncaught TypeError in the stream write path, terminating the process. No enhanced authentication had to be configured for this to be reachable. An AUTH is now rejected when the protocol is not 5, when no Authentication Method was sent in CONNECT (MQTT-4.12.0-6), when the method differs from the one CONNECT carried (MQTT-4.12.0-5), when rc 24 arrives with nothing to continue the exchange, and when the reason code is not one a broker may send (3.15.2.1). Reason code 0 ends the exchange and keeps the connection up. The method is latched from the packet actually written, so a caller mutating options mid-exchange cannot move the goalposts. The teardown is skipped when the exchange belongs to a connection that has already been replaced: handleAuth is application-overridable and answers through a callback, so it can resume long after its connection is gone.
handleAuth is application-overridable and answers through a callback, so a rejection can land after the client has moved on. Without the isCurrent guard the teardown destroys the healthy stream that replaced it; the test holds the exchange open across a reconnect and asserts the live connection survives.
robertsLando
force-pushed
the
fix/ghsa-fwrw-auth
branch
from
September 16, 2026 09:08
dc37942 to
9ddcf10
Compare
robertsLando
added a commit
that referenced
this pull request
Sep 16, 2026
GHSA-8phv-jwjm-93rr) (#2064) ## Summary Fixes **GHSA-8phv-jwjm-93rr** (medium). A broker could make an MQTT.js client re-run its whole connection setup mid-session: in-flight QoS 1 messages resent under their original ids, subscriptions replayed, and the message id state reset underneath a live session. The trigger and the full analysis are in the advisory and stay there until it publishes. Stacked on #2063 (and #2062, #2061, #2060 beneath it); those merge first. ## Fix `src/lib/handlers/connack.ts`, `src/lib/handlers/index.ts`, `src/lib/client.ts`. - [MQTT-3.2.0-2] allows one CONNACK per network connection. A second one is now a protocol error and the connection is dropped. - The gate is "a CONNACK was already handled on this connection" (`connackReceived`), **not** `client.connected`. A refused CONNACK never sets `connected`, so gating on it would let a broker follow a refusal with an accepting CONNACK — in the same chunk, ahead of the teardown — and end up with a connected client the application had already been told had failed. - A refused CONNACK now always tears the connection down. Previously, whenever `reconnectOnConnackError` was off — the default — the socket was left open: the connack timer was already cleared, no keepalive manager existed because the client never became `connected`, and no reconnect was armed, while the broker kept streaming PUBLISHes that were delivered as `message` events to an application that had just been told "Connection refused". `reconnectOnConnackError` now gates only the retry, which is what its name says. - `work()` drops whatever is still queued on a connection the client has moved on from. A CONNACK parked behind a slow `handleMessage` was otherwise judged against the connection that *replaced* it — `connect()` resets `connackReceived` for the new connection, so it passed the gate and `_onConnect` ran against a session it never belonged to. Dropping at the pump covers every handler at once, rather than adding a liveness check to each teardown site. ## Consumer-visible changes - A refused CONNACK now closes the socket in all cases. With `reconnectOnConnackError: false` (the default) the client no longer sits on an open connection after a refusal. Applications that relied on receiving messages after a refusal were relying on a bug. - Event order on a refusal is preserved for `reconnectOnConnackError` users: `error`, then `offline`, then `close`. ## Verification Full node suite on this branch: **1009 tests, 1004 pass, 0 fail, 5 skipped**. Typecheck, lint and build clean. One existing test changed meaning: a topic-alias violation queued on a connection that has since been replaced is now never examined, so it emits nothing instead of an error. Its security assertions — that the dead connection cannot touch the live one — are unchanged.
robertsLando
added a commit
that referenced
this pull request
Sep 16, 2026
…h8jm-hm87-fqw3) (#2065) ## Summary Fixes **GHSA-h8jm-hm87-fqw3** (low). The client advertised a Receive Maximum and then ignored it on inbound QoS 2: a broker could grow the client's incoming store without bound. Reconnecting did not clear it, because a resumed session keeps its store. The trigger and the full analysis are in the advisory and stay there until it publishes. Last of six; stacked on #2064 (and #2063, #2062, #2061, #2060 beneath it). ## Fix `src/lib/client.ts`, `src/lib/handlers/publish.ts`, `src/lib/handlers/pubrel.ts`. - Inbound QoS 2 message ids are tracked against the advertised quota. A broker that exceeds it is disconnected with reason code `0x93` (Receive Maximum exceeded), which §3.3.4 [MQTT-3.3.4-9] is exactly the code for. - A redelivery of a message already held takes no second slot, so DUP redelivery still works [MQTT-4.3.3-10], and the PUBREL handler answers a re-sent PUBREL whether or not the store still holds the entry [MQTT-4.3.3-11]. - The quota is advertised as the value actually enforced. The two differ when the option failed validation, and a rejected `receiveMaximum: 0` on the wire is itself a protocol error (§3.2.2.3.3) the broker would blame us for. - The `receiveMaximum` option is validated and latched at construction, so a caller mutating `options` mid-session cannot disable the check, and a non-number cannot silently defeat it (every comparison against `NaN` is false). ### On slot lifetime Slots are deliberately **kept** across a reconnect. §4.9 describes the flow-control quota as re-initialized per network connection, and read literally that would mean releasing them. They are not released here, because these slots are the bound on the *incoming store*, which is session state: releasing them per connection lets a broker reset the quota by dropping the TCP connection and grow the store across reconnects — the vulnerability itself. The trade-off is that a broker which resumes a session, leaves earlier QoS 2 exchanges unfinished, and then fills the connection to `receiveMaximum` can be disconnected. That requires the broker to leave exchanges unresolved, and the store bound is the property worth keeping. Splitting the two limits — per-connection flow control for the `0x93` decision, a separate store cap refusing the excess with `PUBREC` `0x97` — is a possible follow-up, deliberately not done in a security fix. ## Consumer-visible changes - A broker exceeding the advertised `receiveMaximum` on inbound QoS 2 now gets disconnected instead of being allowed to grow the store. Reconnect behaviour is unchanged. - `properties.receiveMaximum` outside 1..65535, or not an integer, is ignored with a log line and 65535 is enforced and advertised instead. ## Verification Full node suite on this branch: **1030 tests, 1025 pass, 0 fail, 5 skipped**. Typecheck, lint and build clean. With all six merged, the tree is byte-identical to the integration branch the whole set was tested on.
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.
Summary
Fixes GHSA-fwrw-4mhv-wxvm (high). A broker could terminate an MQTT.js client process with a single unsolicited AUTH packet — an uncaught
TypeErrorin the stream write path, where no application code can catch it. Enhanced authentication did not have to be configured for this to be reachable.The trigger and the full analysis are in the advisory and stay there until it publishes.
Stacked on #2062 (and #2061, #2060 beneath it); those merge first.
Fix
src/lib/handlers/auth.ts,src/lib/handlers/index.ts,src/lib/client.ts.An AUTH is now rejected, and the connection dropped, when:
handleAuthdown a weaker path;Reason code 0 ends the exchange successfully and keeps the connection up.
The Authentication Method is latched from the packet actually written, not read from
optionsper packet, so a caller mutatingoptionsmid-exchange cannot move the goalposts.The teardown is skipped when the exchange belongs to a connection that has already been replaced.
client.handleAuthis application-overridable and answers through a callback — an implementation that fetches a token has every reason to be slow — so it can resume long after its connection is gone, and tearing down then would destroy a healthy stream over a dead exchange.Consumer-visible changes
properties.authenticationMethodthat receives an AUTH now emitserrorand drops the connection, where before it crashed the process.handleAuth.Verification
Full node suite on this branch: 978 tests, 973 pass, 0 fail, 5 skipped. Typecheck, lint and build clean.
Merge note: resolves the
_discardParsedPackets/PacketPumpdivergence between this fix and #2060 in favour of the pump, keeping this branch's_authenticationMethodalongside it.