/

CVE-2026-12866

Severity:

CRITICAL RISK

(9.8)

Code Injection (CWE-94) via expr-eval toJSFunction API

CVE-2026-12866

Deferred

Vulnerability type

Category:

Code Injection

CWE:

CWE-94

Impact:

Arbitrary Code Execution

Severity:

CRITICAL RISK

(9.8)

CVSS version:

3.1

Catch this CVE while code is being written

Detect vulnerable code directly in pull requests, so CVEs are fixed before merge.

Summary

The expr-eval library allows crafted user expressions to be converted into executable JavaScript via the toJSFunction() API, enabling arbitrary code execution.

When applications pass untrusted expressions into this compilation path, attackers can escape the intended sandbox and run arbitrary code in the application's execution context.

Affected context

This vulnerability arises in applications that embed expr-eval for dynamic expression parsing and then use the toJSFunction() API on values influenced by users or external systems. It is most relevant where expression strings are treated as data but are transformed directly into JavaScript source and executed with new Function(), especially in server-side environments or privileged browser contexts. The risk increases when the generated functions have access to sensitive objects, application state, or elevated privileges.

Exploit preconditions

  • Attack surface: Any endpoint, API, or UI path where expressions are accepted and evaluated via expr-eval.
  • Required access: Ability to supply or modify expression strings passed into toJSFunction(), either directly or through indirectly controlled configuration or data fields.
  • Trigger point: Invocation of toJSFunction() (or wrappers around it) that compile and execute the attacker-supplied expression using new Function().
  • Why exploitation is possible: User-controlled expressions are interpolated into JavaScript source and executed without robust sanitization, validation, or isolation, allowing injection of arbitrary code beyond the intended expression semantics.

Why this happens

The underlying bug class is code injection as described by CWE-94, where text-based expressions are treated as executable code in a general-purpose language. The expr-eval library's toJSFunction() API constructs JavaScript source strings incorporating user-controlled expression content and then compiles them using new Function(). This pattern turns untrusted data into active code, bypassing any logical sandbox provided by the expression evaluator. Without strict separation between data and code or constraints on what expressions can contain, attackers can supply payloads that extend beyond simple arithmetic or logical operations and instead execute arbitrary JavaScript in the host environment.

Potential impact

  • Arbitrary JavaScript execution in the application's process context.
  • Access to sensitive in-memory data, including tokens, configuration, and user records.
  • Unauthorized invocation of internal APIs and business logic.
  • Data tampering or exfiltration from server-side or privileged browser environments.
  • Escalation to full system compromise where the application has extensive OS or network privileges.

General mitigation guidance

Effective mitigation focuses on preventing untrusted expressions from being converted into executable code and limiting what evaluated expressions can do. Developers can favor evaluation paths that do not rely on new Function() or similar dynamic code generation mechanisms, instead using interpreters that treat expressions purely as data. Where expression-based logic is necessary, restrict the allowable expression grammar and operators to a minimal, declarative subset and deny any capability to reference arbitrary identifiers or functions. Apply strong input validation and reject expressions that deviate from these constraints. Additionally, isolate any evaluation logic in a low-privilege context, minimizing access to sensitive objects and external resources, and ensure the surrounding application architecture maintains least privilege and clear trust boundaries.

How teams detect issues like this

Security teams can detect this class of issue by scanning codebases for uses of expr-eval's toJSFunction() API, as well as generic patterns involving new Function(), eval(), or similar dynamic code execution primitives. Static analysis rules can flag any combination of user-controlled input flowing into expression evaluation or code generation functions. During code review, engineers should treat expression evaluation code as high-risk, looking for clear separation between trusted and untrusted data, and verifying that only constrained grammars are accepted. Policy-based checks in CI/CD pipelines can enforce bans or guarded usage of dynamic evaluation APIs, while automated security testing tools and fuzzers can probe expression endpoints for signs of code execution beyond allowed operations.

Sources

SourceLink
github.comgithub.com/silentmatt/expr-eval/blob/master/src/expression.js%23L55
github.comgithub.com/silentmatt/expr-eval/issues/292
security.snyk.iosecurity.snyk.io/vuln/SNYK-JAVA-ORGWEBJARSNPM-17662018
security.snyk.iosecurity.snyk.io/vuln/SNYK-JS-EXPREVAL-15054690

Frequently asked

questions

Exploitability depends on whether untrusted users can influence expressions passed into toJSFunction(). In many real-world deployments, user input, query parameters, or configuration can reach this API, making exploitation broadly feasible.

An attacker needs the ability to supply or alter expression strings that are evaluated through expr-eval's compilation path. This may be through a public API, form input, configuration field, or any indirect channel that ultimately feeds into toJSFunction().

The safest pattern is to avoid converting untrusted expressions into executable JavaScript altogether. Use non-compiling evaluation mechanisms that interpret expressions as data, strictly limit the allowed syntax, and ensure expressions cannot reference arbitrary identifiers or functions.

Future designs should treat any dynamic evaluation mechanism as a high-risk feature, enforcing strong input validation, minimal expression grammars, and least-privilege execution contexts. Architectural reviews should highlight and constrain any use of eval-like constructs, and automated policies in CI should guard against reintroducing dynamic code generation driven by user-controlled data.

Find out what's already
exploitable in your codebase.