GHSA-qhrr-8q5h-9q3h: Medium severity nuget/MessagePack vulnerability
Impact
MessagePack-CSharp is vulnerable to denial of service through excessive memory allocation when deserializing attacker-controlled data into System.Object.
When PrimitiveObjectFormatter encounters an array, it allocates an object[] using the declared array length before enforcing the configured maximum object-graph depth. A specially crafted payload containing deeply nested arrays can therefore keep many large arrays live simultaneously before deserialization is rejected for exceeding the depth limit.
Because the array-header validation uses the total unread byte count as evidence that the declared elements may be present, nested array headers can reuse the same trailing bytes for this validation. This permits a relatively small payload to cause disproportionately large managed-heap allocations. The reported example uses an approximately 31.5 KiB payload to allocate roughly 114.7 MiB of reference storage on x64—an amplification factor of approximately 3,800—before the depth exception is raised. Repeated requests may cause severe memory pressure, excessive garbage collection, process termination, or loss of service availability.
Applications are affected when they:
- Deserialize untrusted MessagePack data as object, or otherwise use a resolver path that selects PrimitiveObjectFormatter; and - Permit an attacker to submit such data repeatedly.
ASP.NET Core SignalR is one known way to expose the vulnerability remotely: an application that enables AddMessagePackProtocol() and has a reachable hub method with an object parameter may pass attacker-controlled arguments to the vulnerable MessagePack-CSharp formatter. However, the underlying vulnerability is in MessagePack-CSharp, not SignalR, and other applications that deserialize untrusted data through the same formatter may also be affected.
MessagePack-CSharp 2.5.302 is confirmed to contain the vulnerable code. Other releases containing the same allocate-before-depth-check behavior may also be affected. Authentication requirements depend on the application exposing the deserialization endpoint: exploitation requires no privileges for a publicly reachable endpoint, while protected endpoints retain their configured authorization requirements.
Workarounds
Where possible, avoid deserializing untrusted data into System.Object, including object-typed members of otherwise strongly typed models. Use concrete, narrowly defined DTO types instead.
For ASP.NET Core SignalR applications, any of the following can prevent or reduce exposure:
- Replace object parameters in reachable hub methods with concrete types. - Disable the MessagePack hub protocol and use another protocol until a patched MessagePack-CSharp release is available. - Restrict affected hub methods to trusted and authenticated callers. - Apply rate limits and connection limits to reduce the ability to repeat malicious requests.
Reducing the maximum deserialization depth or transport message size may reduce the worst-case allocation, but should be treated only as defense in depth. It does not correct the allocate-before-depth-check behavior and is not a complete remediation.
Applications with advanced resolver configurations may use a custom formatter for object that enforces the depth limit before allocating arrays. Such a formatter should be carefully reviewed and tested against untrusted input.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Upgrade
Upgrade
nuget/MessagePackto a version that resolves this vulnerability.Fixed in 3.1.9 - Upgrade
Upgrade
nuget/MessagePackto a version that resolves this vulnerability.Fixed in 2.5.303 - Configuration
Avoid deserializing untrusted MessagePack data into System.Object, including object-typed model members; replace object parameters in reachable hub methods with concrete, narrowly defined DTO types.
MessagePack-CSharp / ASP.NET Core SignalR deserialization target types = concrete DTO types instead of System.Object - Configuration
Disable AddMessagePackProtocol() and use another protocol until a patched MessagePack-CSharp release is available.
ASP.NET Core SignalR MessagePack hub protocol = disabled - Configuration
Reduce the maximum deserialization depth or transport message size as defense in depth to limit worst-case allocation; this is not a complete remediation.
MessagePack-CSharp maximum deserialization depth and transport message size = reduced - Configuration
Where advanced resolver configuration is used, configure a custom formatter for object that enforces the depth limit before allocating arrays, and carefully review and test it against untrusted input.
MessagePack-CSharp custom object formatter = enforce the depth limit before allocating arrays - Compensating control
Apply rate limits and connection limits to reduce repeated malicious requests and the resulting memory pressure.
- Compensating control
Restrict affected SignalR hub methods to trusted and authenticated callers.
Event History
Frequently Asked Questions
Which application flows are exposed to this issue?
Applications are affected when they deserialize attacker-controlled MessagePack data into System.Object using PrimitiveObjectFormatter. The risk is greatest for endpoints or services that accept MessagePack input from untrusted sources.
What does an attacker need to exploit it?
An attacker needs to submit a specially crafted MessagePack payload containing deeply nested arrays to a reachable deserialization path. No authentication or user interaction is indicated by the supplied vector.
What is the likely operational impact of repeated exploitation?
Repeated malicious requests can create severe managed-heap pressure and excessive garbage collection, potentially terminating the process or making the service unavailable. The reported example used about 31.5 KiB of input to allocate roughly 114.7 MiB of reference storage on x64 before rejection.