Skip to content

fix(mqtt): echo auth method on CONNACK for enhanced auth (MQTT 5 §3.2.2.3.10) - #13907

Merged
ArnabChatterjee20k merged 2 commits into
mainfrom
fix-mqtt-connack-auth-method
Sep 25, 2026
Merged

ArnabChatterjee20k merged 2 commits into
mainfrom
fix-mqtt-connack-auth-method

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

What

For enhanced-authentication MQTT connections, the broker now echoes the CONNECT's Authentication Method property back on the CONNACK.

Why

MQTT 5.0 §3.2.2.3.10 requires that when a client sets an Authentication Method in CONNECT (enhanced auth), the server includes the same Authentication Method in its CONNACK. The broker's Connack::accept() (and the refusal CONNACKs) sent no such property, so:

  • Strict, spec-compliant clients (e.g. HiveMQ 5) — used for native background push delivery — reject the CONNACK and disconnect with:
    Mqtt5ConnAckException: Auth method in CONNACK must be present.
    
  • Lenient clients (mqtt.js) don't enforce the rule, so foreground connections worked — which is why this surfaced only for real background delivery.

Login/JWT/origin were all fine; the sole failure was the missing CONNACK property.

Change

Handler::onConnect attaches the CONNECT's authentication method to every CONNACK — accept and refuse — via a small connackProperties() helper (refusals still carry the Appwrite error as the Reason String). The AUTH/reauth path already echoed the method. The library already encodes CONNACK properties (V5::connack), so no library change was needed.

Test

E2E testConnackEchoesAuthMethod (--group mqtt): a successful enhanced-auth CONNECT asserts the CONNACK carries the method (appwrite-jwt). MqttSubscriber now parses the CONNACK Authentication Method (0x15) alongside the reason string.

MQTT 5.0 (§3.2.2.3.10) requires the server to echo the CONNECT's Authentication
Method property on the CONNACK when the client uses enhanced authentication. The
broker's accept/refuse CONNACKs omitted it, so strict clients (e.g. HiveMQ, used
for native background delivery) rejected the connection with "Auth method in CONNACK
must be present"; lenient clients (mqtt.js) accepted it, which hid the bug.

onConnect now attaches the CONNECT's authentication method to every CONNACK (accept
and refuse) via connackProperties(); refusals still carry the reason string. AUTH
(reauth) already echoed the method. Covered by an e2e that asserts the CONNACK
carries the method.
@greptile-apps

greptile-apps Bot commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[Medium risk] MQTT connection handler now echoes authentication method.

The PR appears safe to merge; no outstanding findings remain.

Summary

The PR echoes the CONNECT Authentication Method on accepted and refused MQTT 5 CONNACKs and adds end-to-end assertions for both outcomes. The previous request for refusal coverage is now satisfied.

Reviews (2) · Last reviewed commit: "test(mqtt): assert the auth method is ec..."

The refusal path also attaches the authentication method, so cover it alongside the
accept case to catch a regression in either response.
@ArnabChatterjee20k
ArnabChatterjee20k merged commit 3ee4002 into main Sep 25, 2026
49 checks passed
@github-actions

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix-mqtt-connack-auth-method (after).

Metric Before After Change
🚀 Requests/sec 200.81 205.84 ⚪ +2.5%
⏱️ Latency P50 87.52 ms 84.71 ms ⚪ -3.2%
⏱️ Latency P95 198.08 ms 195.22 ms ⚪ -1.4%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 84.71 195.22 12,996 205.84 -2.86
Account 165.38 293.72 684 11.33 -5.9
TablesDB 81.8 144.9 7,068 114.12 -18.18
Storage 79.09 164.43 3,420 56.67 -3.25
Functions 123.36 240.38 1,824 30.88 +2.37

Top API waits (after)

API request Max wait (ms)
functions.variables.update 514.61
account.name.update 402.53
functions.create 400.55
tablesdb.rows.delete 367.35
account.get 346.48

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