Nerdbank.MessagePack DateTime Decoding Stack Overflow Vulnerability
A malicious MessagePack payload can trigger a StackOverflowException in Nerdbank.MessagePack due to an uncontrolled stack allocation when decoding DateTime values with oversized timestamp extension lengths, leading to process termination.
Nerdbank.MessagePack versions prior to 1.1.62 are vulnerable to an uncontrolled stack allocation vulnerability. This flaw allows an attacker to craft a malicious MessagePack payload that declares an oversized timestamp extension length. When the application attempts to deserialize this payload and encounters a DateTime value, the reader allocates an attacker-controlled number of bytes on the stack. This excessive allocation results in a StackOverflowException, causing the application to terminate. This vulnerability impacts applications that deserialize MessagePack data from untrusted sources and can lead to denial-of-service conditions. Defenders should prioritize patching or implementing workarounds to mitigate this risk.
Attack Chain
- Attacker crafts a malicious MessagePack payload with an invalid timestamp extension length (not 4, 8, or 12 bytes).
- The target application receives the malicious MessagePack payload from an untrusted source.
- The application attempts to deserialize the MessagePack data using Nerdbank.MessagePack.
- During deserialization, the
DateTimedecoder encounters the malicious timestamp extension. - The decoder derives
tokenSizefrom the attacker-controlled extension length before validating its size. - The unvalidated size is used in a
stackallocon the streaming reader’s slow path, allocating an excessive amount of stack memory. - The excessive stack allocation triggers a
StackOverflowException. - The
StackOverflowExceptionterminates the application process, resulting in a denial of service.
Impact
Successful exploitation of this vulnerability leads to a denial-of-service condition due to process termination. The vulnerability affects applications deserializing MessagePack data from untrusted sources, particularly those handling long-running processes such as services, APIs, workers, or message consumers. Even small malicious payloads can trigger the vulnerability due to the attacker-controlled extension length. This could potentially disrupt critical business functions relying on affected applications.
Recommendation
- Upgrade to Nerdbank.MessagePack version 1.1.62 or later to remediate the vulnerability.
- Implement pre-validation of MessagePack extension headers, rejecting timestamp extensions with lengths other than 4, 8, or 12 bytes, as suggested in the advisory [GHSA-2cwq-pwfr-wcw3].
- Deploy the Sigma rule “Nerdbank MessagePack Suspicious Stack Allocation” to detect potential exploitation attempts in your environment.
- If immediate patching is not feasible, consider running deserialization of untrusted payloads in isolated processes that can be safely restarted, as described in [GHSA-2cwq-pwfr-wcw3].
Detection coverage 2
Nerdbank MessagePack Suspicious Stack Allocation
highDetects potential attempts to exploit the Nerdbank.MessagePack stack overflow vulnerability by identifying processes deserializing MessagePack data with unusually large extension sizes.
Nerdbank MessagePack Suspicious DateTime Deserialization
mediumDetects potential attempts to trigger the Nerdbank.MessagePack stack overflow during DateTime deserialization from untrusted sources.
Detection queries are kept inside the platform. Get full rules →