-
Notifications
You must be signed in to change notification settings - Fork 167
Missing MQTT v5 property protocol validation and decoding buffer safety checks #443
Description
This issue addresses critical omissions in MQTT v5 protocol compliance and buffer safety within the property encoding and decoding logic in wolfMQTT:
- Missing Protocol Validation: The implementation lacked the mandatory check to ensure that a given property is only used within the specific MQTT v5 packet types allowed by its definition (as outlined in the
gPropMatrix).
- Impact: This allowed protocol violations where properties could be sent or received in unauthorized packet types, leading to non-compliant MQTT v5 communication. This resolves an explicit TODO in the code.
- Buffer Safety Hazard: The property decoding logic in
MqttDecode_Propslacked explicit boundary checks before decoding the property identifier (VBI) and before decoding property string data.
- Impact: If a received packet's length field was malformed or maliciously manipulated, the lack of checks could lead to buffer overruns or reading beyond allocated memory during the decoding process.
Area: Protocol, MQTT v5, Property Decoding, Safety
The bugs are protocol compliance and safety logic errors verifiable via static code analysis.
Write:
Protocol Validation: Examine
MqttEncode_PropsandMqttDecode_Propsand confirm the original logic did not validate whether a property'spacket_type_maskallows its use in the current packet type (e.g., trying to send a Session Expiry Interval in a PUBLISH packet). The fix introduces this check and uses the newMQTT_CODE_ERROR_PROPERTY_MISMATCHerror code.Buffer Safety: Analyze
MqttDecode_Propsto confirm the lack of boundary checks against the total packet length before attempting to read variable-byte integers (VBIs) and property string data. This vulnerability requires a malformed packet to exploit.
Additional Context
Fix Proposal is presented in the following PR: #440