Skip to content

MQTT userProperties set in server node not working, and additional properties cannot be set in mqtt node or in message #5360

Closed

Description

@colinl

Current Behavior

Using MQTT v5 there are three places that userProperties may be set

  1. In the mqtt server config node
  2. In the mqtt out node
  3. In the message passed to the mqtt out node

The problems are
a. Case 1 does not work at all
b. Case 2 works
c. case 3 works provided there are no properties specified in the mqtt out node Moved to #5435

Expected Behavior

User Properties should add to or but not replace properties set at a lower level. In other words properties set in the message should add to or override properties set in the mqtt node or the server, and properties set in the mqtt out node should add to or override those set in the server.

Steps To Reproduce

Import the flow below. The server is configured for localhost v5 with a user property configured.

  1. Click the first inject node. Neither the message nor the mqtt node apply properties so the property in the server should be used. This does not appear to work.
  2. Click the second inject node. In this case the mqtt node applies properties. These appear correctly, but the server node property does not.
  3. Click the third inject node. Here the message adds a property and also attempts to override a property set in the mqtt node. Only the node set properties appear, the message properties are ignored. The new property set in the message should be added, but the property set in the mqtt node should not be overwritten.
  4. Click the fourth inject node. This applies properties via the message, with none in the node. This works correctly, apart from that set in the server not appearing.

Example flow

[{"id":"101662ea1a601b72","type":"group","z":"bdd7be38.d3b55","name":"MQTT V5 user properties test","style":{"label":true},"nodes":["bd4e091b8f34d0f6","36235538daae95f6","7c589f639b71196f","b901d49cc8ef4bb0","680554c9b3efe275","50839f1fc7eea6c0","9c280e478b3ffd3e","644efb312c8bbd20","a04f9a771f7af022"],"x":14,"y":1759,"w":612,"h":342},{"id":"bd4e091b8f34d0f6","type":"mqtt out","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"localhost V5 with nodeSetProperty","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"{\"nodeSetProperty\": \"node\", \"propertyOne\": \"One set in out node\"}","correl":"","expiry":"","broker":"eb44199345bf39bb","x":460,"y":1880,"wires":[]},{"id":"36235538daae95f6","type":"inject","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"set propertyOne and Two","props":[{"p":"topic","vt":"str"},{"p":"payload"},{"p":"userProperties","v":"{\"propertyOne\": \"One\", \"property2\": \"Two\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test/topic","payload":"","payloadType":"date","x":170,"y":1920,"wires":[["bd4e091b8f34d0f6"]]},{"id":"7c589f639b71196f","type":"mqtt in","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"","topic":"test/topic","qos":"2","datatype":"auto-detect","broker":"eb44199345bf39bb","nl":false,"rap":true,"rh":0,"inputs":0,"x":110,"y":2060,"wires":[["b901d49cc8ef4bb0"]]},{"id":"b901d49cc8ef4bb0","type":"debug","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":260,"y":2060,"wires":[]},{"id":"680554c9b3efe275","type":"inject","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"No msg properties","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test/topic","payload":"","payloadType":"date","x":150,"y":1800,"wires":[["50839f1fc7eea6c0"]]},{"id":"50839f1fc7eea6c0","type":"mqtt out","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"localhost V5 no node property","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"eb44199345bf39bb","x":450,"y":1800,"wires":[]},{"id":"9c280e478b3ffd3e","type":"inject","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"No msg properties","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test/topic","payload":"","payloadType":"date","x":150,"y":1860,"wires":[["bd4e091b8f34d0f6"]]},{"id":"644efb312c8bbd20","type":"mqtt out","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"localhost V5 no node property","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"eb44199345bf39bb","x":450,"y":1980,"wires":[]},{"id":"a04f9a771f7af022","type":"inject","z":"bdd7be38.d3b55","g":"101662ea1a601b72","name":"set propertyOne and Two","props":[{"p":"topic","vt":"str"},{"p":"payload"},{"p":"userProperties","v":"{\"propertyOne\": \"One\", \"property2\": \"Two\"}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"test/topic","payload":"","payloadType":"date","x":170,"y":1980,"wires":[["644efb312c8bbd20"]]},{"id":"eb44199345bf39bb","type":"mqtt-broker","name":"localhost v5 with source property","broker":"localhost","port":1883,"clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"5","keepalive":60,"cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"{\"source\":\"tigger\"}","sessionExpiry":""}]

Environment

  • Node-RED version: 4.1.1
  • Node.js version: 22.21.0
  • npm version:
  • Platform/OS: Ubuntu
  • Browser:

Activity

  1. dceejay commented on Nov 28, 2025

    @dceejay
    Member

    In general properties set in the node should not get overwritten - as the author has presumably set them for a reason - so they should be respected, and not be overwritten by the msg.

  2. colinl commented on Nov 28, 2025

    @colinl
    ContributorAuthor

    I may be persuaded of that, but the message should be able to add new properties.

  3. dceejay commented on Nov 29, 2025

    @dceejay
    Member

    yes - I can't disagree with that.

  4. colinl commented on Dec 1, 2025

    @colinl
    ContributorAuthor

    I will rephrase the description to only allow the addition of new properties.

  5. changed the title [-]MQTT userProperties all messed up[/-] [+]MQTT userProperties set in server node not working, and additional properties cannot be set in mqtt node or in message[/+] on Dec 1, 2025
  6. colinl commented on Dec 16, 2025

    @colinl
    ContributorAuthor

    @dceejay is this in your area of code? If so is it likely to get looked at in the near future?

  7. dceejay commented on Dec 16, 2025

    @dceejay
    Member

    Hi no. It's @Steve-Mcl for this one I think

  8. colinl commented on Dec 17, 2025

    @colinl
    ContributorAuthor

    @Steve-Mcl will be thinking "Oh no, not something else for that fellow to hassle me about".

  9. Dennis-SEG commented on Dec 17, 2025

    @Dennis-SEG
    Contributor

    Feature Request: Environment/Global Variables for MQTT Node Authentication

    Problem

    Currently, the Node-RED MQTT broker node requires credentials (username/password) to be hardcoded via the UI. For mass device rollouts, this means:

    • Each device must be individually configured via developer mode
    • Credentials are stored in plain text in the flow configuration
    • No option for centralized credential management
    • Time-consuming and error-prone at scale

    Proposed Solution

    Support for env variables and/or global context variables in the MQTT broker node authentication fields:

    Username: ${MQTT_USERNAME}
    Password: ${MQTT_PASSWORD}
    

    Or via global context:

    Username: global.get("mqtt_credentials.username")
    Password: global.get("mqtt_credentials.password")
    

    Benefits

    Aspect Current With env/global support
    Mass rollout Per-device configuration Single image deployment
    Security Credentials in flow.json Credentials in environment
    Management Developer mode required Backend-controlled provisioning
    Scalability Poor Excellent

    Use Case: Industrial IoT Deployments

    When deploying hundreds of EMS devices:

    1. Base image is flashed with standard Node-RED flows
    2. Environment variables are pushed via provisioning backend
    3. Device boots → reads credentials from env → automatically connects to MQTT broker
    4. Zero-touch deployment without developer mode access
  10. knolleary commented on Dec 17, 2025

    @knolleary
    Member

    @Dennis-SEG as that is not related to this issue, can you raise a separate issue for your topic rather than tag it on as a comment here.

  11. thalesmaoa commented on Jan 14, 2026

    @thalesmaoa
    1. Click the first inject node. Neither the message nor the mqtt node apply properties so the property in the server should be used. This does not appear to work.

    I'm sorry, but I'm a little confused. I'm facing the same issue. If I can set it inside server config, why it doesn't work?

  12. colinl commented on Jan 14, 2026

    @colinl
    ContributorAuthor

    If I can set it inside server config, why it doesn't work?

    Because there is a bug in the code. The point of this issue is to report the bugs.

  13. Steve-Mcl commented on Jan 14, 2026

    @Steve-Mcl
    Contributor

    If I can set it inside server config, why it doesn't work?

    Because there is a bug in the code. The point of this issue is to report the bugs.

    There may well be a bug (I'd need to do some testing) but do you have an mqtt broker that requires user property values in the connection? It's not typically something you would stumble on.

    As stated in the spec https://docs.oasis-open.org/mqtt/mqtt/v5.0/mqtt-v5.0.html:

    3.1.2.11.8 User Property
    38 (0x26) Byte, Identifier of the User Property.

    Followed by a UTF-8 String Pair.

    The User Property is allowed to appear multiple times to represent multiple name, value pairs. The same name is allowed to appear more than once.

    Non-normative comment

    User Properties on the CONNECT packet can be used to send connection related properties from the Client to the Server. The meaning of these properties is not defined by this specification


    case 3 works provided there are no properties specified in the mqtt out node

    In general properties set in the node should not get overwritten - as the author has presumably set them for a reason - so they should be respected, and not be overwritten by the msg.

    This ☝️

    I may be persuaded of that, but the message should be able to add new properties

    yes - I can't disagree with that.

    But yes, on reflection, I can't argue with that either.

    @knolleary @dceejay should ask the OP to make a separate FR issue for this specific point? (This issue has a lot of noise)

  14. colinl commented on Jan 15, 2026

    @colinl
    ContributorAuthor

    do you have an mqtt broker that requires user property values in the connection? It's not typically something you would stumble on.

    I have a system with multiple brokers (mosquitto) and use Bridging to synchronise data across brokers. In order that I can determine which system is the original source for a topic I add add a source user property containing the system name. The logical place to put this is in the broker config.

    ask the OP to make a separate FR issue for this specific point? [Adding new properties in message]

    I will do that.

  15. Steve-Mcl commented on Jan 15, 2026

    @Steve-Mcl
    Contributor

    do you have an mqtt broker that requires user property values in the connection? It's not typically something you would stumble on.

    I have a system with multiple brokers (mosquitto) and use Bridging to synchronise data across brokers. In order that I can determine which system is the original source for a topic I add add a source user property containing the system name. The logical place to put this is in the broker config.

    That's not what the server user props are for I'm afraid. They are intended to be part of the CONNECT whereby a very specific broker might use "user properties" during the connect to perform some operation (perhaps check a JWT or other type of identification or logic). They are not there for general common setting.

  16. colinl commented on Jan 15, 2026

    @colinl
    ContributorAuthor

    Yes, I think you are right. Since I have no evidence that this does not work correctly I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions