The vulnerability lies in the devalue library's parsing mechanism, specifically within the unflatten function, which is invoked by the exported parse function. The security flaw allows for a denial-of-service attack when devalue.parse is used on untrusted data. The patch is applied to the unflatten function in src/parse.js.
The vulnerability stems from two primary issues related to resource exhaustion from specially crafted inputs:
-
Invalid ArrayBuffer Value: The logic for deserializing an ArrayBuffer presumed its value would be a base64-encoded string but failed to validate this. An attacker could supply a non-string value (such as a large object), causing the decode64 function to consume excessive CPU and memory, resulting in a denial of service. The fix introduces a typeof base64 !== 'string' check to mitigate this.
-
Circular References: The patch also adds checks to prevent infinite recursion caused by circular references in the input data. This affects both TypedArrays and objects with custom revivers. For instance, a TypedArray could be crafted to reference itself as its own underlying buffer, leading to an infinite loop during the hydration process.
The main vulnerable function is unflatten, as it contains the flawed logic. The hydrate function, where the changes are implemented, is an inner function of unflatten, making unflatten the correct scope for identification. The parse function serves as the user-facing API and the entry point for the vulnerability, so it would also be present in any runtime profile of an exploit. Consequently, both parse and unflatten are the critical functions to monitor.