CVE-2026-40897: Remote Code Execution via Array Property Modification in mathjs
Vulnerability ID: CVE-2026-40897
CVSS Score: 8.8
Published: 2026-04-24
A critical vulnerability in the mathjs expression parser permits attackers to bypass sandbox restrictions. By exploiting an improperly controlled modification of dynamically-determined object attributes on Array instances, an attacker can leak the Function constructor and achieve unauthenticated remote code execution.
TL;DR
mathjs versions 13.1.1 through 15.1.x fail to sufficiently restrict property modification on Array instances. This allows attackers to overwrite internal array methods, bypass the sandbox, and execute arbitrary code.
⚠️ Exploit Status: POC
Technical Details
- CWE ID: CWE-915
- CVSS Score: 8.8
- Attack Vector: Network
- EPSS Score: 0.00082
- Impact: Remote Code Execution (RCE)
- Exploit Status: Proof of Concept
Affected Systems
- Node.js applications using mathjs versions 13.1.1 through 15.1.x
- Client-side web applications evaluating untrusted expressions with mathjs
- Serverless functions exposing math.evaluate() via APIs
-
mathjs: >= 13.1.1, < 15.2.0 (Fixed in:
15.2.0)
Code Analysis
Commit: 513ab2a
Security fix for sandbox escape via array method hijacking
Mitigation Strategies
- Upgrade mathjs to the patched version 15.2.0 or higher.
- Implement strict input validation to block calls to internal functions like
reviver. - Isolate expression evaluation workloads in restricted containers or Web Workers.
Remediation Steps:
- Audit project dependencies using
npm auditor equivalent tools to identify vulnerablemathjsversions. - Update the
package.jsonto requiremathjs@^15.2.0. - Execute the test suite to verify no regressions in valid mathematical expressions.
- Deploy the updated application to production environments.
References
- GitHub Advisory: GHSA-29qv-4j9f-fjw5
- Fix Commit: 513ab2a0e01004af91b31aada68fae8a821326ad
- Pull Request #3656
- NVD Record for CVE-2026-40897
- CVE.org Record for CVE-2026-40897
Read the full report for CVE-2026-40897 on our website for more details including interactive diagrams and full exploit analysis.
Top comments (0)