VDB
KO
MEDIUM

GHSA-4qm4-8hg2-g2xm

MessagePack allows untrusted data to lead to DoS attack due to hash collisions and stack overflow

Details

### Impact

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](https://github.com/MessagePack-CSharp/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf), which provided an inadequate fix for the hash collision part of the vulnerability.

### Patches

The following steps are required to mitigate this risk.

1. Upgrade to a version of the library where a fix is available. If upgrading from v1, check out [our migration guide](https://github.com/MessagePack-CSharp/MessagePack-CSharp/blob/master/doc/migration.md). 1. Review the steps in [this previous advisory](https://github.com/MessagePack-CSharp/MessagePack-CSharp/security/advisories/GHSA-7q36-4xx7-xcxf) to ensure you have your application configured for untrusted data.

### Workarounds

If upgrading MessagePack to a patched version is not an option for you, you may apply a manual workaround as follows:

1. Declare a class that derives from `MessagePackSecurity`. 2. Override the `GetHashCollisionResistantEqualityComparer<T>` method to provide a collision-resistant hash function of your own and avoid calling `base.GetHashCollisionResistantEqualityComparer<T>()`. 3. Configure a `MessagePackSerializerOptions` with an instance of your derived type by calling `WithSecurity` on an existing options object. 4. Use your custom options object for all deserialization operations. This may be by setting the `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.

### References

- Learn more about best security practices when reading untrusted data with [MessagePack 1.x](https://github.com/MessagePack-CSharp/MessagePack-CSharp/tree/v1.x#security) or [MessagePack 2.x](https://github.com/MessagePack-CSharp/MessagePack-CSharp#security). - The .NET team's [discussion on hash collision vulnerabilities of their `HashCode` struct](https://github.com/GrabYourPitchforks/runtime/blob/threat_models/docs/design/security/System.HashCode.md) (or in [the pull request that merges this into the dotnet org](https://github.com/dotnet/runtime/pull/108864)).

### For more information

If you have any questions or comments about this advisory:

* [Start a public discussion](https://github.com/MessagePack-CSharp/MessagePack-CSharp/discussions) * [Email us privately](mailto:andrewarnott@live.com)

Are you affected?

Enter the version of the package you're using.

Affected packages

NuGet / MessagePack
Introduced in: 0 Fixed in: 2.5.187
Fix dotnet add package MessagePack --version 2.5.187
NuGet / MessagePack
Introduced in: 2.6.95-alpha Fixed in: 3.0.214-rc.1
Fix dotnet add package MessagePack --version 3.0.214-rc.1

References