mqtt: reject control bytes in the topic#22112
Closed
alhudz wants to merge 1 commit into
Closed
Conversation
bagder
approved these changes
Jun 22, 2026
There was a problem hiding this comment.
Pull request overview
This PR hardens curl’s MQTT URL parsing by rejecting percent-decoded control bytes in the topic path component, preventing invalid MQTT topic names (notably embedded NUL) from being serialized into SUBSCRIBE/PUBLISH packets and causing broker protocol errors.
Changes:
- Decode MQTT topics using
REJECT_CTRLinstead ofREJECT_NADAto reject decoded control bytes (< 0x20). - Add a new regression test (
test2109) that reproducesmqtt://host/aa%00bband asserts failure before SUBSCRIBE is sent. - Register the new test in the test suite makefile.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| lib/mqtt.c | Switch topic URL-decoding to REJECT_CTRL so decoded control bytes are rejected. |
| tests/data/test2109 | New MQTT test that ensures an embedded decoded NUL in the topic is rejected (CURLE_URL_MALFORMAT) before SUBSCRIBE. |
| tests/data/Makefile.am | Adds test2109 to the TESTCASES list so it runs in CI. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Member
|
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Repro:
mqtt://host/aa%00bb(any percent-encoded control byte in the topic, including anul).Cause:
mqtt_get_topicURL-decodes the topic withREJECT_NADA, so the byte is copied verbatim into the length-prefixedSUBSCRIBE/PUBLISHpacket and goes out on the wire (observed820a00010005616100626200, topicaa\0bb). Anulin a topic name is forbidden by MQTT 3.1.1[MQTT-1.5.4-2], so a conformant broker treats it as a protocol error.Fix: decode with
REJECT_CTRL, matching every other URL scheme that turns a path component into a command argument (ftp,imap,pop3,smtp,smb,dictall use it).test2109covers it.