Skip to content

fix(binding-mqtt): answer an unresolved subscribe filter or publish acknowledgement with 0x80 - #3223

Merged
jfallows merged 4 commits into
developfrom
fix/3207-mqtt-unauthorized-filter-as-no-route
Nov 14, 2026
Merged

jfallows merged 4 commits into
developfrom
fix/3207-mqtt-unauthorized-filter-as-no-route

Conversation

@jfallows

@jfallows jfallows commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Description

Zilla does not distinguish "no route" from "no authorized route", so a response must not reveal which topics exist behind a route. Two places answered the two cases differently or with a code that revealed the route; the maintainer decided that both answer 0x80 (Unspecified error) on MQTT 5.

  • Subscribe. A SUBSCRIBE filter that no route matches or that no route authorizes for the client is answered in the SUBACK with 0x80. Before, MqttBindingConfig.resolveSubscribeReasonCode returned 0x87 (Not authorized) when a route matched the topic but its guard rejected the client, and 0x83 when no route matched. MQTT 3.1.1 already answers 0x80 through SUBACK_FAILURE_CODE_V4.
  • Publish. MqttServerFactory.onDecodePublishUnroutable answers an unresolved PUBLISH at QoS 1 and 2 on MQTT 5 with 0x80 in the PUBACK or PUBREC. Before, it answered 0x87 for every unresolved PUBLISH, authorized or not. The QoS 0 and MQTT 3.1.1 path (DISCONNECT 0x83) is unchanged.

What changed in the code:

  • MqttBindingConfig.resolveSubscribeReasonCode returns SUCCESS when resolveSubscribe finds an authorized matching route, otherwise UNSPECIFIED_ERROR. This mirrors resolveSubscribe right above it, which already treats an unauthorized route as no route. The now-unused imports are removed.
  • MqttServerFactory: the fallback when the binding is not found in resolveSubscribeReasonCode uses UNSPECIFIED_ERROR, and onDecodePublishUnroutable passes UNSPECIFIED_ERROR to doEncodePubackV5 and doEncodePubrecV5. The method structure is unchanged; restructuring it into onDecodePublish is a separate issue. Every comparison of a subscription's reason code in the server is == SUCCESS, so the failure code value is carried to the SUBACK and nothing else branches on it.
  • Unchanged: UNSUBSCRIBE handling, malformed or unsupported filters (their DISCONNECT codes), the QoS 0 and v3.1.1 publish DISCONNECT, the application peer's own rejections (publish.qos1.message.rejected, publish.qos2.message.rejected, *.non.successful), and the application scripts (the application peer sees no reason code for a failed filter).

These script changes follow a policy decision, not implementation convenience. The specification allows several codes in both places; 0x80 is the one its tables offer when the Server does not wish to reveal the reason (quoted below). The scripts changed are network v5 client.rpt and server.rpt of:

  • subscribe: subscribe.topic.filters.unroutable.mixed, subscribe.topic.filters.unroutable.all, subscribe.unroutable, subscribe.invalid.topic.guarded.identity.param, subscribe.topic.filter.unauthorized (0x83 to 0x80)
  • publish: publish.qos1.unroutable, publish.qos2.unroutable (0x87 to 0x80)

The network v4 scripts already expect 0x80. session.subscribe.unroutable.resume carries no reason code on the wire.

Fixes #3207

Specification statements

Read myself in the OASIS Standard pages (mqtt-v5.0-os.html and mqtt-v3.1.1-os.html, downloaded, converted to text, read with grep and sed):

  • v5 3.8.4: the Server MUST respond with a SUBACK [MQTT-3.8.4-1]; the SUBACK MUST contain a Reason Code for each Topic Filter/Subscription Option pair [MQTT-3.8.4-6]; this Reason Code "MUST either show the maximum QoS that was granted for that Subscription or indicate that the subscription failed" [MQTT-3.8.4-7]. Nothing requires a particular failure code.
  • v5 Table 3-8 (Subscribe Reason Codes), 0x80 Unspecified error: "The subscription is not accepted and the Server either does not wish to reveal the reason or none of the other Reason Codes apply." The same table defines 0x83 Implementation specific error ("The SUBSCRIBE is valid but the Server does not accept it"), 0x87 Not authorized ("The Client is not authorized to make this subscription") and 0x8F Topic Filter invalid ("The Topic Filter is correctly formed but is not allowed for this Client").
  • v5 Table 3-4 (PUBACK Reason Codes) and Table 3-5 (PUBREC Reason Codes), 0x80 Unspecified error, in both: "The receiver does not accept the publish but either does not want to reveal the reason, or it does not match one of the other values." The PUBACK table also defines 0x83 Implementation specific error ("The PUBLISH is valid but the receiver is not willing to accept it.") and 0x87 Not authorized ("The PUBLISH is not authorized."). Both tables have the same 0x80 row; the PUBREC table's 0x83 and 0x87 rows were not read separately beyond the shared 0x80 row.
  • v5 4.13.2: acknowledgements with a Reason Code of 0x80 or greater indicate the packet was in error, with no consequences for other Sessions or Packets (read at the passage that begins "SUBACK, UNSUBACK with a Reason Code of 0x80 or greater").
  • v3.1.1 3.8.4: the SUBACK return code "MUST either show the maximum QoS that was granted for that Subscription or indicate that the subscription failed" [MQTT-3.8.4-5].

Not read for this change: the rest of the specification beyond the clauses and tables above. The v3.1.1 SUBACK return-code table (0x80 as the only failure code) was relied on from #3191 and the existing SUBACK_FAILURE_CODE_V4 mapping rather than re-read. The PUBREL and PUBCOMP tables were not read; they are not touched.

Test evidence

Test-first: the first commit of this change (316a181e7) holds only the script changes. Against the production code of the previous head (5b43da842), run as ./mvnw clean verify -pl runtime/binding-mqtt -Dit.test=..., all seven affected tests failed with a ComparisonFailure on the reason code. The 10-second timeouts alongside some of them follow the mismatch.

  • server.v5.SubscribeIT: shouldSubscribeTopicFiltersUnroutableMixed, shouldSubscribeTopicFiltersUnroutableAll, shouldSubscribeUnroutable, shouldSubscribeInvalidTopicGuardedIdentityParam, shouldSubscribeTopicFilterUnauthorized: expected SUBACK [0x80], but was [0x83] (Specified behavior did not match expected:<...[0x8[0] # reason code...> but was:<...[0x8[3]]...>).
  • server.v5.PublishIT: shouldPublishQos1Unroutable, shouldPublishQos2Unroutable: expected PUBACK/PUBREC [0x80], but was [0x87] (<...et id = 1 [0x8[0] # reason code...> but was:<...et id = 1 [0x8[7] # reason code...>).

The spec peer-to-peer ITs agree with the scripts because client and server scripts changed together. The second commit (c2f699c60) holds the production change.

After the fix, clean install with -Dmaven.build.cache.skipCache=true, checkstyle and license checks on, upstream modules installed first (-Dskip.checks=true, tests skipped), at head c2f699c60:

  • specs/binding-mqtt.spec: 518 ITs, 0 failures, 2 skipped (+ 78 unit and schema tests, 4 skipped)
  • specs/binding-mqtt-kafka.spec: 279 ITs, 0 failures (+ 27 unit tests)
  • runtime/binding-mqtt: 419 ITs, 0 failures, 6 skipped (+ 44 unit tests)
  • runtime/binding-mqtt-kafka: 160 ITs, 0 failures (+ 10 unit tests)

No script of binding-mqtt-kafka changed and MqttBindingConfig is not used by it; both mqtt-kafka modules are verified as dependents.

Not run: the full reactor with -am (the build module's notice check cannot resolve snapshot siblings in this sandbox), examples/, and the other protocol modules.

Not delivered

  • The restructure of onDecodePublishUnroutable into onDecodePublish: a separate issue after this lands.
  • QoS 0 and MQTT 3.1.1 publish keep the DISCONNECT 0x83 path.

Follow-ups

  1. Restructure onDecodePublishUnroutable into onDecodePublish (separate issue, as above).
  2. mqtt-kafka route mismatch and the other items listed in fix(binding-mqtt): answer an unroutable filter with a per-filter suback failure #3191 remain as noted there.

🤖 Generated with Claude Code

https://claude.ai/code/session_01SiHVoWYdVYDvbXA5Wqhtso

@jfallows jfallows changed the title fix(binding-mqtt): answer an unauthorized subscribe filter as a filter that no route matches fix(binding-mqtt): answer an unresolved subscribe filter or publish acknowledgement with 0x80 Nov 14, 2026
@jfallows
jfallows added this pull request to stack #3236 November 14, 2026 23:00
@jfallows
jfallows merged commit a36bdd0 into develop Nov 14, 2026
17 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: answer a filter that no route authorizes the same way as a filter that no route matches

2 participants