The analysis of the patch 0aee2f61866e35ffa0aef915221cdf6b026ffdd4 reveals two primary vulnerabilities that allow arbitrary JavaScript execution through the mathjs expression parser.
First, the get function in src/utils/array.js, which is used by matrix types like DenseMatrix and SparseMatrix, failed to validate that its index argument was an array. The patch rectifies this by adding an Array.isArray(index) check. Before the fix, an attacker could provide a specially crafted object as the index. When the function attempted to iterate over this object, it could trigger malicious methods (like reduce in the exploit PoC), leading to code execution. The vulnerable functions in a runtime profile would be DenseMatrix.get or SparseMatrix.get calling the underlying vulnerable get.
Second, the property access control functions in src/utils/customs.js were too permissive for arrays. The original isSafeProperty function allowed any property to be set on an array. This was exploited by overwriting the map property of an array instance within the expression. When this array was later used, the attacker-controlled map function would be executed. The patch replaces isSafeProperty with more granular checks, isSafeObjectProperty and isSafeArrayProperty, where the latter only permits numeric indices and the length property to be accessed or modified on arrays. The vulnerable functions in this scenario are setSafeProperty and getSafeProperty, which are called internally by the expression parser during assignment and member access operations.