MQTT Protocol Packet Injection via Unchecked CONNACK Remaining Length
curl's MQTT client reads a CONNACK packet but only validates and consumes the first two bytes, leaving any extra bytes in the receive buffer. A malicious MQTT server can place additional bytes after the CONNACK so that curl reinterprets them as a separate MQTT message, such as a PUBLISH.
- Disclosed after 6 days
I'm not sure if this is a vulnerability or intended behavior, but I noticed that curl MQTT implementation accepts CONNACK packets with Remaining Length values greater than 2, which appears to violate the MQTT v3.1.1 specification.
According to the MQTT spec, CONNACK packets should have a Remaining Length of exactly 2 bytes, but curl seems to process packets with larger values and treats the extra bytes as new MQTT messages.
Affected version
» curl -V
curl 8.18.0 (x86_64-pc-linux-gnu) libcurl/8.18.0 OpenSSL/3.6.1 zlib/1.3.1 brotli/1.2.0 zstd/1.5.7 libidn2/2.3.8 libpsl/0.21.5 libssh2/1.11.1 nghttp2/1.68.0 ngtcp2/1.20.0 nghttp3/1.15.0 mit-krb5/1.21.3
Release-Date: 2026-01-07
Protocols: dict file ftp ftps gopher gophers http https imap imaps ipfs ipns mqtt pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp ws wss
Features: alt-svc AsynchDNS brotli GSS-API HSTS HTTP2 HTTP3 HTTPS-proxy IDN IPv6 Kerberos Largefile libz NTLM PSL SPNEGO SSL threadsafe TLS-SRP UnixSockets zstd
Steps To Reproduce:
- So in mqtt_verify_connack its reads the entire CONNACK packet,but only validates and consumes the first 2 bytes of the payload.
static CURLcode mqtt_verify_connack(struct Curl_easy *data)
{
...
result = mqtt_recv_atleast(data, MQTT_CONNACK_LEN);
if(result)
goto fail;
...
if(ptr[0] != 0x00 || ptr[1] != 0x00) { // only checks first 2 bytes:
...
}
mqtt_recv_consume(data, MQTT_CONNACK_LEN);
...
}
- And in mqtt_doing its reads from the buffer for the next MQTT message, but the leftover bytes are still in the buffer.
case MQTT_CONNACK:
result = mqtt_verify_connack(data);
...
mqtt->nextstate = MQTT_FIRST;
- I made a simple python poc script that will mimic MQTT, run this and try with curl to the server and its works to do inject a PUBLISH command.

So bytes embedded inside CONNACK are reinterpreted as a separate MQTT message, and from this attacker can inject arbitrary MQTT messages.
Supporting Material/References:
I attached the poc.py script and screenshoot bellow.
Impact
An attacker could potentially inject other control packets.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the CONNACK handler consumes only the fixed two-byte payload without accounting for the packet's declared Remaining Length, so surplus bytes remain in the buffer and are parsed as the next message.
Impact
An attacker controlling the MQTT server could inject other control packets into the client's message stream, though the report only demonstrates a PUBLISH and does not describe concrete harm.
What the attacker needed
Attacker controls the MQTT server; victim's curl connects to that server
The fix
The report suggests validating the Remaining Length and consuming the whole packet, or rejecting packets not exactly two bytes.
How it was found
- Run the supplied Python script that mimics an MQTT server and sends a CONNACK with extra bytes.
- Point curl at that server using its MQTT support.
- Observe that curl treats the leftover bytes as a separate MQTT message, injecting a PUBLISH command.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
MQTT is a messaging protocol where a client connects to a server and the server replies with a small acknowledgement packet called CONNACK. curl only checked the first two bytes of that reply and left anything extra sitting in its buffer, so the extra bytes were later read as if they were a brand new message from the server. A malicious server can use this to make curl process messages the client never expected.
What is Misconfiguration?
Settings left unsafe: exposed panels, open storage buckets, debug modes, default credentials.