Mar 24, 2026·6 min read·182 visits
A session hijacking vulnerability in NATS-Server allows an unauthenticated attacker to intercept private MQTT messages by exploiting Client ID hash collisions and null-byte truncation.
NATS-Server versions prior to 2.11.15 and 2.12.5 contain multiple vulnerabilities within the MQTT session management and packet parsing logic. These flaws, notably a Client ID hash collision weakness and null-byte truncation, allow unauthenticated remote attackers to hijack active MQTT sessions and intercept private message streams.
NATS-Server implements an MQTT interface backed by its JetStream persistence engine. The system relies on Client IDs to map incoming connections to existing message streams and subscriptions. An unauthenticated remote attacker can manipulate these Client IDs to bypass authentication mechanisms and hijack active sessions.
The vulnerability comprises several distinct software defects affecting how the server processes MQTT identifiers. The primary defect involves a hash collision weakness within the session persistence layer. Secondary defects include improper input validation concerning null-byte truncation and protocol desynchronization in fixed-size control packets.
Successful exploitation allows the attacker to assume the identity of a legitimate client. The server subsequently routes the victim's private message stream to the attacker. This exposes sensitive data and potentially disrupts the legitimate client's connection.
The JetStream backend uses a custom hashing function to optimize lookups for persisted MQTT sessions. When a client reconnects with the cleanSession=false flag, the server calculates the hash of the provided Client ID to retrieve the corresponding session state. The server failed to verify that the string identifier of the retrieved session matched the string identifier of the requesting client.
This logical omission creates a direct session hijacking vector. If two distinct Client IDs produce identical hash values, the server treats them as the same entity. The custom hashing algorithm used by NATS-Server exhibits sufficient collision probability to make this practically exploitable by brute-forcing local hashes until a match is found for a target ID.
Beyond the hashing flaw, the server processes MQTT string identifiers without sanitizing null bytes. If internal string handling logic truncates the input at the first null byte, an attacker can append arbitrary characters to a legitimate Client ID. This bypasses length restrictions while still mapping to the victim's internal session representation.
Furthermore, clustered deployments suffer from state desynchronization due to improper struct comparisons. The server relies on reflect.DeepEqual to enforce idempotency during stream creation. The StreamSource struct contains an internal iname field mutated exclusively by the server, causing mathematically identical user requests to be rejected as mismatched configurations.
The primary vulnerability resides in the session retrieval logic where the server implicitly trusts the hash index. The vulnerable implementation retrieves the session object based solely on the integer hash value. The code returns the session immediately without verifying the underlying string identifiers.
The patch introduced in commit 43e13a40a67a43880d14293791799fc5b0465bb5 corrects this by adding explicit string comparison. After fetching the session via the hash index, the server now performs a strict equality check. If the identifiers differ, the server rejects the connection and returns an authentication failure.
// Conceptual logic based on NATS-Server MQTT implementation
// Vulnerable Logic
sessionHash := getHash(requestedClientID)
if session, exists := server.sessions[sessionHash]; exists {
// Implicit trust of the hash index
return session
}
// Patched Logic
sessionHash := getHash(requestedClientID)
if session, exists := server.sessions[sessionHash]; exists {
// Explicit identifier verification added
if session.ClientID != requestedClientID {
return nil, ErrSessionMismatch
}
return session
}A parallel patch addressed the null-byte truncation vulnerability in commit adfb16280e2a842ffe102b398170552b9112b919. The developers added explicit boundary checks across all MQTT string parsing functions. The parser now iterates through the byte array and raises a protocol error if a \0 character is encountered within the Client ID, username, or topic strings.
The clustered stream state desynchronization also required a structural fix. The patch in commit ad80e455d8624ba01cfa69a05c7090e448ccfab3 modified the clustering layer. Before evaluating reflect.DeepEqual, the server now explicitly synchronizes the iname field from the existing state to the proposed state. This guarantees that internal metadata does not cause false negatives during configuration equivalence checks.
An attacker requires network access to the target NATS-Server MQTT interface, which defaults to port 1883. The attacker also needs prior knowledge of a victim's Client ID. Once the target ID is known, the attacker computes the NATS-specific hash for that ID offline.
The attacker generates millions of random Client IDs locally, hashing each until a collision with the target hash is found. The NATS test suite demonstrates this exact scenario using known colliding IDs, such as cid-03579431 and cid-09191235. The attacker connects to the server using the collided ID and sets the MQTT cleanSession flag to false.
The server processes the connection request, hashes the attacker's ID, and inadvertently retrieves the victim's persistent session. The server binds the attacker's network connection to the victim's session state. Any pending messages or future messages published to the victim's subscribed topics are actively routed to the attacker.
The primary impact of this vulnerability is a severe breach of message confidentiality. An attacker successfully exploiting the hash collision or null-byte truncation vectors gains full read access to the victim's subscribed message streams. Depending on the deployment context, this exposes sensitive telemetry, command-and-control directives, or private user data.
Integrity is indirectly affected if the attacker leverages the hijacked session to publish messages under the victim's identity. While the official CVSS vector scores integrity as None, application-level spoofing remains a practical consequence in systems lacking external message-level cryptographic signatures. The server explicitly trusts the connection as belonging to the victim.
Availability is compromised due to session displacement mechanics. MQTT protocol rules dictate that a new connection using an existing Client ID session forces the server to disconnect the older connection. The legitimate client experiences a persistent denial-of-service condition and is repeatedly disconnected as long as the attacker maintains the colliding session.
System administrators must upgrade NATS-Server deployments to versions 2.11.15 or 2.12.5. These releases contain the necessary string verification checks and strict input parsing logic required to prevent identifier manipulation. Environments running the 2.12 release candidate series must upgrade to 2.12.6-RC.1.
If immediate patching is unfeasible, administrators should restrict network access to the MQTT listener port. Implementing strict firewall rules or utilizing mutual TLS ensures that only trusted clients can initiate connections. This mitigates the risk of external exploitation by unauthorized external actors.
Organizations should implement strict Client ID naming policies and leverage NATS Authorization Callouts. By validating the Client ID against an external identity provider during the connection phase, administrators enforce a strict one-to-one mapping between authenticated users and their authorized MQTT session identifiers.
CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:N/A:L| Product | Affected Versions | Fixed Version |
|---|---|---|
nats-server nats-io | < 2.11.15 | 2.11.15 |
nats-server nats-io | 2.12.0-RC.1 to < 2.12.5 | 2.12.5 |
| Attribute | Detail |
|---|---|
| CWE ID | CWE-287, CWE-488 |
| Attack Vector | Network |
| CVSS Score | 6.5 |
| Exploit Status | Proof-of-Concept |
| KEV Status | Not Listed |
| Impact | Session Hijacking, Message Interception |
The product does not adequately verify the identity of the user attempting to access a specific session or resource.
NATS Server prior to versions 2.12.8 and 2.14.3 contains an incorrect authorization vulnerability (CWE-863) in its message tracing subsystem. When evaluating whether a connection is permitted to publish trace events to a destination subject specified in the Nats-Trace-Dest header, the server only checks standard client permissions and omits permission checks for leaf node connections. This allows a connected leaf node operator with restricted publishing privileges to emit internal trace events to unauthorized subjects and suppress standard message delivery using the Nats-Trace-Only header.
CVE-2026-63341 is a high-severity Denial of Service (DoS) vulnerability in the Aedes MQTT broker for Node.js affecting all versions prior to 1.1.1. The flaw stems from missing input validation on the hierarchical depth of incoming MQTT topic strings before they are passed to the underlying topic-matching engine, qlobber. Because qlobber enforces a hardcoded limit of 100 topic levels and throws a synchronous exception when this threshold is exceeded, an attacker can send a single MQTT packet containing 101 or more forward-slash-separated levels to trigger an uncaught exception that immediately terminates the Node.js broker process.
CVE-2026-61725 is a path traversal vulnerability (CWE-22) in the sevenz-rust2 Cargo package prior to version 0.21.1. The vulnerability occurs because the decompression utility fails to validate or sanitize archive entry filenames before joining them with the destination directory path via std::path::Path::join. An attacker who supplies a crafted 7z archive containing parent directory traversal sequences or absolute paths can write or overwrite arbitrary files on the host filesystem with the privileges of the extracting process.
CVE-2026-77309 (GHSA-jrjx-9jjw-747m) is a high-severity unauthenticated remote code execution vulnerability affecting NASA-AMMOS AIT-GUI versions 1.0.0 through 2.5.0. The flaw results from chaining an incomplete file cleanup error in the telemetry query endpoint (/tlm/query) with a directory traversal flaw in the script execution endpoint (/script/run). An attacker on an adjacent network can stage arbitrary Python statements into a static file on disk and execute that file under the privileges of the AIT-GUI web server process.
A vulnerability classified under CWE-116 (Improper Encoding or Escaping of Output) exists in memtomem-stm versions 0.1.0 through 0.1.33. The software acts as a Model Context Protocol (MCP) short-term memory proxy gateway for AI agent architectures. When surfacing retrieved memories and scratchpad items into downstream Large Language Model (LLM) context envelopes, the SurfacingFormatter component fails to properly sanitize untrusted memory attributes. An attacker with the ability to plant untrusted content into the agent's long-term or working memory store can inject arbitrary structural delimiters, close the <surfaced-memories> XML boundary prematurely, visually obscure instructions using Unicode bidirectional overrides, and execute stored prompt injection attacks against downstream LLM agents.
CVE-2026-77331 (GHSA-72jh-722p-rqr3) is a concurrency and session-state synchronization vulnerability in memtomem-stm, a short-term memory proxy gateway for AI agents. In versions 0.1.2 prior to 0.1.34, concurrent Model Context Protocol (MCP) Remote Procedure Call (RPC) failures or mid-flight task cancellations can initiate duplicate reconnect loops and permit dirty or cancelled transport sessions to be reused. This deficiency results in session-state integrity loss and local service degradation.