Skip to content

fix: refuse No Local on a shared subscription - #2144

Open
Xnadir wants to merge 1 commit into
mqttjs:mainfrom
Xnadir:fix/shared-sub-no-local
Open

Xnadir wants to merge 1 commit into
mqttjs:mainfrom
Xnadir:fix/shared-sub-no-local

Conversation

@Xnadir

@Xnadir Xnadir commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

subscribe() sends No Local on a shared subscription. That is a Protocol Error [MQTT-3.8.3-4], and a server must close the connection on a Protocol Error. subscribe() has already stored the topic for resubscribe by then, so every reconnect sends it again.

const client = mqtt.connect('mqtt://localhost', { protocolVersion: 5 })
client.once('connect', () =>
  client.subscribe('$share/group/t', { qos: 1, nl: true }, (err) => console.log(err?.message)),
)
// main: the SUBSCRIBE is sent with No Local set
// here: "No Local is not allowed on shared subscription $share/group/t", nothing is sent or stored

On MQTT 5, subscribe() now gives its callback an error when a $share/ topic filter has nl: true, either from the options or from a subscription map, the same way it already handles an invalid topic. No Local on a normal topic, and a shared subscription without it, are sent as before. MQTT 3.1.1 has no No Local flag, so it is unchanged. (The Aedes in devDependencies has no MQTT 5 support, so I couldn't show the broker side in a test; the test checks that nothing is sent or stored.)

Tests

  • should refuse No Local on a shared subscription and send no SUBSCRIBE (string + options and subscription-map forms; nl: true on a normal topic and nl: false on a shared one still go out). It fails on main and passes here.

On Windows a full run of client_mqtt5.ts stops after the first keepalive tests, on main as well; with the keepalive suite skipped it shows the same failures as main. eslint and tsc --noEmit are clean.

This change was written with the help of Claude Code (AI). I reviewed it and ran the tests above.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.86%. Comparing base (61d7b34) to head (58e6f14).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2144      +/-   ##
==========================================
+ Coverage   88.81%   88.86%   +0.04%     
==========================================
  Files          26       26              
  Lines        1905     1913       +8     
  Branches      453      457       +4     
==========================================
+ Hits         1692     1700       +8     
  Misses        173      173              
  Partials       40       40              
Flag Coverage Δ
unittests 88.86% <100.00%> (+0.04%) ⬆️

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.

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