Skip to content

fix: enforce MQTT 5 Receive Maximum for inbound QoS 2 messages (GHSA-h8jm-hm87-fqw3) - #2065

Merged
robertsLando merged 1 commit into
mainfrom
fix/ghsa-h8jm-receive-max
Sep 16, 2026
Merged

robertsLando merged 1 commit into
mainfrom
fix/ghsa-h8jm-receive-max

Conversation

@robertsLando

Copy link
Copy Markdown
Member

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.

@robertsLando
robertsLando force-pushed the fix/ghsa-h8jm-receive-max branch from 46faf82 to c8f2bc2 Compare September 16, 2026 09:03
@robertsLando
robertsLando force-pushed the fix/ghsa-h8jm-receive-max branch from c8f2bc2 to b016f23 Compare September 16, 2026 09:05
@robertsLando
robertsLando force-pushed the fix/ghsa-h8jm-receive-max branch from b016f23 to 966b766 Compare September 16, 2026 09:08
@codecov

codecov Bot commented Sep 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.54%. Comparing base (7108ea5) to head (225f420).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2065      +/-   ##
==========================================
+ Coverage   85.18%   85.54%   +0.35%     
==========================================
  Files          26       26              
  Lines        1715     1757      +42     
  Branches      395      407      +12     
==========================================
+ Hits         1461     1503      +42     
  Misses        220      220              
  Partials       34       34              
Flag Coverage Δ
unittests 85.54% <100.00%> (+0.35%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@robertsLando
robertsLando force-pushed the fix/ghsa-h8jm-receive-max branch from 966b766 to e64ae57 Compare September 16, 2026 09:09
Base automatically changed from fix/ghsa-8phv-dup-connack to main September 16, 2026 09:10
…h8jm-hm87-fqw3)

The client advertised a Receive Maximum and then ignored it on the way
in: a broker could send unlimited QoS 2 PUBLISH packets with distinct
message ids, never send PUBREL, and grow the incoming store without
bound. Reconnecting did not help, because a resumed session keeps its
store.

Inbound QoS 2 message ids are now tracked against the advertised quota,
and a broker that exceeds it is disconnected with 0x93. A redelivery of
a message already held takes no second slot, so DUP still works, and
the PUBREL handler answers a re-sent PUBREL whether or not the store
still has the entry.

The quota is also advertised as the value actually enforced: they 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.

Slots are kept across a reconnect on purpose. They are the bound on the
incoming store, which is session state: releasing them per connection
would let a broker reset the quota by dropping the TCP connection and
grow the store across reconnects, which is the vulnerability itself.
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