Summary
Untrusted data can lead to DoS attack due to hash collisions and stack overflow in MessagePack
MessagePack 1.x users
Upgrade to any 1.9.x version.
When deserializing untrusted data, put MessagePack into a more secure mode with:
MessagePackSecurity.Active = MessagePackSecurity.UntrustedData;In MessagePack v1.x this is a static property and thus the security level is shared by the entire process or AppDomain.
Use MessagePack v2.1 or later for better control over the security level for your particular use.Any code produced by mpc should be regenerated with the mpc tool with the matching (patched) version. Such generated code usually is written to a file called
Generated.cs. A patchedGenerated.csfile will typically reference theMessagePackSecurityclass.Review any custom-written
IMessagePackFormatter<T>implementations in your project or that you might use from 3rd party packages to ensure they also utilize theMessagePackSecurityclass as required.
In particular, a formatter that deserializes an object (as opposed to a primitive value) should wrap the deserialization in ausing (MessagePackSecurity.DepthStep())block. For example:public MyObject Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return default; } else { using (MessagePackSecurity.DepthStep()) // STACK OVERFLOW MITIGATION { MyObject o = new MyObject(); // deserialize members of the object here. return o; } } }If your custom formatter creates hash-based collections (e.g.
Dictionary<K, V>orHashSet<T>) where the hashed key comes from the messagepack data, always instantiate your collection usingMessagePackSecurity.Active.GetEqualityComparer<T>()as the equality comparer:var collection = new HashSet<T>(MessagePackSecurity.Active.GetEqualityComparer<T>());This ensures that when reading untrusted data, you will be using a collision-resistent hash algorithm.
Learn more about best security practices when reading untrusted data with MessagePack 1.x.
MessagePack 2.x users
Upgrade to any 2.1.x or later version.
When deserializing untrusted data, put MessagePack into a more secure mode by configuring your
MessagePackSerializerOptions.Securityproperty:var options = MessagePackSerializerOptions.Standard .WithSecurity(MessagePackSecurity.UntrustedData); // Pass the options explicitly for the greatest control. T object = MessagePackSerializer.Deserialize<T>(data, options); // Or set the security level as the default. MessagePackSerializer.DefaultOptions = options;Any code produced by mpc should be regenerated with the mpc tool with the matching (patched) version. Such generated code usually is written to a file called
Generated.cs. A patchedGenerated.csfile will typically reference theSecuritymember on theMessagePackSerializerOptionsparameter.Review any custom-written
IMessagePackFormatter<T>implementations in your project or that you might use from 3rd party packages to ensure they also utilize theMessagePackSecurityclass as required.
In particular, a formatter that deserializes an object (as opposed to a primitive value) should calloptions.Security.DepthStep(ref reader);before deserializing the object's members, and be sure to revert the depth step withreader.Depth--;before exiting the method. For example:public MyObject Deserialize(ref MessagePackReader reader, MessagePackSerializerOptions options) { if (reader.TryReadNil()) { return default; } else { options.Security.DepthStep(ref reader); // STACK OVERFLOW MITIGATION, line 1 try { MyObject o = new MyObject(); // deserialize members of the object here. return o; } finally { reader.Depth--; // STACK OVERFLOW MITIGATION, line 2 } } }If your custom formatter creates hash-based collections (e.g.
Dictionary<K, V>orHashSet<T>) where the hashed key comes from the messagepack data, always instantiate your collection usingoptions.Security.GetEqualityComparer<TKey>()as the equality comparer:var collection = new HashSet<T>(options.Security.GetEqualityComparer<T>());This ensures that when reading untrusted data, you will be using a collision-resistent hash algorithm.
Learn more about best security practices when reading untrusted data with MessagePack 2.x.
Workarounds
The security vulnerabilities are in the formatters.
Avoiding the built-in formatters entirely in favor of reading messagepack primitive data directly
or relying on carefully written custom formatters can provide a workaround.
MessagePack v1.x users may utilize the MessagePackBinary static class directly to read the data they expect.
MessagePack v2.x users may utilize the MessagePackReader struct directly to read the data they expect.
References
Learn more about best security practices when reading untrusted data with MessagePack 1.x or MessagePack 2.x.
For more information
If you have any questions or comments about this advisory:
- Open an issue in MessagePack-CSharp
- Email us
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 either of two vectors:
- hash collisions - leading to large CPU consumption disproportionate to the size of the data being deserialized.
- stack overflow - leading to the deserializing process crashing.
CVE-2020-5234 has a CVSS score of 4.8 (Medium). The vector is network-reachable, low privileges required, and user interaction required. A CVSS score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether this affects your application depends on whether the vulnerable code is present and reachable in your environment. A fixed version is available (1.9.11, 2.1.90); upgrading removes the vulnerable code path.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
The following steps are required to mitigate this risk.
- Upgrade to a version of the library where a fix is available
- Add code to your application to put MessagePack into the defensive
UntrustedDatamode. - Identify all MessagePack extensions that implement
IMessagePackFormatter<T>implementations that do not ship with the MessagePack library to include the security mitigations. This includes those acquired from 3rd party packages and classes included directly into your project. Any AOT formatters generated with the MPC tool must be regenerated with the patched version of mpc. - Review your messagepack-serializable data structures for hash-based collections that use custom or unusual types for the hashed key. See below for details on handling such situations.
Review the MessagePackSecurity class to tweak any settings as necessary to strike the right balance between performance, functionality, and security.
Specialized IEqualityComparer<T> implementations provide the hash collision resistance.
Each type of hashed key may require a specialized implementation of its own.
The patched MessagePack library includes many such implementations for primitive types commonly used as keys in hash-based collections.
If your data structures use custom types as keys in these hash-based collections,
putting MessagePack in UntrustedData mode may lead the deserializer to throw an exception
because no safe IEqualityComparer<T> is available for your custom T type.
You can provide your own safe implementation by deriving from the MessagePackSecurity class
and overriding the GetHashCollisionResistantEqualityComparer<T>() method to return your own
custom implementation when T matches your type, and fallback to return base.GetHashCollisionResistantEqualityComparer<T>(); for types you do not have custom implementations for.
Unrelated to this advisory, but as general security guidance, you should also avoid the Typeless serializer/formatters/resolvers for untrusted data as that opens the door for the untrusted data to potentially deserialize unanticipated types that can compromise security.
Frequently Asked Questions
- What is CVE-2020-5234? CVE-2020-5234 is a medium-severity security vulnerability in MessagePack (nuget), affecting versions < 1.9.11. It is fixed in 1.9.11, 2.1.90.
- How severe is CVE-2020-5234? CVE-2020-5234 has a CVSS score of 4.8 (Medium). This score reflects the worst-case severity of the vulnerability, not your specific exposure. Whether it represents real risk in your environment depends on whether the vulnerable code is present and reachable.
- Which packages are affected by CVE-2020-5234?
MessagePack(nuget) (versions < 1.9.11)MessagePack.ImmutableCollection(nuget) (versions < 1.9.11)MessagePack.ReactiveProperty(nuget) (versions < 1.9.11)MessagePack.UnityShims(nuget) (versions < 1.9.11)MessagePack.Unity(nuget) (versions < 1.9.11)
- Is there a fix for CVE-2020-5234? Yes. CVE-2020-5234 is fixed in 1.9.11, 2.1.90. Upgrade to this version or later.
- Is CVE-2020-5234 exploitable, and should I be worried? Whether CVE-2020-5234 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2020-5234 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2020-5234?
- Upgrade
MessagePackto 1.9.11 or later - Upgrade
MessagePackto 2.1.90 or later - Upgrade
MessagePack.ImmutableCollectionto 1.9.11 or later - Upgrade
MessagePack.ImmutableCollectionto 2.1.90 or later - Upgrade
MessagePack.ReactivePropertyto 1.9.11 or later - Upgrade
MessagePack.ReactivePropertyto 2.1.90 or later - Upgrade
MessagePack.UnityShimsto 1.9.11 or later - Upgrade
MessagePack.UnityShimsto 2.1.90 or later - Upgrade
MessagePack.Unityto 1.9.11 or later - Upgrade
MessagePack.Unityto 2.1.90 or later
- Upgrade