Summary
The jsonpath package unsafely evaluates user-supplied JSONPath expressions using a generic expression evaluator that is not meant for untrusted input.
An attacker who can influence JSONPath strings can execute arbitrary JavaScript code in Node.js (remote code execution) or in the browser (cross-site scripting), affecting all jsonpath methods that evaluate paths against objects.
Affected context
This vulnerability appears in applications that use the jsonpath library to evaluate JSONPath expressions that may be derived from, or influenced by, external input.
It is relevant in both:
- Server-side Node.js environments, where JSONPath is used for querying or transforming JSON structures (e.g., APIs, data processing pipelines, configuration handling).
- Client-side browser contexts, where JSONPath may be used in dashboards, admin consoles, or data viewers.
The issue is triggered whenever jsonpath's evaluation functions process an attacker-controlled or partially attacker-controlled JSONPath string.
Exploit preconditions
- Attack surface: Any API, function, or feature that:
- Accepts JSONPath expressions from users, clients, configuration files, logs, or external systems; and
- Passes those expressions to jsonpath's evaluation methods.
- Required access:
- Remote users who can submit JSONPath expressions (e.g., request parameters, body fields, query builders), or
- Indirect influence via stored configuration, templates, or data that is later used as a JSONPath.
- Trigger point:
- Calls to jsonpath methods such as
.query,.nodes,.paths,.value,.parent, or.applywith a crafted JSONPath expression. - Why exploitation is possible:
- jsonpath uses
static-evalor similar expression evaluation that compiles and evaluates JSONPath fragments as JavaScript. - These evaluators are not sandboxed and allow execution of arbitrary expressions when fed untrusted input, mapping directly to arbitrary code injection.
Why this happens
The core issue is that jsonpath treats JSONPath expressions as executable logic and evaluates them using an expression engine (static-eval) not designed for adversarial input.
Instead of treating JSONPath purely as a declarative query language with a constrained grammar, jsonpath permits expression fragments that are effectively JavaScript and are passed to a generic evaluator.
This pattern corresponds to CWE-94: Improper Control of Generation of Code ('Code Injection'), where attacker-controlled data is incorporated into code that is generated and executed at runtime without strict syntactic and semantic validation.
In abstract terms, the bug class is: "Interpreting untrusted input as code or script within a powerful evaluation context."
Potential impact
- Remote Code Execution (RCE) in Node.js processes that rely on jsonpath.
- Cross-site Scripting (XSS) in browser-based applications that evaluate untrusted JSONPath using jsonpath.
- Unauthorized access to sensitive data in memory by executing arbitrary JS with the application's privileges.
- Lateral movement within server environments by using RCE to pivot to other services or systems.
- Data manipulation or destruction within the application's process (e.g., tampering with application state, configuration, or in-memory caches).
- Service disruption or Denial of Service by executing resource-intensive or destructive payloads.
General mitigation guidance
Effective mitigation focuses on eliminating the interpretation of untrusted JSONPath as executable code and constraining expression capabilities.
General defensive patterns include:
- Avoid evaluating untrusted JSONPath:
- Do not accept raw JSONPath strings directly from users or external systems when possible.
- Expose only a constrained, pre-defined set of server-side queries that users can select from, instead of free-form JSONPath.
- Constrain the query language:
- Use JSONPath implementations that treat paths as data and do not provide embedded JavaScript or expression evaluation.
- If expression support is required, restrict to a well-defined subset that cannot access global objects or arbitrary functions.
- Apply robust input validation and normalization:
- Enforce strict syntax validation of JSONPath expressions against a whitelist of allowed tokens and operators before evaluation.
- Reject or sanitize expressions that include constructs beyond simple path navigation (e.g., dynamic function calls, arbitrary predicates).
- Reduce privileges of the execution environment:
- Run Node.js processes using least-privilege OS accounts and minimal capabilities.
- Limit access to sensitive environment variables, file system paths, and network resources to reduce impact of potential code execution.
- Architectural isolation:
- Consider isolating any required dynamic evaluation in a hardened, constrained microservice or worker with restricted permissions and clear resource bounds.
How teams detect issues like this
Detection involves static inspection of code paths that construct and evaluate JSONPath expressions, combined with runtime monitoring:
- Static analysis and code scanning:
- Search for imports of
jsonpathand calls to.query,.nodes,.paths,.value,.parent,.apply. - Flag any call sites where the JSONPath argument originates from user input (e.g., HTTP parameters, request bodies, query builders, or deserialized external configuration).
- Identify usage of generic JS evaluators (
static-eval,eval,Function, or similar) tied to JSONPath handling. - Code review signals:
- Application features that promise "user-defined JSON queries," "advanced JSONPath filters," or "scriptable data views."
- Patterns where JSONPath strings are concatenated or interpolated from input data.
- Lack of explicit validation or schema enforcement for JSONPath fields in APIs.
- Policy and CI enforcement:
- Add repository policies that disallow dangerous expression-evaluation libraries for user-supplied data.
- Integrate security linters or SAST tools that can flag untrusted data flowing into JSONPath parameters.
- Runtime monitoring:
- Instrument logging around JSONPath evaluation entry points to capture unexpected or complex expressions.
- Monitor for anomalous behavior like unexpected outbound network calls, file system access, or spikes in CPU usage originating from JSONPath-related code paths.

