/

CVE-2026-58213

Severity:

HIGH RISK

(7.1)

Command Injection (CWE-74) via MQTT in NATS Server

CVE-2026-58213

Analyzed

Vulnerability type

Category:

Command Injection via Protocol Stream Manipulation

CWE:

CWE-74

Impact:

Unauthorized NATS Protocol Command Injection

Severity:

HIGH RISK

(7.1)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

NATS Server versions prior to 2.14.1 and 2.12.9 improperly handle MQTT subscription filters containing protocol control characters.

Under certain routing conditions, these characters can corrupt the NATS protocol stream and allow injection of unintended NATS operations, becoming risky when untrusted MQTT clients can publish or subscribe freely.

Affected context

This vulnerability occurs in NATS Server deployments that expose MQTT connectivity and forward MQTT subscriptions into NATS routing paths (such as route or leafnode connections).

It is relevant when MQTT clients are permitted to supply arbitrary subscription filters without strict validation and when those filters are propagated into internal NATS protocol streams.

Environments with multi-node NATS clusters or federated leafnodes are more susceptible, particularly where client input is treated as trusted protocol metadata.

Exploit preconditions

  • Attack surface: MQTT listener exposed by NATS Server.
  • Required access: Ability for an MQTT client to connect and create subscription filters (typically network-level access and MQTT credentials if required by deployment).
  • Trigger point: Submission of malicious subscription filters containing NATS protocol control characters that are forwarded to route or leafnode connections.
  • Why exploitation is possible: The server does not properly sanitize or delimit MQTT subscription filters before embedding them into NATS protocol messages, allowing attacker-controlled data to be interpreted as part of the internal NATS command stream.

Why this happens

The root cause is improper neutralization of special elements in input used within a communication protocol, corresponding to CWE-74: Improper Neutralization of Special Elements in Output Used by a Downstream Component.

MQTT subscription filter strings are treated as opaque data and forwarded into NATS routing messages without adequate validation, escaping, or delimitation.

As a result, protocol control characters embedded in the filters can break the expected framing and be parsed as separate NATS protocol commands, enabling unintended operations to be injected into the cluster.

Potential impact

  • An attacker may cause injection of unintended NATS protocol operations (e.g., rogue subscriptions or publications).
  • Cluster routing behavior could be corrupted, potentially leading to message misdelivery or denial of service conditions.
  • Access control assumptions around which subjects are subscribed or published to can be undermined.
  • Message integrity and confidentiality within federated NATS deployments could be weakened through manipulated protocol streams.

General mitigation guidance

Effective mitigation focuses on reducing trust in client-provided subscription filters and enforcing strict protocol boundaries.

Common defensive patterns include:

  • Validating MQTT subscription filters against a conservative character set and rejecting or normalizing inputs containing protocol control characters.
  • Applying robust escaping or delimitation when embedding client input into internal protocol messages to prevent it from being interpreted as commands.
  • Segmenting external MQTT client connections from sensitive routing paths, and using strict authorization policies for routes and leafnodes.
  • Applying least-privilege messaging permissions so that injected commands cannot override critical subjects or system channels even if protocol manipulation occurs.

How teams detect issues like this

Detection commonly involves:

  • Static analysis or configuration review to identify code paths where client-controlled strings are written directly into protocol streams without neutralization.
  • Logging and monitoring of NATS routing and leafnode connections for malformed protocol frames, unexpected subscriptions, or anomalous command sequences.
  • Policy-based checks that enforce allowed character sets and subject patterns for MQTT subscriptions at the edge of the system.
  • Automated security testing and fuzzing of MQTT inputs to observe whether protocol corruption or command injection is possible in cluster communications.

Sources

SourceLink
github.comgithub.com/nats-io/nats-server/commit/366837cfc65ab9ccb4f98193c65e8daf238582d8
github.comgithub.com/nats-io/nats-server/commit/64ebae40051ee497c481e10f316238faf0de1736
github.comgithub.com/nats-io/nats-server/commit/f14856b9e57a36818f43851cb69b6e33670885c9
github.comgithub.com/nats-io/nats-server/pull/8163
github.comgithub.com/nats-io/nats-server/pull/8164
github.comgithub.com/nats-io/nats-server/releases/tag/v2.12.9
github.comgithub.com/nats-io/nats-server/releases/tag/v2.14.1
github.comgithub.com/nats-io/nats-server/security/advisories/GHSA-qrcv-3558-gj4f

Frequently asked

questions

Yes, if the NATS Server exposes an MQTT listener over the network and allows remote clients to create subscriptions, an attacker can attempt to exploit the issue via crafted MQTT subscription filters.

The attacker needs the ability to connect as an MQTT client and issue subscription filters. In many deployments this may require valid credentials, but in less restrictive environments simple network reachability could be sufficient.

The safest pattern is to rigorously validate and neutralize client-controlled input before it is embedded in any internal protocol stream. Enforcing strict character sets and properly delimiting or escaping data prevents it from being parsed as commands by downstream NATS routing components.

Design protocol handling layers so that untrusted input is never mixed directly with control data, apply consistent input validation and output encoding, and include protocol fuzzing and security-focused code review for any gateway that bridges external clients into internal messaging systems.

Find out what's already
exploitable in your codebase.