Add validation that the remaining length is less than 2^28#901
Conversation
|
Thanks for this PR. But the equivalent PR in the Go Paho.mqtt library that inspired this, also fixed the decoding code for remaining length as well as the encoding code. As I understand it, @PierreF As I understand it, and the code base (possibly mistakenly, I admit) This PR misunderstands the issue and is even Security Theatre. Personally I'd close it to maintain high standards for the code, and avoid setting a bad precedent. The decoding code in Paho.mqtt that calculates |
|
Thank you for the thorough review. I'd like to clarify a few points. On the paho.mqtt.golang issue I think there may be a slight misunderstanding about the threat model in eclipse-paho/paho.mqtt.golang#737. That issue assumes an attacker who can control input to the client application but has no direct access to the MQTT broker. The concern is that if such an attacker feeds a sufficiently large value into the application, On the decoding side I noticed that the existing decode loop already handles this correctly — it returns On paho.mqtt.python specifically I agree that this is not a security fix, and I want to be clear on that point. As noted in the issue, the realistic security impact is extremely low. Unlike the golang case, it is not realistically possible to set a Remaining Length as large as 2³¹ or 2³² through this library's API. Theoretically, if a broker were to stop reading at the 4th byte regardless of the MSB and treat only those bytes as the length, the attack could succeed — but among the 23 brokers I surveyed, none exhibited such behavior. And even if such a broker existed, the truncation would occur on the broker side, which I think should reasonably be considered the broker's responsibility rather than the client's. Why I still submitted this PR Although the security impact appears minimal in practice, I noticed that depending on how an application using this library is implemented, there could be a code path that sends a spec-violating packet without the developer intending to do so. That felt worth addressing. I'm aware that my implementation may not meet the project's coding standards, and I'm very open to feedback or suggestions on how to improve it. If there's a cleaner approach you'd prefer, I'm happy to revise accordingly. |
|
@63n0 Thanks. LGTM then. The change does ensure we play nicely (in accordance with the spec) with brokers, both good and bad. Also it rules out a potential bug, closes the FIXME, and makes the codebase more robust. Also the code quality is fine. My reference about "quality" was intended towards avoiding adding PRs for the sake of it, with no real benefit. |
Fixed it to throw a ValueError if the remaining length is too large, and removed the FIXME comment.
Closes: #900