The vulnerability is a code injection flaw in the math-codegen library. The core of the issue lies in the insecure construction of JavaScript code from a parsed math expression. The cg.parse() method and its underlying components generate code that is then executed via new Function(). The vulnerability arises because user-controlled input, particularly string literals and identifiers, was not properly sanitized before being embedded into the generated code.
The patch, identified in commit 4bb52d3030683362b3559ee8dd91350555a05f6b, addresses this by consistently applying JSON.stringify() to all external data being incorporated into the code string. This ensures that values are treated as data (e.g., a literal string) rather than as executable code.
The most critical point of injection was within lib/node/ConstantNode.js, where string literals were directly concatenated. This allowed an attacker to close the string, inject arbitrary commands, and achieve Remote Code Execution (RCE). The same commit also fixed similar, albeit less direct, injection vulnerabilities in other node handlers (AssignmentNode, FunctionNode, SymbolNode) where identifiers were not escaped, demonstrating a systemic issue of improper code generation. The analysis identifies all functions that were modified to safely handle input, as they were all part of the attack surface.