/

CVE-2026-41139

Severity:

HIGH RISK

(8.8)

Expression Injection (CWE-94) in Math.js Parser Engine

CVE-2026-41139

Modified

Vulnerability type

Category:

Expression Injection / Code Injection

CWE:

CWE-915, CWE-94

Impact:

Arbitrary Code Execution

Severity:

HIGH RISK

(8.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

Math.js versions 13.1.0 through 15.1.x contain an issue in the expression parser that allows arbitrary JavaScript execution when evaluating crafted expressions.

Applications that expose mathjs expression evaluation to users without strict sandboxing or validation may inadvertently grant attackers code execution within the server or client runtime.

Affected context

This vulnerability appears in projects that integrate Math.js and allow dynamic expression evaluation using its parser, especially in Node.js backends or privileged browser contexts.

Risk increases when user-controlled or externally sourced strings are passed directly to the parser without filtering, sandboxing, or constraining the available functions and symbols.

Environments where the Math.js evaluation context has access to sensitive data, system APIs, or other application components are more likely to see impactful exploitation.

Exploit preconditions

  • Attack surface: Any API, UI component, or service that evaluates Math.js expressions derived from untrusted or semi-trusted input.
  • Required access: Ability to submit or influence expressions processed by the Math.js parser (e.g., form fields, query parameters, stored configuration, workflow rules).
  • Trigger point: Invocation of the Math.js evaluation mechanisms (such as math.evaluate or parser-based evaluation) on attacker-crafted expressions.
  • Why exploitation is possible: The parser can be driven to execute arbitrary JavaScript rather than being strictly limited to mathematical operations and safe expression constructs.

Why this happens

The underlying issue is a failure to strictly separate data from executable logic in the expression parsing and evaluation pipeline.

Instead of constraining evaluation to a safe subset of math operations, the parser path permits constructs that resolve to general-purpose JavaScript execution.

This behavior corresponds to CWE-94: Improper Control of Generation of Code ('Code Injection') and is closely related to CWE-915: Improperly Controlled Modification of Dynamically-Determined Object Attributes, where dynamic evaluation and attribute access are insufficiently restricted.

Potential impact

  • Attackers may execute arbitrary JavaScript within the application runtime context.
  • Sensitive data accessible to the Math.js environment could be read, modified, or exfiltrated.
  • Server-side usage may lead to compromise of application integrity, data stores, or connected services.
  • Client-side usage can allow hostile scripts to pivot into broader cross-site scripting or account takeover scenarios.
  • Application-specific business logic and security controls implemented around expression evaluation may be bypassed or subverted.

General mitigation guidance

Effective mitigation centers on tightening the evaluation model and reducing trust in dynamically provided expressions.

Recommended defensive patterns include:

  • Treat all user-provided expressions as untrusted data and apply strict allowlists of supported operations, functions, and symbols.
  • Prefer safe expression evaluators that do not expose general-purpose JavaScript execution and avoid generic eval-like semantics entirely.
  • Constrain the execution context so that evaluated expressions cannot access sensitive APIs, global objects, or mutable shared state.
  • Apply least-privilege principles to the environment where expressions are evaluated, including process isolation or sandboxing where feasible.
  • Integrate robust input validation and schema-based checking for expression formats before they reach the evaluation path.

How teams detect issues like this

Detection typically focuses on identifying dangerous expression evaluation patterns and contexts where untrusted input reaches Math.js.

Useful approaches include:

  • Static analysis rules to flag calls to Math.js evaluation APIs when their arguments originate from request data, form inputs, or other external sources.
  • Code review checklists that require explicit justification and constraints for any dynamic expression evaluation, including reviews of the permitted function set and evaluation context.
  • Logging and monitoring around expression evaluation endpoints to detect anomalous or complex expressions indicative of probing or exploitation attempts.
  • Policy-based enforcement in CI/CD pipelines that disallow generic code-generation or evaluation patterns and highlight risky parser configurations.

Sources

SourceLink
github.comgithub.com/josdejong/mathjs/commit/0aee2f61866e35ffa0aef915221cdf6b026ffdd4
github.comgithub.com/josdejong/mathjs/commit/bcf0da46f0b8577ec03c9ecd7bff8b5c2543a611
github.comgithub.com/josdejong/mathjs/pull/3656
github.comgithub.com/josdejong/mathjs/releases/tag/v15.2.0
github.comgithub.com/josdejong/mathjs/security/advisories/GHSA-5v89-rwgr-qj6g
access.redhat.comaccess.redhat.com/security/cve/CVE-2026-41139
bugzilla.redhat.combugzilla.redhat.com/show_bug.cgi?id=2467648
security.access.redhat.comsecurity.access.redhat.com/data/csaf/v2/vex/2026/cve-2026-41139.json

Frequently asked

questions

Yes, if a remote user can supply or influence expressions evaluated by Math.js. Any network-exposed API or interface that passes untrusted expressions to the parser can be a remote attack surface.

An attacker needs the ability to submit or modify expressions that the application evaluates using Math.js. This could be direct (form inputs, API calls) or indirect (stored configuration, workflow rules, or templated expressions).

The safest approach is to restrict Math.js to a strictly defined set of mathematical operations and eliminate any path that permits general JavaScript execution. Combine this with hard boundaries around the evaluation context and avoid generic dynamic code evaluation altogether.

Design expression features as data-processing tools rather than code-execution engines, enforce strong input validation and allowlists, and subject any dynamic evaluation mechanisms to rigorous threat modeling, security review, and automated checks during development.

Find out what's already
exploitable in your codebase.