The vulnerability exists because the jsonpath library uses an embedded, unsandboxed version of static-eval to evaluate script expressions within JSONPath queries. An attacker can craft a malicious path containing arbitrary JavaScript. When methods like query, nodes, or value process this path, the script expression is parsed into an Abstract Syntax Tree (AST) and passed to static-eval's walk function for evaluation, leading to code execution. This can result in Remote Code Execution (RCE) in a Node.js environment or Cross-Site Scripting (XSS) in a browser.
The patch, introduced in version 1.2.1, mitigates this in two main ways. First, it adds assertion functions (_assert_safe_key, _assert_safe_components) within the jsonpath library itself to validate path components before they are processed. These checks are called from the main public API functions. Second, it hardens the embedded static-eval module by preventing access to sensitive properties like __proto__, prototype, and constructor, which are common vectors for prototype pollution and gadget chain exploitation. The identified vulnerable functions are the public entry points that accept the malicious path and the internal walk function where the code execution is ultimately triggered.