CVE-2026-58213 Overview
CVE-2026-58213 is a protocol injection vulnerability in NATS Server, the high-performance messaging server for NATS.io. The flaw exists in how the MQTT (Message Queuing Telemetry Transport) handler processes subscription filters before forwarding them across the cluster. An authenticated MQTT client can embed NATS protocol control characters inside subscription filters. The server then relays these unsanitized characters through route or leafnode connections, corrupting the forwarded protocol stream. This allows an attacker to inject unintended NATS protocol operations across trusted server-to-server links. The issue is classified under [CWE-74] (Improper Neutralization of Special Elements in Output Used by a Downstream Component). Versions prior to 2.14.1 and 2.12.9 are affected.
Critical Impact
An authenticated MQTT client can inject arbitrary NATS protocol operations into route or leafnode streams, breaking the integrity of inter-server messaging boundaries.
Affected Products
- NATS Server versions prior to 2.12.9 (2.12.x branch)
- NATS Server versions prior to 2.14.1 (2.14.x branch)
- Deployments exposing the MQTT listener with clustering, routes, or leafnode connections enabled
Discovery Timeline
- 2026-07-08 - CVE-2026-58213 published to NVD
- 2026-07-08 - Last updated in NVD database
- Fixed releases v2.12.9 and v2.14.1 published by the NATS maintainers (see NATS Server Release v2.12.9 and NATS Server Release v2.14.1)
Technical Details for CVE-2026-58213
Vulnerability Analysis
NATS Server bridges MQTT clients into the native NATS protocol by translating MQTT topics into NATS subjects. The NATS wire protocol is line-oriented and uses whitespace, carriage returns, and newlines as operation delimiters. When an MQTT subscription filter contained protocol control characters such as spaces or CRLF sequences, the server accepted the value and later serialized it verbatim into the outbound stream sent to routes and leafnodes. Downstream servers parsed the corrupted stream as if it contained additional protocol commands. The result is a classic downstream injection pattern in which trust between clustered NATS servers is abused through an untrusted MQTT input surface.
Root Cause
The root cause is inconsistent input validation between the MQTT subscribe path and the MQTT publish path. The publish path already enforced stricter subject character rules through mqttValidatePublishTopic, while the subscribe/will-topic paths used the more permissive mqttValidateTopic. Control characters that are illegal in NATS subjects were therefore never rejected on subscription filters, and no additional escaping was performed before those filters were forwarded to peer servers.
Attack Vector
Exploitation requires network access to the MQTT listener and valid MQTT credentials. The attacker sends an MQTT SUBSCRIBE (or connects with a crafted Will topic) whose filter contains embedded whitespace or newline bytes. The NATS server translates the filter and forwards it over its route or leafnode connection to other servers in the cluster. Peer servers interpret the injected bytes as new NATS protocol operations, allowing the attacker to smuggle operations across a trust boundary they would not normally be able to reach directly.
// Patch: server/mqtt.go - Use the stricter publish-topic validator on the Will topic
if len(topic) == 0 {
return 0, nil, errMQTTEmptyWillTopic
}
- if err := mqttValidateTopic(topic, "Will topic"); err != nil {
+ if err := mqttValidatePublishTopic(topic, "Will topic"); err != nil {
return 0, nil, err
}
// Convert MQTT topic to NATS subject
Source: NATS Server Commit 366837c
// Patch: server/mqtt.go - Reject control characters on both subscribe and publish paths
errMQTTEmptyUsername = errors.New("empty user name not allowed")
errMQTTTopicIsEmpty = errors.New("topic cannot be empty")
errMQTTPacketIdentifierIsZero = errors.New("packet identifier cannot be 0")
- errMQTTUnsupportedCharacters = errors.New("character ' ' not supported for MQTT topics")
+ errMQTTUnsupportedCharacters = errors.New("character not supported for MQTT topics")
errMQTTInvalidSession = errors.New("invalid MQTT session")
errMQTTInvalidRetainFlags = errors.New("invalid retained message flags")
errMQTTSessionCollision = errors.New("stored session does not match client ID")
Source: NATS Server Commit 64ebae4
Detection Methods for CVE-2026-58213
Indicators of Compromise
- MQTT SUBSCRIBE or CONNECT frames whose topic filters contain whitespace, \r, \n, or other non-printable bytes.
- NATS server logs showing protocol parse errors (Protocol Error, unexpected operations) on route or leafnode connections shortly after MQTT client activity.
- Unexpected SUB, PUB, or UNSUB operations appearing on peer servers with no corresponding legitimate publisher.
- MQTT clients repeatedly disconnecting and reconnecting after sending malformed subscription filters.
Detection Strategies
- Enable verbose or trace logging on the MQTT listener and grep for subscription filters containing control characters or spaces.
- Correlate MQTT client sessions with route/leafnode protocol errors on the same server within a short time window.
- Deploy a network sensor that inspects MQTT SUBSCRIBE packets for topic filters violating the MQTT specification character rules.
- Monitor NATS server metrics for spikes in slow_consumers or protocol parse failures on inter-server links.
Monitoring Recommendations
- Forward NATS server logs and MQTT access logs to a centralized SIEM or data lake for retention and alerting.
- Alert on any peer server reporting Protocol Error on a route or leafnode connection.
- Track the version string reported by each NATS server in the cluster to detect unpatched nodes.
- Baseline expected MQTT subscription topics per client identity and alert on deviations.
How to Mitigate CVE-2026-58213
Immediate Actions Required
- Upgrade all NATS Server instances to 2.12.9 or 2.14.1 or later on every node in every cluster and leafnode hub.
- Rotate MQTT client credentials if logs indicate exploitation attempts.
- Audit account permissions to ensure MQTT users cannot publish or subscribe to sensitive administrative subjects.
- Review route and leafnode authorization to confirm that inter-server trust is scoped as narrowly as practical.
Patch Information
The maintainers released fixes in NATS Server v2.12.9 and NATS Server v2.14.1. The relevant changes are tracked in Pull Request 8163 and Pull Request 8164, with additional hardening in commit f14856b. Full background is documented in the GHSA-qrcv-3558-gj4f advisory.
Workarounds
- Disable the MQTT listener in nats-server.conf if MQTT is not required for the deployment.
- Restrict MQTT listener exposure to trusted network segments only, behind a firewall or service mesh.
- Require strong authentication and per-account isolation for all MQTT clients until patched builds are deployed.
- Terminate MQTT clients that submit subscription filters containing invalid characters at an upstream proxy.
# Configuration example: disable MQTT until all nodes are patched
# /etc/nats/nats-server.conf
# Comment out or remove the mqtt block to disable the listener
# mqtt {
# port: 1883
# no_auth_user: "mqttuser"
# }
# Verify server version after upgrade
# $ nats-server --version
# nats-server: v2.14.1
Disclaimer: This content was generated using AI. While we strive for accuracy, please verify critical information with official sources.

