msgpack / msgpack-cli

MessagePack implementation for Common Language Infrastructure / msgpack.org[C#]
http://msgpack.org
Apache License 2.0
835 stars 175 forks source link

Is this Library save to accept untrusted data? #274

Closed CCludts closed 6 years ago

CCludts commented 6 years ago

Hi,

I'd like use this library to accept messages from untrusted (Unity) clients. The clients might try and tinker with the binaries to (DDOS) attack our servers. (Server also in Unity).

Is there no way a attacker could send a message that:

take unproportial cpu to decode take unproportial memory to decode instantiate a random C# class / call unwanted methods.

yfakariya commented 6 years ago

First, I am very happy to start discuss about security with community!

Here is my answer for your question:

Any idea?

CCludts commented 6 years ago

Resource quotas sound look a good idea (might want to include quotas for strings also, unless you dont pre-allocate). I have very little knowledge on the topic, so I cant be of much assistance with that.

As for the runtime de-serialization, this paper on JSON-deserializer vulnerabilities was eye-opening to me. Maybe it can be of help should you decide to implement more safeguards. https://www.blackhat.com/docs/us-17/thursday/us-17-Munoz-Friday-The-13th-JSON-Attacks-wp.pdf

yfakariya commented 6 years ago

@PencilBow Thank you! I'm reading the paper.

CCludts commented 6 years ago

@yfakariya In case you're still interested, I found out that protobuf's CSharp implementation has some nice safeguards for avoiding arbitrary allocations. Hope it can be of help. https://github.com/google/protobuf/blob/master/csharp/src/Google.Protobuf/CodedInputStream.cs#L1139

yfakariya commented 6 years ago

@PencilBow Thank you!