When this library is used to deserialize messagepack data from an untrusted source, there is a risk of a denial of service attack by an attacker that sends data contrived to produce hash collisions, leading to large CPU consumption disproportionate to the size of the data being deserialized.
This is similar to a prior advisory, which provided an inadequate fix for the hash collision part of the vulnerability.
The following steps are required to mitigate this risk.
If upgrading MessagePack to a patched version is not an option for you, you may apply a manual workaround as follows:
MessagePackSecurity
.GetHashCollisionResistantEqualityComparer<T>
method to provide a collision-resistant hash function of your own and avoid calling base.GetHashCollisionResistantEqualityComparer<T>()
.MessagePackSerializerOptions
with an instance of your derived type by calling WithSecurity
on an existing options object.MessagePackSerializer.DefaultOptions
static property, if you call methods that rely on this default property, and/or by passing in the options object explicitly to any Deserialize
method.HashCode
struct.If you have any questions or comments about this advisory:
The product uses an algorithm that produces a digest (output value) that does not meet security expectations for a hash function that allows an adversary to reasonably determine the original input (preimage attack), find another input that can produce the same hash (2nd preimage attack), or find multiple inputs that evaluate to the same hash (birthday attack).
A hash function is defined as an algorithm that maps arbitrarily sized data into a fixed-sized digest (output) such that the following properties hold:
Building on this definition, a cryptographic hash function must also ensure that a malicious actor cannot leverage the hash function to have a reasonable chance of success at determining any of the following:
What is regarded as “reasonable” varies by context and threat model, but in general, “reasonable” could cover any attack that is more efficient than brute force (i.e., on average, attempting half of all possible combinations). Note that some attacks might be more efficient than brute force but are still not regarded as achievable in the real world. Any algorithm does not meet the above conditions will generally be considered weak for general use in hashing. In addition to algorithmic weaknesses, a hash function can be made weak by using the hash in a security context that breaks its security guarantees. For example, using a hash function without a salt for storing passwords (that are sufficiently short) could enable an adversary to create a “rainbow table” [REF-637] to recover the password under certain conditions; this attack works against such hash functions as MD5, SHA-1, and SHA-2.